File tree 3 files changed +15
-1
lines changed
src/edu/stanford/nlp/trees/tregex
test/src/edu/stanford/nlp/trees/tregex
3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -45,10 +45,13 @@ public String toString() {
45
45
if (isNegated ()) {
46
46
sb .append ("!(" );
47
47
}
48
+ if (isOptional ()) {
49
+ sb .append ("?(" );
50
+ }
48
51
for (TregexPattern node : children ) {
49
52
sb .append (node .toString ());
50
53
}
51
- if (isNegated ()) {
54
+ if (isNegated () || isOptional () ) {
52
55
sb .append (")" );
53
56
}
54
57
} else {
Original file line number Diff line number Diff line change @@ -266,6 +266,8 @@ public String toString() {
266
266
sb .append ('=' );
267
267
sb .append (name );
268
268
}
269
+ // TODO: is this space necessary? The CoordinationPattern could put spaces between terms
270
+ // Currently this results in extra blank spaces at the end of a pattern
269
271
sb .append (' ' );
270
272
if (child != null ) {
271
273
sb .append (child .toString ());
Original file line number Diff line number Diff line change @@ -1559,6 +1559,15 @@ public void testNegatedOptional() {
1559
1559
}
1560
1560
}
1561
1561
1562
+ public void testOptionalToString () {
1563
+ TregexPattern pattern ;
1564
+ pattern = TregexPattern .compile ("A ?(< B < C)" );
1565
+ assertEquals ("Root (A ?(< B < C ))" , pattern .toString ());
1566
+
1567
+ pattern = TregexPattern .compile ("A ?< B" );
1568
+ assertEquals ("Root (A ?< B )" , pattern .toString ());
1569
+ }
1570
+
1562
1571
/**
1563
1572
* A user supplied an example of a negated disjunction which went into an infinite loop.
1564
1573
* Apparently no one had ever used a negated disjunction of tree structures before!
You can’t perform that action at this time.
0 commit comments