|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.trees.tregex.TreeMatcher
public class TreeMatcher
Matches a TreePattern
against a Tree
. For programmatic
usage, the important methods are:
reset()
resets the TreeMatcher
find()
attempts to find the next match of the
TreePattern to the Tree.
matches(edu.stanford.nlp.trees.Tree)
determines whether the TreePattern matches
the Tree at the root of the Tree.
getMatch()
once a match has been found, returns the
Tree node corresponding to the root of the TreePattern.
getNode(java.lang.Object)
once a match has been found, allows you to
use the name given to a node description in the TreePattern to
retrieve the node matched to that node description
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.
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 |
---|
public boolean matches(Tree t)
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.
t
- the supplied tree node for a matchpublic TreeMatcher reset()
public boolean find()
public Tree getMatch()
public Tree getNode(Object name)
public static void main(String[] args)
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.
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)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |