Exemple #1
0
 public static Tree ProcessPatternsOnTree(List <Tuple <TregexPattern, TsurgeonPattern> > ops, Tree t)
 {
     matchedOnTree = false;
     foreach (Tuple <TregexPattern, TsurgeonPattern> op in ops)
     {
         try
         {
             TregexMatcher   m   = op.Item1.Matcher(t);
             TsurgeonMatcher tsm = op.Item2.GetMatcher();
             while (m.Find())
             {
                 matchedOnTree = true;
                 t             = tsm.Evaluate(t, m);
                 if (t == null)
                 {
                     return(null);
                 }
                 m = op.Item1.Matcher(t);
             }
         }
         catch (NullReferenceException npe)
         {
             throw new SystemException(
                       "Tsurgeon.processPatternsOnTree failed to match label for pattern: " + op.Item1 + ", " +
                       op.Item2, npe);
         }
     }
     return(t);
 }
Exemple #2
0
            public LocationMatcher(Dictionary<string, Tree> newNodeNames, CoindexationGenerator coindexer,
                TreeLocation location)
            {
                this.newNodeNames = newNodeNames;
                this.coindexer = coindexer;
                this.location = location;

                this.childMatcher = location.child.GetMatcher(newNodeNames, coindexer);
            }
            public LocationMatcher(Dictionary <string, Tree> newNodeNames, CoindexationGenerator coindexer,
                                   TreeLocation location)
            {
                this.newNodeNames = newNodeNames;
                this.coindexer    = coindexer;
                this.location     = location;

                this.childMatcher = location.child.GetMatcher(newNodeNames, coindexer);
            }
Exemple #4
0
 /// <summary>
 /// Copies the Auxiliary tree.  Also, puts the new names->nodes map in the TsurgeonMatcher that called copy.
 /// </summary>
 public AuxiliaryTree Copy(TsurgeonMatcher matcher)
 {
     var newNamesToNodes = new Dictionary<string, Tree>();
     Tuple<Tree, Tree> result = CopyHelper(Tree, newNamesToNodes);
     foreach (var entry in newNamesToNodes)
     {
         matcher.NewNodeNames.Add(entry.Key, entry.Value);
     }
     return new AuxiliaryTree(result.Item1, result.Item2, newNamesToNodes, originalTreeString);
 }
        /// <summary>
        /// Copies the Auxiliary tree.  Also, puts the new names->nodes map in the TsurgeonMatcher that called copy.
        /// </summary>
        public AuxiliaryTree Copy(TsurgeonMatcher matcher)
        {
            var newNamesToNodes       = new Dictionary <string, Tree>();
            Tuple <Tree, Tree> result = CopyHelper(Tree, newNamesToNodes);

            foreach (var entry in newNamesToNodes)
            {
                matcher.NewNodeNames.Add(entry.Key, entry.Value);
            }
            return(new AuxiliaryTree(result.Item1, result.Item2, newNamesToNodes, originalTreeString));
        }
Exemple #6
0
        /// <summary>
        /// Tries to match a pattern against a tree.  If it succeeds, apply the surgical operations contained in a {@link TsurgeonPattern}.
        /// </summary>
        /// <param name="matchPattern">A {@link TregexPattern} to be matched against a {@link Tree}.</param>
        /// <param name="p">A {@link TsurgeonPattern} to apply.</param>
        /// <param name="t">the {@link Tree} to match against and perform surgery on.</param>
        /// <returns>t, which has been surgically modified.</returns>
        public static Tree ProcessPattern(TregexPattern matchPattern, TsurgeonPattern p, Tree t)
        {
            TregexMatcher   m   = matchPattern.Matcher(t);
            TsurgeonMatcher tsm = p.GetMatcher();

            while (m.Find())
            {
                t = tsm.Evaluate(t, m);
                if (t == null)
                {
                    break;
                }
                m = matchPattern.Matcher(t);
            }
            return(t);
        }