当前位置: 首页>>代码示例>>C#>>正文


C# Tree.IsLeaf方法代码示例

本文整理汇总了C#中Tree.IsLeaf方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.IsLeaf方法的具体用法?C# Tree.IsLeaf怎么用?C# Tree.IsLeaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tree的用法示例。


在下文中一共展示了Tree.IsLeaf方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StripTag

 protected void StripTag(Tree t)
 {
     if (! t.IsLeaf())
     {
         string label = CleanUpLabel(t.Value());
         t.SetValue(label);
         foreach (Tree child in t.GetChildrenAsList())
         {
             StripTag(child);
         }
     }
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:12,代码来源:DependencyTreeTransformer.cs

示例2: CopyHelper

        private Tuple<Tree, Tree> CopyHelper(Tree node, Dictionary<string, Tree> newNamesToNodes)
        {
            Tree clone;
            Tree newFoot = null;
            if (node.IsLeaf())
            {
                if (node == Foot)
                {
                    // found the foot node; pass it up.
                    clone = node.TreeFactory().NewTreeNode(node.Label(), new List<Tree>(0));
                    newFoot = clone;
                }
                else
                {
                    clone = node.TreeFactory().NewLeaf(node.Label().LabelFactory().NewLabel(node.Label()));
                }
            }
            else
            {
                var newChildren = new List<Tree>(node.Children().Length);
                foreach (Tree child in node.Children())
                {
                    Tuple<Tree, Tree> newChild = CopyHelper(child, newNamesToNodes);
                    newChildren.Add(newChild.Item1);
                    if (newChild.Item2 != null)
                    {
                        newFoot = newChild.Item2;
                    }
                }
                clone = node.TreeFactory().NewTreeNode(node.Label().LabelFactory().NewLabel(node.Label()), newChildren);
            }

            if (nodesToNames.ContainsKey(node))
            {
                newNamesToNodes.Add(nodesToNames[node], clone);
            }

            return new Tuple<Tree, Tree>(clone, newFoot);
        }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:39,代码来源:AuxiliaryTree.cs

示例3: LeftEdge

 private static bool LeftEdge(Tree t, Tree t1, int i)
 {
     if (t == t1)
     {
         return true;
     }
     else if (t1.IsLeaf())
     {
         int j = t1.Yield().Count; // so that empties don't add size
         i = i + j;
         return false;
     }
     else
     {
         foreach (Tree kid in t1.Children())
         {
             if (LeftEdge(t, kid, i))
             {
                 return true;
             }
         }
         return false;
     }
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:24,代码来源:Trees.cs

示例4: DetermineHead

        /// <summary>
        /// Determine which daughter of the current parse tree is the head.
        /// </summary>
        /// <param name="t">
        /// The parse tree to examine the daughters of. 
        /// If this is a leaf, <code>null</code> is returned
        /// </param>
        /// <param name="parent">The parent of t</param>
        /// <returns>
        /// The daughter parse tree that is the head of <code>t</code>.
        /// Returns null for leaf nodes.
        /// </returns>
        public Tree DetermineHead(Tree t, Tree parent)
        {
            if (NonTerminalInfo == null)
            {
                throw new InvalidDataException(
                    "Classes derived from AbstractCollinsHeadFinder must create and fill HashMap nonTerminalInfo.");
            }
            if (t == null || t.IsLeaf())
            {
                throw new ArgumentException("Can't return head of null or leaf Tree.");
            }

            Tree[] kids = t.Children();

            Tree theHead;
            // first check if subclass found explicitly marked head
            if ((theHead = FindMarkedHead(t)) != null)
            {
                return theHead;
            }

            // if the node is a unary, then that kid must be the head
            // it used to special case preterminal and ROOT/TOP case
            // but that seemed bad (especially hardcoding string "ROOT")
            if (kids.Length == 1)
            {
                return kids[0];
            }

            return DetermineNonTrivialHead(t, parent);
        }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:43,代码来源:AbstractCollinsHeadFinder.cs

示例5: RightEdge

 private static bool RightEdge(Tree t, Tree t1, int i)
 {
     if (t == t1)
     {
         return true;
     }
     else if (t1.IsLeaf())
     {
         int j = t1.Yield().Count; // so that empties don't add size
         i = i - j;
         return false;
     }
     else
     {
         Tree[] kids = t1.Children();
         for (int j = kids.Length - 1; j >= 0; j--)
         {
             if (RightEdge(t, kids[j], i))
             {
                 return true;
             }
         }
         return false;
     }
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:25,代码来源:Trees.cs

示例6: ReplaceNode

 /// <summary>
 /// Replaces all instances (by ==) of node with node1.
 /// Doesn't affect the node t itself
 /// </summary>
 public static void ReplaceNode(Tree node, Tree node1, Tree t)
 {
     if (t.IsLeaf())
         return;
     Tree[] kids = t.Children();
     var newKids = new List<Tree>(kids.Length);
     foreach (Tree kid in kids)
     {
         if (kid != node)
         {
             newKids.Add(kid);
             ReplaceNode(node, node1, kid);
         }
         else
         {
             newKids.Add(node1);
         }
     }
     t.SetChildren(newKids);
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:24,代码来源:Trees.cs

示例7: TreeToLatexEvenHelper

 private static int TreeToLatexEvenHelper(Tree t, StringBuilder c, StringBuilder h, int n,
     int nextN, int indent, int curDepth, int maxDepth)
 {
     var sb = new StringBuilder();
     for (int i = 0; i < indent; i++)
         sb.Append("  ");
     h.Append('\n').Append(sb);
     int tDepth = t.Depth();
     if (tDepth == 0 && tDepth + curDepth < maxDepth)
     {
         for (int pad = 0; pad < maxDepth - tDepth - curDepth; pad++)
         {
             h.Append("{\\ntnode{pad}{}, ");
         }
     }
     h.Append("{\\ntnode{z").Append(n).Append("}{").Append(t.Label()).Append('}');
     if (!t.IsLeaf())
     {
         for (int k = 0; k < t.Children().Length; k++)
         {
             h.Append(", ");
             c.Append("\\nodeconnect{z").Append(n).Append("}{z").Append(nextN).Append("}\n");
             nextN = TreeToLatexEvenHelper(t.Children()[k], c, h, nextN, nextN + 1, indent + 1, curDepth + 1,
                 maxDepth);
         }
     }
     if (tDepth == 0 && tDepth + curDepth < maxDepth)
     {
         for (int pad = 0; pad < maxDepth - tDepth - curDepth; pad++)
         {
             h.Append('}');
         }
     }
     h.Append('}');
     return nextN;
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:36,代码来源:Trees.cs

示例8: TreeToLatexHelper

 private static int TreeToLatexHelper(Tree t, StringBuilder c, StringBuilder h,
     int n, int nextN, int indent)
 {
     var sb = new StringBuilder();
     for (int i = 0; i < indent; i++)
         sb.Append("  ");
     h.Append('\n').Append(sb);
     h.Append("{\\")
         .Append(t.IsLeaf() ? "" : "n")
         .Append("tnode{z")
         .Append(n)
         .Append("}{")
         .Append(t.Label())
         .Append('}');
     if (!t.IsLeaf())
     {
         for (int k = 0; k < t.Children().Length; k++)
         {
             h.Append(", ");
             c.Append("\\nodeconnect{z").Append(n).Append("}{z").Append(nextN).Append("}\n");
             nextN = TreeToLatexHelper(t.Children()[k], c, h, nextN, nextN + 1, indent + 1);
         }
     }
     h.Append('}');
     return nextN;
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:26,代码来源:Trees.cs

示例9: LeafLabels

 private static void LeafLabels(Tree t, List<ILabel> l)
 {
     if (t.IsLeaf())
     {
         l.Add(t.Label());
     }
     else
     {
         foreach (Tree kid in t.Children())
         {
             LeafLabels(kid, l);
         }
     }
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:14,代码来源:Trees.cs

示例10: Leaves

 private static void Leaves(Tree t, List<Tree> l)
 {
     if (t.IsLeaf())
     {
         l.Add(t);
     }
     else
     {
         foreach (Tree kid in t.Children())
         {
             Leaves(kid, l);
         }
     }
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:14,代码来源:Trees.cs

示例11: FindFootNodeHelper

 private static Tree FindFootNodeHelper(Tree t)
 {
     Tree foundDtr = null;
     if (t.IsLeaf())
     {
         var match = FootNodeLabelPattern.Match(t.Label().Value());
         if (match.Success)
         {
             t.Label().SetValue(match.Groups[1].Value);
             return t;
         }
         else
         {
             return null;
         }
     }
     foreach (Tree child in t.Children())
     {
         Tree thisFoundDtr = FindFootNodeHelper(child);
         if (thisFoundDtr != null)
         {
             if (foundDtr != null)
             {
                 throw new TsurgeonParseException("Error -- two foot nodes in subtree" + t.ToString());
             }
             else
             {
                 foundDtr = thisFoundDtr;
             }
         }
     }
     /*Matcher m = escapedFootNodeCharacter.matcher(t.label().value());
     t.label().setValue(m.replaceAll(footNodeCharacter));*/
     var newS = EscapedFootNodeCharacter.Replace(t.Label().Value(), FootNodeCharacter);
     t.Label().SetValue(newS);
     return foundDtr;
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:37,代码来源:AuxiliaryTree.cs

示例12: 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()));
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:23,代码来源:BobChrisTreeNormalizer.cs


注:本文中的Tree.IsLeaf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。