Skip to content

Commit baedc9a

Browse files
committed
Flesh out the test a bit more
1 parent 9711192 commit baedc9a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

test/src/edu/stanford/nlp/semgraph/semgrex/SemgrexTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ public void testBatchUniq() {
15751575
public void testVariableGroups() {
15761576
// first, a basic test that it is capturing the variable groups correctly
15771577
SemgrexPattern pattern = SemgrexPattern.compile("{word:/(.*ill.*)/#1%name}");
1578-
SemanticGraph graph = SemanticGraph.valueOf("[ate-2 subj> Bill-1 obj>[muffins-5 compound> Blueberry-3 compound> filled-4]]");
1578+
SemanticGraph graph = SemanticGraph.valueOf("[ate-2 subj> Bill-1 obj>[muffins-6 compound> Blueberry-3 compound> Flueberry-4 compound> filled-5]]");
15791579
Set<String> matches = new HashSet<>();
15801580
SemgrexMatcher matcher = pattern.matcher(graph);
15811581
while (matcher.find()) {
@@ -1586,11 +1586,30 @@ public void testVariableGroups() {
15861586
Set<String> expectedMatches = Stream.of("Bill", "filled").collect(Collectors.toCollection(HashSet::new));
15871587
assertEquals(expectedMatches, matches);
15881588

1589+
// test a basic use case of a single variable string matching
15891590
pattern = SemgrexPattern.compile("{word:/(.*)ill/#1%name} .. {word:/(.*)lueberry/#1%name}");
15901591
matcher = pattern.matcher(graph);
15911592
assertTrue(matcher.find());
15921593
assertEquals("B", matcher.variableStrings.getString("name"));
1594+
// this should not match Flueberry
15931595
assertFalse(matcher.find());
1596+
1597+
// this time, because the variable names are different,
1598+
// both Blueberry and Flueberry should match
1599+
pattern = SemgrexPattern.compile("{word:/(.*)ill/#1%name} .. {word:/(.*)lueberry/#1%letter}");
1600+
matcher = pattern.matcher(graph);
1601+
matches.clear();
1602+
assertTrue(matcher.find());
1603+
assertEquals("B", matcher.variableStrings.getString("name"));
1604+
assertNotNull(matcher.variableStrings.getString("letter"));
1605+
matches.add(matcher.variableStrings.getString("letter"));
1606+
assertTrue(matcher.find());
1607+
assertEquals("B", matcher.variableStrings.getString("name"));
1608+
assertNotNull(matcher.variableStrings.getString("letter"));
1609+
matches.add(matcher.variableStrings.getString("letter"));
1610+
assertFalse(matcher.find());
1611+
expectedMatches = Stream.of("B", "F").collect(Collectors.toCollection(HashSet::new));
1612+
assertEquals(expectedMatches, matches);
15941613
}
15951614

15961615
public static void outputBatchResults(SemgrexPattern pattern, List<CoreMap> sentences) {

0 commit comments

Comments
 (0)