예제 #1
0
        /// <summary>
        /// Checks the node's ancestors to find the highest ancestor with the
        /// same <code>headWordNode</code> as this node
        /// </summary>
        public TreeGraphNode HighestNodeWithSameHead()
        {
            TreeGraphNode node = this;

            while (true)
            {
                TreeGraphNode parent = SafeCast(node.Parent());
                if (parent == null || parent.HeadWordNode() != node.HeadWordNode())
                {
                    return(node);
                }
                node = parent;
            }
        }
예제 #2
0
        /// <summary>
        /// Uses the specified {@link HeadFinder <code>HeadFinder</code>}
        /// to determine the heads for this node and all its descendants,
        /// and to store references to the head word node and head tag node
        /// in this node's {@link CoreLabel <code>CoreLabel</code>} and the
        /// <code>CoreLabel</code>s of all its descendants.
        ///
        /// Note that, in contrast to {@link Tree#percolateHeads
        /// <code>Tree.percolateHeads()</code>}, which assumes {@link
        /// edu.stanford.nlp.ling.CategoryWordTag
        /// <code>CategoryWordTag</code>} labels and therefore stores head
        /// words and head tags merely as <code>string</code>s, this
        /// method stores references to the actual nodes.  This mitigates
        /// potential problems in sentences which contain the same word more than once.
        /// </summary>
        /// <param name="hf">The headfinding algorithm to use</param>
        public override void PercolateHeads(IHeadFinder hf)
        {
            if (IsLeaf())
            {
                TreeGraphNode hwn = HeadWordNode();
                if (hwn == null)
                {
                    SetHeadWordNode(this);
                }
            }
            else
            {
                foreach (Tree child in Children())
                {
                    child.PercolateHeads(hf);
                }
                TreeGraphNode head = SafeCast(hf.DetermineHead(this, _parent));
                if (head != null)
                {
                    TreeGraphNode hwn = head.HeadWordNode();
                    if (hwn == null && head.IsLeaf())
                    {
                        // below us is a leaf
                        SetHeadWordNode(head);
                    }
                    else
                    {
                        SetHeadWordNode(hwn);
                    }

                    TreeGraphNode htn = head.HeadTagNode();
                    if (htn == null && head.IsLeaf())
                    {
                        // below us is a leaf
                        SetHeadTagNode(this);
                    }
                    else
                    {
                        SetHeadTagNode(htn);
                    }
                }
            }
        }