Esempio n. 1
0
            public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                // find match and get its parent
                Tree targetNode = ChildMatcher[0].Evaluate(tree, tregex);
                Tree parent     = targetNode.Parent(tree);
                // substitute original node for foot of auxiliary tree.  Foot node is ignored
                AuxiliaryTree ft           = node.AdjunctionTree().Copy(this);
                Tree          parentOfFoot = ft.Foot.Parent(ft.Tree);

                if (parentOfFoot == null)
                {
                    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);
                }
            }
Esempio n. 2
0
 public CreateSubtreeNode(TsurgeonPattern start, TsurgeonPattern end, AuxiliaryTree tree) :
     base("combineSubtrees",
          (end == null) ? new TsurgeonPattern[] { start } : new TsurgeonPattern[] { start, end })
 {
     this.auxTree = tree;
     FindFoot();
 }
Esempio n. 3
0
            /**
             * Combines all nodes between start and end into one subtree, then
             * replaces those nodes with the new subtree in the corresponding
             * location under parent
             */

            public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                Tree startChild = ChildMatcher[0].Evaluate(tree, tregex);
                Tree endChild   = (ChildMatcher.Length == 2) ? 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 = node.auxTree.Copy(this);

                // 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.
                var  children      = new List <Tree>();
                var  innerChildren = new List <Tree>();
                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);
            }
Esempio n. 4
0
        public CreateSubtreeNode(TsurgeonPattern start, TsurgeonPattern end, AuxiliaryTree tree) :
            base("combineSubtrees",
                (end == null) ? new TsurgeonPattern[] {start} : new TsurgeonPattern[] {start, end})
        {

            this.auxTree = tree;
            FindFoot();
        }
Esempio n. 5
0
 public AdjoinNode(string name, AuxiliaryTree t, TsurgeonPattern p) :
     base(name, new TsurgeonPattern[] { p })
 {
     if (t == null || p == null)
     {
         throw new NullReferenceException("AdjoinNode: illegal null argument, t=" + t + ", p=" + p);
     }
     padjunctionTree = t;
 }
Esempio n. 6
0
 public AdjoinNode(string name, AuxiliaryTree t, TsurgeonPattern p) :
     base(name, new TsurgeonPattern[] {p})
 {
     if (t == null || p == null)
     {
         throw new NullReferenceException("AdjoinNode: illegal null argument, t=" + t + ", p=" + p);
     }
     padjunctionTree = t;
 }
Esempio n. 7
0
            public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                // find match
                Tree targetNode = ChildMatcher[0].Evaluate(tree, tregex);
                // put children underneath target in foot of auxilary tree
                AuxiliaryTree ft = node.AdjunctionTree().Copy(this);

                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);
            }
Esempio n. 8
0
            public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                // find match and get its parent
                Tree targetNode = ChildMatcher[0].Evaluate(tree, tregex);
                Tree parent     = targetNode.Parent(tree);
                // put children underneath target in foot of auxilary tree
                AuxiliaryTree ft = node.padjunctionTree.Copy(this);

                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);
                }
            }
Esempio n. 9
0
 public AdjoinNode(AuxiliaryTree t, TsurgeonPattern p) :
     this("adjoin", t, p)
 {
 }
Esempio n. 10
0
 public CreateSubtreeNode(TsurgeonPattern start, AuxiliaryTree tree) :
     this(start, null, tree)
 {
 }
Esempio n. 11
0
 public CreateSubtreeNode(TsurgeonPattern start, AuxiliaryTree tree) :
     this(start, null, tree)
 {
 }
Esempio n. 12
0
 public AdjoinNode(AuxiliaryTree t, TsurgeonPattern p) :
     this("adjoin", t, p)
 {
 }
Esempio n. 13
0
 public AdjoinToFootNode(AuxiliaryTree t, TsurgeonPattern p) :
     base("adjoinF", t, p)
 {
 }
Esempio n. 14
0
 public HoldTreeNode(AuxiliaryTree t) :
     base("hold", TsurgeonPattern.EmptyTsurgeonPatternArray)
 {
     this.subTree = t;
 }
Esempio n. 15
0
 public AdjoinToFootNode(AuxiliaryTree t, TsurgeonPattern p) :
     base("adjoinF", t, p)
 {
 }
Esempio n. 16
0
 public InsertNode(AuxiliaryTree t, TreeLocation l) :
     this(new HoldTreeNode(t), l)
 {
     // Copy occurs in HoldTreeNode's `evaluate` method
     needsCopy = false;
 }
Esempio n. 17
0
 public AdjoinToHeadNode(AuxiliaryTree t, TsurgeonPattern p) :
     base("adjoinH", t, p)
 {
 }
Esempio n. 18
0
 public AdjoinToHeadNode(AuxiliaryTree t, TsurgeonPattern p) :
     base("adjoinH", t, p)
 {
 }
Esempio n. 19
0
 public InsertNode(AuxiliaryTree t, TreeLocation l) :
     this(new HoldTreeNode(t), l)
 {
     // Copy occurs in HoldTreeNode's `evaluate` method
     needsCopy = false;
 }
Esempio n. 20
0
 public HoldTreeNode(AuxiliaryTree t) :
     base("hold", TsurgeonPattern.EmptyTsurgeonPatternArray)
 {
     this.subTree = t;
 }