/// <summary> /// Checks the node's ancestors to find the highest ancestor with the /// same /// <c>headWordNode</c> /// as this node. /// </summary> public virtual Edu.Stanford.Nlp.Trees.TreeGraphNode HighestNodeWithSameHead() { Edu.Stanford.Nlp.Trees.TreeGraphNode node = this; while (true) { Edu.Stanford.Nlp.Trees.TreeGraphNode parent = SafeCast(((Edu.Stanford.Nlp.Trees.TreeGraphNode)node.Parent())); if (parent == null || parent.HeadWordNode() != node.HeadWordNode()) { return(node); } node = parent; } }
/// <summary> /// Uses the specified /// <see cref="IHeadFinder"/> /// /// <c>HeadFinder</c> /// } /// 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 /// <see cref="Edu.Stanford.Nlp.Ling.CoreLabel"/> /// /// <c>CoreLabel</c> /// } and the /// <c>CoreLabel</c> /// s of all its descendants.<p> /// <p/> /// Note that, in contrast to /// <see cref="Tree.PercolateHeads(IHeadFinder)"/> /// { /// <c>Tree.percolateHeads()</c> /// }, which assumes /// <see cref="Edu.Stanford.Nlp.Ling.CategoryWordTag"/> /// { /// <c>CategoryWordTag</c> /// } labels and therefore stores head /// words and head tags merely as /// <c>String</c> /// 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()) { Edu.Stanford.Nlp.Trees.TreeGraphNode hwn = HeadWordNode(); if (hwn == null) { SetHeadWordNode(this); } } else { foreach (Tree child in ((Edu.Stanford.Nlp.Trees.TreeGraphNode[])Children())) { child.PercolateHeads(hf); } Edu.Stanford.Nlp.Trees.TreeGraphNode head = SafeCast(hf.DetermineHead(this, parent)); if (head != null) { Edu.Stanford.Nlp.Trees.TreeGraphNode hwn = head.HeadWordNode(); if (hwn == null && head.IsLeaf()) { // below us is a leaf SetHeadWordNode(head); } else { SetHeadWordNode(hwn); } } else { log.Info("Head is null: " + this); } } }