public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                // find match and get its parent
                Tree targetNode = this.childMatcher[0].Evaluate(tree, tregex);
                Tree parent     = targetNode.Parent(tree);
                // substitute original node for foot of auxiliary tree.  Foot node is ignored
                AuxiliaryTree ft = this._enclosing.AdjunctionTree().Copy(this, tree.TreeFactory(), tree.Label().LabelFactory());
                // log.info("ft=" + ft + "; ft.foot=" + ft.foot + "; ft.tree=" + ft.tree);
                Tree parentOfFoot = ft.foot.Parent(ft.tree);

                if (parentOfFoot == null)
                {
                    AdjoinToFootNode.log.Info("Warning: adjoin to foot for depth-1 auxiliary tree has no effect.");
                    return(tree);
                }
                int i = parentOfFoot.ObjectIndexOf(ft.foot);

                if (parent == null)
                {
                    parentOfFoot.SetChild(i, targetNode);
                    return(ft.tree);
                }
                else
                {
                    int j = parent.ObjectIndexOf(targetNode);
                    parent.SetChild(j, ft.tree);
                    parentOfFoot.SetChild(i, targetNode);
                    return(tree);
                }
            }
 public AdjoinNode(string name, AuxiliaryTree t, TsurgeonPattern p)
     : base(name, new TsurgeonPattern[] { p })
 {
     if (t == null || p == null)
     {
         throw new ArgumentNullException("AdjoinNode: illegal null argument, t=" + t + ", p=" + p);
     }
     adjunctionTree = t;
 }
            /// <summary>
            /// Combines all nodes between start and end into one subtree, then
            /// replaces those nodes with the new subtree in the corresponding
            /// location under parent
            /// </summary>
            public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                Tree startChild = this.childMatcher[0].Evaluate(tree, tregex);
                Tree endChild   = (this.childMatcher.Length == 2) ? this.childMatcher[1].Evaluate(tree, tregex) : startChild;
                Tree parent     = startChild.Parent(tree);

                // sanity check
                if (parent != endChild.Parent(tree))
                {
                    throw new TsurgeonRuntimeException("Parents did not match for trees when applied to " + this);
                }
                AuxiliaryTree treeCopy = this._enclosing.auxTree.Copy(this, tree.TreeFactory(), tree.Label().LabelFactory());
                // Collect all the children of the parent of the node we care
                // about.  If the child is one of the nodes we care about, or
                // between those two nodes, we add it to a list of inner children.
                // When we reach the second endpoint, we turn that list of inner
                // children into a new node using the newly created label.  All
                // other children are kept in an outer list, with the new node
                // added at the appropriate location.
                IList <Tree> children      = Generics.NewArrayList();
                IList <Tree> innerChildren = Generics.NewArrayList();
                bool         insideSpan    = false;

                foreach (Tree child in parent.Children())
                {
                    if (child == startChild || child == endChild)
                    {
                        if (!insideSpan && startChild != endChild)
                        {
                            insideSpan = true;
                            innerChildren.Add(child);
                        }
                        else
                        {
                            insideSpan = false;
                            innerChildren.Add(child);
                            // All children have been collected; place these beneath the foot of the auxiliary tree
                            treeCopy.foot.SetChildren(innerChildren);
                            children.Add(treeCopy.tree);
                        }
                    }
                    else
                    {
                        if (insideSpan)
                        {
                            innerChildren.Add(child);
                        }
                        else
                        {
                            children.Add(child);
                        }
                    }
                }
                parent.SetChildren(children);
                return(tree);
            }
            public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                // find match
                Tree targetNode = this.childMatcher[0].Evaluate(tree, tregex);
                // put children underneath target in foot of auxilary tree
                AuxiliaryTree ft = this._enclosing.AdjunctionTree().Copy(this, tree.TreeFactory(), tree.Label().LabelFactory());

                ft.foot.SetChildren(targetNode.GetChildrenAsList());
                // put children of auxiliary tree under target.  root of auxiliary tree is ignored.  root of original is maintained.
                targetNode.SetChildren(ft.tree.GetChildrenAsList());
                return(tree);
            }
            public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                // find match and get its parent
                Tree targetNode = this.childMatcher[0].Evaluate(tree, tregex);
                Tree parent     = targetNode.Parent(tree);
                // put children underneath target in foot of auxilary tree
                AuxiliaryTree ft = this._enclosing.adjunctionTree.Copy(this, tree.TreeFactory(), tree.Label().LabelFactory());

                ft.foot.SetChildren(targetNode.GetChildrenAsList());
                // replace match with root of auxiliary tree
                if (parent == null)
                {
                    return(ft.tree);
                }
                else
                {
                    int i = parent.ObjectIndexOf(targetNode);
                    parent.SetChild(i, ft.tree);
                    return(tree);
                }
            }
 public AdjoinToHeadNode(AuxiliaryTree t, TsurgeonPattern p)
     : base("adjoinH", t, p)
 {
 }
Exemplo n.º 7
0
 public HoldTreeNode(AuxiliaryTree t)
     : base("hold", TsurgeonPattern.EmptyTsurgeonPatternArray)
 {
     this.subTree = t;
 }
 public AdjoinToFootNode(AuxiliaryTree t, TsurgeonPattern p)
     : base("adjoinF", t, p)
 {
 }
Exemplo n.º 9
0
 public InsertNode(AuxiliaryTree t, TreeLocation l)
     : this(new HoldTreeNode(t), l)
 {
     // Copy occurs in HoldTreeNode's `evaluate` method
     needsCopy = false;
 }
 public CreateSubtreeNode(TsurgeonPattern start, TsurgeonPattern end, AuxiliaryTree tree)
     : base("combineSubtrees", (end == null) ? new TsurgeonPattern[] { start } : new TsurgeonPattern[] { start, end })
 {
     this.auxTree = tree;
     FindFoot();
 }
 public CreateSubtreeNode(TsurgeonPattern start, AuxiliaryTree tree)
     : this(start, null, tree)
 {
 }
Exemplo n.º 12
0
 public virtual void TestUnescape()
 {
     NUnit.Framework.Assert.AreEqual("asdf", AuxiliaryTree.Unescape("asdf"));
     NUnit.Framework.Assert.AreEqual("asdf=", AuxiliaryTree.Unescape("asdf\\="));
     NUnit.Framework.Assert.AreEqual("asdf\\=", AuxiliaryTree.Unescape("asdf\\\\="));
 }
 public AdjoinNode(AuxiliaryTree t, TsurgeonPattern p)
     : this("adjoin", t, p)
 {
 }