public class TreeGrep<T> extends Object
Usage:
Suppose tree
is some tree and we wish to find all instances of pattern
in it.
TreeGrep<String> grepper = new TreeGrep<String>(pattern); if (grepper.matches(tree)) { List<TreeGrepMatch<String>> matches = grepper.getMatches(); for (TreeGrepMatch<String> match : matches) { // do something with the match } }Refer the documentation of
TreeGrepMatch
for details about how to use it the match
object. This class does not yet support regular expression searches for trees like tregex or
tgrep. Moreover, the current implementation can be improved by using something like the
Boyer-Moore algorithm for both vertical and horizontal search.TreeGrepMatch
Modifier and Type | Field and Description |
---|---|
static String |
endOfChildrenString |
protected List<TreeGrepMatch<T>> |
matchesList |
static String |
startOfChildrenString |
Modifier and Type | Method and Description |
---|---|
protected boolean |
doesLabelMatchPatternLabel(T treeLabel,
T patternLabel) |
protected List<TreeGrepMatch<T>> |
doesNodeMatchPattern(Tree<T> tree,
Tree<T> currentPattern,
List<TreeGrepMatch<T>> nodeMatches) |
boolean |
doesThisTreeMatch(Tree<T> tree)
Checks if the tree that is passed as a parameter matches the pattern.
|
List<TreeGrepMatch<T>> |
getMatches()
Gets a list of matches for the pattern in the most recently searched tree.
|
Tree<T> |
getPattern() |
boolean |
matches(Tree<T> tree)
This checks whether any subtrees of
tree match the pattern. |
protected List<TreeGrepMatch<T>> |
mergeChildrenMatches(List<List<TreeGrepMatch<T>>> childrenMatches,
List<TreeGrepMatch<T>> currentNodeMatches) |
String |
toString() |
public static String endOfChildrenString
public static String startOfChildrenString
protected List<TreeGrepMatch<T>> matchesList
public boolean matches(Tree<T> tree)
tree
match the pattern.
Note: Each subtree might have multiple matches within it that match the pattern. For example, if the pattern is
(VP (NP NN ))
and the tree has
(VP (NP NN) (NP NN))
then, this function will only return the (VP...)
subtree, and does not indicate
that there are two matches within that subtree, both rooted at the VP
.
public boolean doesThisTreeMatch(Tree<T> tree)
matches(Tree)
because it does not recursively check interior nodes for matches.public List<TreeGrepMatch<T>> getMatches()
TreeGrepMatch
objects. See the general documentation of this class
for a sample usage.protected boolean doesLabelMatchPatternLabel(T treeLabel, T patternLabel)
protected List<TreeGrepMatch<T>> doesNodeMatchPattern(Tree<T> tree, Tree<T> currentPattern, List<TreeGrepMatch<T>> nodeMatches)
protected List<TreeGrepMatch<T>> mergeChildrenMatches(List<List<TreeGrepMatch<T>>> childrenMatches, List<TreeGrepMatch<T>> currentNodeMatches)
Copyright © 2017. All rights reserved.