本文整理汇总了C#中Tree.Parent方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.Parent方法的具体用法?C# Tree.Parent怎么用?C# Tree.Parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.Parent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PruneHelper
private static Tree PruneHelper(Tree root, Tree nodeToPrune)
{
if (nodeToPrune == root)
return null;
Tree parent = nodeToPrune.Parent(root);
parent.RemoveChild(Trees.ObjectEqualityIndexOf(parent, nodeToPrune));
if (parent.Children().Length == 0)
return PruneHelper(root, parent);
return root;
}
示例2: FindCcParent
/// <summary>
/// Given a tree t, if this tree contains a CC inside a NP followed by 2 nodes
/// (i.e. we have a flat structure that will not work for the dependencies),
/// it will call transform CC on the NP containing the CC and the index of the
/// CC, and then return the root of the whole transformed tree.
/// If it finds no such tree, this method returns null.
/// </summary>
private static Tree FindCcParent(Tree t, Tree root)
{
if (t.IsPreTerminal())
{
if (t.Value().StartsWith(PartsOfSpeech.CoordinatingConjunction))
{
Tree parent = t.Parent(root);
if (parent != null && parent.Value().StartsWith(CoordinationTransformer.Noun))
{
List<Tree> children = parent.GetChildrenAsList();
int ccIndex = children.IndexOf(t);
if (children.Count > ccIndex + 2 && NotNp(children, ccIndex) && ccIndex != 0 &&
(ccIndex == children.Count - 1 || !children[ccIndex + 1].Value().StartsWith(PartsOfSpeech.CoordinatingConjunction)))
{
TransformCc(parent, ccIndex);
return root;
}
}
}
}
else
{
foreach (Tree child in t.GetChildrenAsList())
{
Tree cur = FindCcParent(child, root);
if (cur != null)
{
return cur;
}
}
}
return null;
}
示例3: GetParent
public Tree GetParent(Tree node)
{
if (node is IHasParent)
{
return node.Parent();
}
if (nodesToParents == null)
{
nodesToParents = new IdentityDictionary<Tree, Tree>();
}
if (nodesToParents.Count == 0)
{
FillNodesToParents(root, null);
}
Tree parent;
nodesToParents.TryGetValue(node, out parent);
return parent;
}