public virtual Tree TransformTree(Tree tree) { ILabel lab = tree.Label(); if (tree.IsLeaf()) { Tree leaf = this.tf.NewLeaf(lab); leaf.SetScore(tree.Score()); return(leaf); } string s = lab.Value(); s = this._enclosing.TreebankLanguagePack().BasicCategory(s); int numKids = tree.NumChildren(); IList <Tree> children = new List <Tree>(numKids); for (int cNum = 0; cNum < numKids; cNum++) { Tree child = tree.GetChild(cNum); Tree newChild = this.TransformTree(child); // cdm 2007: for just subcategory stripping, null shouldn't happen // if (newChild != null) { children.Add(newChild); } // } // if (children.isEmpty()) { // return null; // } CategoryWordTag newLabel = new CategoryWordTag(lab); newLabel.SetCategory(s); if (lab is IHasTag) { string tag = ((IHasTag)lab).Tag(); tag = this._enclosing.TreebankLanguagePack().BasicCategory(tag); newLabel.SetTag(tag); } Tree node = this.tf.NewTreeNode(newLabel, children); node.SetScore(tree.Score()); return(node); }
// end class SubcategoryStripper public virtual Tree TransformTree(Tree tree) { ILabel lab = tree.Label(); if (tree.IsLeaf()) { Tree leaf = this.tf.NewLeaf(lab); leaf.SetScore(tree.Score()); return(leaf); } string s = lab.Value(); s = this._enclosing.TreebankLanguagePack().BasicCategory(s); s = this._enclosing.TreebankLanguagePack().StripGF(s); int numKids = tree.NumChildren(); IList <Tree> children = new List <Tree>(numKids); for (int cNum = 0; cNum < numKids; cNum++) { Tree child = tree.GetChild(cNum); Tree newChild = this.TransformTree(child); children.Add(newChild); } CategoryWordTag newLabel = new CategoryWordTag(lab); newLabel.SetCategory(s); if (lab is IHasTag) { string tag = ((IHasTag)lab).Tag(); tag = this._enclosing.TreebankLanguagePack().BasicCategory(tag); tag = this._enclosing.TreebankLanguagePack().StripGF(tag); newLabel.SetTag(tag); } Tree node = this.tf.NewTreeNode(newLabel, children); node.SetScore(tree.Score()); return(node); }