@@ -1575,7 +1575,7 @@ public void testBatchUniq() {
1575
1575
public void testVariableGroups () {
1576
1576
// first, a basic test that it is capturing the variable groups correctly
1577
1577
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 ]]" );
1579
1579
Set <String > matches = new HashSet <>();
1580
1580
SemgrexMatcher matcher = pattern .matcher (graph );
1581
1581
while (matcher .find ()) {
@@ -1586,11 +1586,30 @@ public void testVariableGroups() {
1586
1586
Set <String > expectedMatches = Stream .of ("Bill" , "filled" ).collect (Collectors .toCollection (HashSet ::new ));
1587
1587
assertEquals (expectedMatches , matches );
1588
1588
1589
+ // test a basic use case of a single variable string matching
1589
1590
pattern = SemgrexPattern .compile ("{word:/(.*)ill/#1%name} .. {word:/(.*)lueberry/#1%name}" );
1590
1591
matcher = pattern .matcher (graph );
1591
1592
assertTrue (matcher .find ());
1592
1593
assertEquals ("B" , matcher .variableStrings .getString ("name" ));
1594
+ // this should not match Flueberry
1593
1595
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 );
1594
1613
}
1595
1614
1596
1615
public static void outputBatchResults (SemgrexPattern pattern , List <CoreMap > sentences ) {
0 commit comments