Skip to content

Commit

Permalink
Allow dashes as the word in an expression with indices in SemanticGra…
Browse files Browse the repository at this point in the history
…ph.valueOf
  • Loading branch information
AngledLuffa committed Apr 5, 2023
1 parent 429688d commit 203eb06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/edu/stanford/nlp/semgraph/SemanticGraph.java
Expand Up @@ -1861,7 +1861,7 @@ public SemanticGraph makeSoftCopy() {

// ============================================================================

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

/**
* This nested class is a helper for valueOf(). It represents the task of
Expand Down
26 changes: 26 additions & 0 deletions test/src/edu/stanford/nlp/semgraph/SemanticGraphTest.java
Expand Up @@ -304,6 +304,32 @@ public void testValueOfSimple() {
assertEquals(sg.getParentsWithReln(E, "dep").size(), 0);
}

/**
* Test that dashes as the word work as expected with indices
*/
public void testValueOfDashes() {
SemanticGraph sg = SemanticGraph.valueOf("[--3 obj> -/bar-1 obj> C-4 nsubj> [D-2 obj> E-0]]");

List<IndexedWord> words = sg.vertexListSorted();
assertEquals(words.size(), 5);

for (int i = 0; i < 5; ++i) {
assertEquals(words.get(i).index(), i);
}
IndexedWord A = words.get(3);
IndexedWord B = words.get(1);
IndexedWord C = words.get(4);
IndexedWord D = words.get(2);
IndexedWord E = words.get(0);

assertEquals(A.word(), "-");
assertEquals(B.word(), "-");
assertEquals(B.tag(), "bar");
assertEquals(C.word(), "C");
assertEquals(D.word(), "D");
assertEquals(E.word(), "E");
}

/**
* Test the vertices and edges of a very simple valueOf graph with indices added
*/
Expand Down

0 comments on commit 203eb06

Please sign in to comment.