@@ -166,7 +166,8 @@ private Attribute buildRegexAttribute(String key, String value, boolean negated,
166166 }
167167 }
168168
169- private boolean checkMatch (Attribute attr , boolean ignoreCase , String nodeValue , VariableStrings tempVariableStrings ) {
169+ private boolean checkMatch (Attribute attr , boolean ignoreCase , String nodeValue ,
170+ VariableStrings variableStrings , VariableStrings tempVariableStrings ) {
170171 if (nodeValue == null ) {
171172 // treat non-existent attributes has having matched a negated expression
172173 // so for example, `cpos!:NUM` matches not having a cpos at all
@@ -188,7 +189,20 @@ private boolean checkMatch(Attribute attr, boolean ignoreCase, String nodeValue,
188189 Matcher matcher = ((Pattern ) toMatch ).matcher (nodeValue );
189190 if (matcher .matches ()) {
190191 matches = true ;
191- // TODO: check the VariableStrings here
192+ for (Pair <Integer , String > varGroup : attr .variableGroups ) {
193+ String existingString = variableStrings .getString (varGroup .second ());
194+ if (existingString == null ) {
195+ existingString = tempVariableStrings .getString (varGroup .second ());
196+ }
197+ String matchedString = matcher .group (varGroup .first ());
198+ if (existingString != null && !existingString .equals (matchedString )) {
199+ matches = false ;
200+ break ;
201+ }
202+ if (matchedString != null ) {
203+ tempVariableStrings .setVar (varGroup .second (), matchedString );
204+ }
205+ }
192206 } else {
193207 matches = false ;
194208 }
@@ -203,7 +217,7 @@ private boolean checkMatch(Attribute attr, boolean ignoreCase, String nodeValue,
203217
204218 @ SuppressWarnings ("unchecked" )
205219 public boolean nodeAttrMatch (IndexedWord node , final SemanticGraph sg , boolean ignoreCase ,
206- VariableStrings tempVariableStrings ) {
220+ VariableStrings variableStrings , VariableStrings tempVariableStrings ) {
207221 // System.out.println(node.word());
208222 if (isRoot ) {
209223 // System.out.println("checking root");
@@ -237,7 +251,7 @@ public boolean nodeAttrMatch(IndexedWord node, final SemanticGraph sg, boolean i
237251 // }
238252 // System.out.println(nodeValue);
239253
240- boolean matches = checkMatch (attr , ignoreCase , nodeValue , tempVariableStrings );
254+ boolean matches = checkMatch (attr , ignoreCase , nodeValue , variableStrings , tempVariableStrings );
241255
242256 if (!matches ) {
243257 // System.out.println("doesn't match");
@@ -265,7 +279,7 @@ public boolean nodeAttrMatch(IndexedWord node, final SemanticGraph sg, boolean i
265279 }
266280
267281 // TODO: not connected to varGroups yet
268- boolean matches = checkMatch (attr , ignoreCase , nodeValue , tempVariableStrings );
282+ boolean matches = checkMatch (attr , ignoreCase , nodeValue , variableStrings , tempVariableStrings );
269283 if (!matches ) {
270284 return negDesc ;
271285 }
@@ -519,7 +533,7 @@ private void goToNextNodeMatch() {
519533 } else {
520534 boolean found = myNode .nodeAttrMatch (nextMatch ,
521535 hyp ? sg : sg_aligned ,
522- ignoreCase , tempVariableStrings );
536+ ignoreCase , variableStrings , tempVariableStrings );
523537 if (found ) {
524538 // nodeAttrMatch already checks negDesc, so no need to
525539 // check for that here
@@ -530,7 +544,7 @@ private void goToNextNodeMatch() {
530544 } else { // try to match the description pattern.
531545 boolean found = myNode .nodeAttrMatch (nextMatch ,
532546 hyp ? sg : sg_aligned ,
533- ignoreCase , tempVariableStrings );
547+ ignoreCase , variableStrings , tempVariableStrings );
534548 if (found ) {
535549 // nodeAttrMatch already checks negDesc, so no need to
536550 // check for that here
0 commit comments