本文整理汇总了C#中Tree.NumChildren方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.NumChildren方法的具体用法?C# Tree.NumChildren怎么用?C# Tree.NumChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.NumChildren方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransformCc
/// <summary>
/// If things match, this method destructively changes the children list
/// of the tree t. When this method is called, t is an NP and there must
/// be at least two children to the right of ccIndex.
/// </summary>
/// <param name="t">The tree to transform a conjunction in</param>
/// <param name="ccIndex">The index of the CC child</param>
/// <returns>t</returns>
private static Tree TransformCc(Tree t, int ccIndex)
{
// use the factories of t to create new nodes
ITreeFactory tf = t.TreeFactory();
ILabelFactory lf = t.Label().LabelFactory();
Tree[] ccSiblings = t.Children();
//check if other CC
var ccPositions = new List<int>();
for (int i = ccIndex + 1; i < ccSiblings.Length; i++)
{
if (ccSiblings[i].Value().StartsWith(PartsOfSpeech.CoordinatingConjunction) && i < ccSiblings.Length - 1)
{
// second conjunct to ensure that a CC we add isn't the last child
ccPositions.Add(i);
}
}
// a CC b c ... -> (a CC b) c ... with b not a DT
string beforeSibling = ccSiblings[ccIndex - 1].Value();
if (ccIndex == 1 &&
(beforeSibling == PartsOfSpeech.Determiner
|| beforeSibling == PartsOfSpeech.Adjective
|| beforeSibling == PartsOfSpeech.Adverb
|| !(ccSiblings[ccIndex + 1].Value() == PartsOfSpeech.Determiner))
&& !(beforeSibling.StartsWith("NP")
|| beforeSibling.Equals("ADJP")
|| beforeSibling == PartsOfSpeech.NounPlural))
{
// && (ccSiblings.Length == ccIndex + 3 || !ccPositions.isEmpty())) { // something like "soya or maize oil"
string leftHead = GetHeadTag(ccSiblings[ccIndex - 1]);
//create a new tree to be inserted as first child of t
Tree left = tf.NewTreeNode(lf.NewLabel(leftHead), null);
for (int i = 0; i < ccIndex + 2; i++)
{
left.AddChild(ccSiblings[i]);
}
// remove all the children of t before ccIndex+2
for (int i = 0; i < ccIndex + 2; i++)
{
t.RemoveChild(0);
}
// if stuff after (like "soya or maize oil and vegetables")
// we need to put the tree in another tree
if (ccPositions.Any())
{
bool comma = false;
int index = ccPositions[0];
if (ccSiblings[index - 1].Value() == PartsOfSpeech.Comma)
{
//to handle the case of a comma ("soya and maize oil, and vegetables")
index = index - 1;
comma = true;
}
string head = GetHeadTag(ccSiblings[index - 1]);
if (ccIndex + 2 < index)
{
Tree tree = tf.NewTreeNode(lf.NewLabel(head), null);
tree.AddChild(0, left);
int k = 1;
for (int j = ccIndex + 2; j < index; j++)
{
t.RemoveChild(0);
tree.AddChild(k, ccSiblings[j]);
k++;
}
t.AddChild(0, tree);
}
else
{
t.AddChild(0, left);
}
Tree rightTree = tf.NewTreeNode(lf.NewLabel(Noun), null);
int start = 2;
if (comma)
{
start++;
}
while (start < t.NumChildren())
{
Tree sib = t.GetChild(start);
t.RemoveChild(start);
rightTree.AddChild(sib);
}
t.AddChild(rightTree);
}
//.........这里部分代码省略.........
示例2: Test
/// <summary>
/// Doesn't accept nodes that are A over A nodes (perhaps due to
/// empty removal or are EDITED nodes).
/// </summary>
public bool Test(Tree t)
{
if (t.IsLeaf() || t.IsPreTerminal())
{
return true;
}
// The special switchboard non-terminals clause
if ("EDITED".Equals(t.Label().Value()) || "CODE".Equals(t.Label().Value()))
{
return false;
}
if (t.NumChildren() != 1)
{
return true;
}
return
! (t.Label() != null && t.Label().Value() != null &&
t.Label().Value().Equals(t.GetChild(0).Label().Value()));
}