Example #1
0
 // hack-in field for seeing whether there was a match.
 public static Tree ProcessPatternsOnTree(IList <Pair <TregexPattern, TsurgeonPattern> > ops, Tree t)
 {
     matchedOnTree = false;
     foreach (Pair <TregexPattern, TsurgeonPattern> op in ops)
     {
         try
         {
             TregexMatcher   m   = op.First().Matcher(t);
             TsurgeonMatcher tsm = op.Second().Matcher();
             while (m.Find())
             {
                 matchedOnTree = true;
                 t             = tsm.Evaluate(t, m);
                 if (t == null)
                 {
                     return(null);
                 }
                 m = op.First().Matcher(t);
             }
         }
         catch (ArgumentNullException npe)
         {
             throw new Exception("Tsurgeon.processPatternsOnTree failed to match label for pattern: " + op.First() + ", " + op.Second(), npe);
         }
     }
     return(t);
 }
Example #2
0
 internal LocationMatcher(TreeLocation _enclosing, IDictionary <string, Tree> newNodeNames, CoindexationGenerator coindexer)
 {
     this._enclosing   = _enclosing;
     this.newNodeNames = newNodeNames;
     this.coindexer    = coindexer;
     this.childMatcher = this._enclosing.child.Matcher(newNodeNames, coindexer);
 }
        /// <summary>Copies the Auxiliary tree.</summary>
        /// <remarks>
        /// Copies the Auxiliary tree.  Also, puts the new names-&gt;nodes map in the TsurgeonMatcher that called copy.
        /// <br />
        /// The trees and labels to use when making the copy are specified
        /// with treeFactory and labelFactory.  This lets the tsurgeon script
        /// produce trees which are of the same type as the input trees.
        /// Each of the tsurgeon relations which copies a tree should include
        /// pass in the correct factories.
        /// </remarks>
        public virtual Edu.Stanford.Nlp.Trees.Tregex.Tsurgeon.AuxiliaryTree Copy(TsurgeonMatcher matcher, ITreeFactory treeFactory, ILabelFactory labelFactory)
        {
            if (labelFactory == null)
            {
                labelFactory = CoreLabel.Factory();
            }
            IDictionary <string, Tree> newNamesToNodes = Generics.NewHashMap();
            Pair <Tree, Tree>          result          = CopyHelper(tree, newNamesToNodes, treeFactory, labelFactory);

            //if(! result.first().dominates(result.second()))
            //log.info("Error -- aux tree copy doesn't dominate foot copy.");
            matcher.newNodeNames.PutAll(newNamesToNodes);
            return(new Edu.Stanford.Nlp.Trees.Tregex.Tsurgeon.AuxiliaryTree(result.First(), result.Second(), newNamesToNodes, originalTreeString));
        }
Example #4
0
        /// <summary>Tries to match a pattern against a tree.</summary>
        /// <remarks>
        /// Tries to match a pattern against a tree.  If it succeeds, apply the surgical operations contained in a
        /// <see cref="TsurgeonPattern"/>
        /// .
        /// </remarks>
        /// <param name="matchPattern">
        /// A
        /// <see cref="Edu.Stanford.Nlp.Trees.Tregex.TregexPattern"/>
        /// to be matched against a
        /// <see cref="Edu.Stanford.Nlp.Trees.Tree"/>
        /// .
        /// </param>
        /// <param name="p">
        /// A
        /// <see cref="TsurgeonPattern"/>
        /// to apply.
        /// </param>
        /// <param name="t">
        /// the
        /// <see cref="Edu.Stanford.Nlp.Trees.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.Matcher();

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