Skip to content

Commit 203eb06

Browse files
committed
Allow dashes as the word in an expression with indices in SemanticGraph.valueOf
1 parent 429688d commit 203eb06

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/edu/stanford/nlp/semgraph/SemanticGraph.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ public SemanticGraph makeSoftCopy() {
18611861

18621862
// ============================================================================
18631863

1864-
private static final Pattern WORD_AND_INDEX_PATTERN = Pattern.compile("([^-]*)-([0-9]+)");
1864+
private static final Pattern WORD_AND_INDEX_PATTERN = Pattern.compile("(.*)-([0-9]+)");
18651865

18661866
/**
18671867
* This nested class is a helper for valueOf(). It represents the task of

test/src/edu/stanford/nlp/semgraph/SemanticGraphTest.java

+26
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,32 @@ public void testValueOfSimple() {
304304
assertEquals(sg.getParentsWithReln(E, "dep").size(), 0);
305305
}
306306

307+
/**
308+
* Test that dashes as the word work as expected with indices
309+
*/
310+
public void testValueOfDashes() {
311+
SemanticGraph sg = SemanticGraph.valueOf("[--3 obj> -/bar-1 obj> C-4 nsubj> [D-2 obj> E-0]]");
312+
313+
List<IndexedWord> words = sg.vertexListSorted();
314+
assertEquals(words.size(), 5);
315+
316+
for (int i = 0; i < 5; ++i) {
317+
assertEquals(words.get(i).index(), i);
318+
}
319+
IndexedWord A = words.get(3);
320+
IndexedWord B = words.get(1);
321+
IndexedWord C = words.get(4);
322+
IndexedWord D = words.get(2);
323+
IndexedWord E = words.get(0);
324+
325+
assertEquals(A.word(), "-");
326+
assertEquals(B.word(), "-");
327+
assertEquals(B.tag(), "bar");
328+
assertEquals(C.word(), "C");
329+
assertEquals(D.word(), "D");
330+
assertEquals(E.word(), "E");
331+
}
332+
307333
/**
308334
* Test the vertices and edges of a very simple valueOf graph with indices added
309335
*/

0 commit comments

Comments
 (0)