Skip to content

Commit a89dadc

Browse files
committed
Add a _ROOT_ description which matches exactly the root of a tree
1 parent 974ba41 commit a89dadc

File tree

7 files changed

+267
-180
lines changed

7 files changed

+267
-180
lines changed

src/edu/stanford/nlp/trees/tregex/DescriptionPattern.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class DescriptionPattern extends TregexPattern {
1818
private static Redwood.RedwoodChannels log = Redwood.channels(DescriptionPattern.class);
1919

2020
enum DescriptionMode {
21-
PATTERN, STRINGS, EXACT, ANYTHING
21+
PATTERN, STRINGS, EXACT, ANYTHING, ROOT
2222
}
2323

2424
private final Relation rel;
@@ -77,6 +77,11 @@ public DescriptionPattern(Relation rel, boolean negDesc, String desc,
7777
descPattern = null;
7878
exactMatch = null;
7979
stringFilter = null;
80+
} else if (desc.equals("_ROOT_")) {
81+
descriptionMode = DescriptionMode.ROOT;
82+
descPattern = null;
83+
exactMatch = null;
84+
stringFilter = null;
8085
} else if (SINGLE_WORD_PATTERN.matcher(desc).matches()) {
8186
// Expressions are written like this to put special characters
8287
// in the tregex matcher, but a regular expression is less
@@ -403,6 +408,9 @@ private void goToNextTreeNodeMatch() {
403408
case STRINGS:
404409
found = myNode.stringFilter.test(value);
405410
break;
411+
case ROOT:
412+
found = (nextTreeNodeMatchCandidate == root);
413+
break;
406414
default:
407415
throw new IllegalArgumentException("Unexpected match mode");
408416
}

0 commit comments

Comments
 (0)