@@ -166,7 +166,8 @@ private Attribute buildRegexAttribute(String key, String value, boolean negated,
166
166
}
167
167
}
168
168
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 ) {
170
171
if (nodeValue == null ) {
171
172
// treat non-existent attributes has having matched a negated expression
172
173
// 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,
188
189
Matcher matcher = ((Pattern ) toMatch ).matcher (nodeValue );
189
190
if (matcher .matches ()) {
190
191
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
+ }
192
206
} else {
193
207
matches = false ;
194
208
}
@@ -203,7 +217,7 @@ private boolean checkMatch(Attribute attr, boolean ignoreCase, String nodeValue,
203
217
204
218
@ SuppressWarnings ("unchecked" )
205
219
public boolean nodeAttrMatch (IndexedWord node , final SemanticGraph sg , boolean ignoreCase ,
206
- VariableStrings tempVariableStrings ) {
220
+ VariableStrings variableStrings , VariableStrings tempVariableStrings ) {
207
221
// System.out.println(node.word());
208
222
if (isRoot ) {
209
223
// System.out.println("checking root");
@@ -237,7 +251,7 @@ public boolean nodeAttrMatch(IndexedWord node, final SemanticGraph sg, boolean i
237
251
// }
238
252
// System.out.println(nodeValue);
239
253
240
- boolean matches = checkMatch (attr , ignoreCase , nodeValue , tempVariableStrings );
254
+ boolean matches = checkMatch (attr , ignoreCase , nodeValue , variableStrings , tempVariableStrings );
241
255
242
256
if (!matches ) {
243
257
// System.out.println("doesn't match");
@@ -265,7 +279,7 @@ public boolean nodeAttrMatch(IndexedWord node, final SemanticGraph sg, boolean i
265
279
}
266
280
267
281
// TODO: not connected to varGroups yet
268
- boolean matches = checkMatch (attr , ignoreCase , nodeValue , tempVariableStrings );
282
+ boolean matches = checkMatch (attr , ignoreCase , nodeValue , variableStrings , tempVariableStrings );
269
283
if (!matches ) {
270
284
return negDesc ;
271
285
}
@@ -519,7 +533,7 @@ private void goToNextNodeMatch() {
519
533
} else {
520
534
boolean found = myNode .nodeAttrMatch (nextMatch ,
521
535
hyp ? sg : sg_aligned ,
522
- ignoreCase , tempVariableStrings );
536
+ ignoreCase , variableStrings , tempVariableStrings );
523
537
if (found ) {
524
538
// nodeAttrMatch already checks negDesc, so no need to
525
539
// check for that here
@@ -530,7 +544,7 @@ private void goToNextNodeMatch() {
530
544
} else { // try to match the description pattern.
531
545
boolean found = myNode .nodeAttrMatch (nextMatch ,
532
546
hyp ? sg : sg_aligned ,
533
- ignoreCase , tempVariableStrings );
547
+ ignoreCase , variableStrings , tempVariableStrings );
534
548
if (found ) {
535
549
// nodeAttrMatch already checks negDesc, so no need to
536
550
// check for that here
0 commit comments