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


C# Tree.TreeFactory方法代码示例

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


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

示例1: 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

示例2: 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

示例3: TransformTree

 public Tree TransformTree(Tree tree)
 {
     return NormalizeWholeTree(tree, tree.TreeFactory());
 }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:4,代码来源:BobChrisTreeNormalizer.cs


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