Skip to content

Commit a9965b2

Browse files
committed
Fix the output of optional CoordinationPatterns in Tregex
1 parent 9c67d39 commit a9965b2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ public String toString() {
4545
if (isNegated()) {
4646
sb.append("!(");
4747
}
48+
if (isOptional()) {
49+
sb.append("?(");
50+
}
4851
for (TregexPattern node : children) {
4952
sb.append(node.toString());
5053
}
51-
if (isNegated()) {
54+
if (isNegated() || isOptional()) {
5255
sb.append(")");
5356
}
5457
} else {

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

+2
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ public String toString() {
266266
sb.append('=');
267267
sb.append(name);
268268
}
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
269271
sb.append(' ');
270272
if (child != null) {
271273
sb.append(child.toString());

test/src/edu/stanford/nlp/trees/tregex/TregexTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,15 @@ public void testNegatedOptional() {
15591559
}
15601560
}
15611561

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+
15621571
/**
15631572
* A user supplied an example of a negated disjunction which went into an infinite loop.
15641573
* Apparently no one had ever used a negated disjunction of tree structures before!

0 commit comments

Comments
 (0)