edu.stanford.nlp.trees.tregex
Class TreeMatcher

java.lang.Object
  extended by edu.stanford.nlp.trees.tregex.TreeMatcher

public class TreeMatcher
extends Object

Matches a TreePattern against a Tree. For programmatic usage, the important methods are:

For running it from the command line, see the main method for a description of command line arguments and the TreePattern class for a description of supported tree patterns.

Author:
Roger Levy

Nested Class Summary
static class TreeMatcher.TRegexTreeReaderFactory
           
 
Method Summary
 boolean find()
          Attempts to find the next match, if any.
 Tree getMatch()
          Returns the root node currently matched by the TreePattern
 Tree getNode(Object name)
          Returns the relevant node in the pattern by the name it was given in the TreePattern
static void main(String[] args)
          Use to match a tree pattern to the trees in files.
 boolean matches(Tree t)
          Attempts to match the input TreePattern against the specified Tree, at the supplied Tree node t.
 TreeMatcher reset()
          Resets the TreeMatcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

matches

public boolean matches(Tree t)
Attempts to match the input TreePattern against the specified Tree, at the supplied Tree node t. Stops at the first full match, if any.

At the moment, matches() is fairly inefficiently implemented: for cases where the root tree-pattern node description matches t but the rest of the pattern does not match given that assignment, it actually traverses the entire tree and the entire pattern to look for a deeper complete match before rejecting any that it may find. Hopefully this will be fixed in the future.

Parameters:
t - the supplied tree node for a match

reset

public TreeMatcher reset()
Resets the TreeMatcher.


find

public boolean find()
Attempts to find the next match, if any.


getMatch

public Tree getMatch()
Returns the root node currently matched by the TreePattern


getNode

public Tree getNode(Object name)
Returns the relevant node in the pattern by the name it was given in the TreePattern


main

public static void main(String[] args)
Use to match a tree pattern to the trees in files. Usage:

java edu.stanford.nlp.trees.tregex.TreeMatcher [-T] [-C] [-w] [-f] [-tn TN] pattern [handle] filepath

It prints out all the matches of the tree pattern to every tree in the treebank rooted at the filepath.

Parameters:
args - Command line arguments: Argument 1 is the tree pattern which might name a node with =name (for some arbitrary string "name"), argument 2 is an optional name =name, and argument 3 is a filepath to files with trees. A -T flag causes all trees to be printed as processed. Otherwise just matches are printed. The -C flag suppresses printing of matches, so only a number of matches is printed. The -w flag causes the whole of a tree that matches to be printed. The -f flag prints the filename of the file containing each match. The -tn flag is followed by the name of a TreeNormalizer class, which can be used to normalize trees before they are matched (e.g., to strip functional tags)


Stanford NLP Group