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


C# Tree.GetChild方法代码示例

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


在下文中一共展示了Tree.GetChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
                }
//.........这里部分代码省略.........
开发者ID:gblosser,项目名称:OpenNlp,代码行数:101,代码来源:CoordinationTransformer.cs

示例2: TaggedLeafLabels

 private static void TaggedLeafLabels(Tree t, List<CoreLabel> l)
 {
     if (t.IsPreTerminal())
     {
         var fl = (CoreLabel) t.GetChild(0).Label();
         fl.Set(typeof (CoreAnnotations.TagLabelAnnotation), t.Label());
         l.Add(fl);
     }
     else
     {
         foreach (Tree kid in t.Children())
         {
             TaggedLeafLabels(kid, l);
         }
     }
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:16,代码来源:Trees.cs

示例3: Update

        private void Update(string _path, Tree<RemoteFileInfo> _tree)
        {
            try
            {
                RemoteDirectoryInfo directory = m_session.ListDirectory(_path);

                foreach (WinSCP.RemoteFileInfo fileInfo in directory.Files)
                {
                    if (fileInfo.Name != "..")
                    {
                        if (fileInfo.IsDirectory)
                        {
                            //if the entry not cached - add the directory and then update its contents
                            if (Tree<RemoteFileInfo>.Find(m_ignoreTree, i => i.Name == fileInfo.Name && i.IsDirectory) == null)
                            {
                                _tree.AddChild(new RemoteFileInfo(fileInfo));

                                Update(_path + "/" + fileInfo.Name, _tree.GetChild(_tree.Children.Count - 1));
                            }
                        }
                        else
                        {
                            //if we are not ignoring the file
                            if (Tree<RemoteFileInfo>.Find(m_ignoreTree, i => i.Name == fileInfo.Name && !i.IsDirectory) == null)
                            {
                                //if the file extension is one we care about add it to list, other wise add to the ignore list
                                //if (!m_ignoredExtensions.Contains(Utilities.GetExtensionFromFileName(fileInfo.Name)))
                                {
                                    _tree.AddChild(new RemoteFileInfo(fileInfo));
                                }
                                //else
                                //{
                                //    m_ignoreTree.AddChild(new RemoteFileInfo2(fileInfo));
                                //}
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LOG.ErrorFormat("Error: {0}", e);
            }
        }
开发者ID:mkramers,项目名称:Projects,代码行数:44,代码来源:SessionManager.cs

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