Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e2ff5c

Browse files
committed
Most basic connection of saving the values, not testing checking the values yet
1 parent0851981 commit9e2ff5c

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

‎src/edu/stanford/nlp/semgraph/semgrex/NodePattern.java‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ private Attribute buildRegexAttribute(String key, String value, boolean negated,
166166
}
167167
}
168168

169-
privatebooleancheckMatch(Attributeattr,booleanignoreCase,StringnodeValue,VariableStringstempVariableStrings) {
169+
privatebooleancheckMatch(Attributeattr,booleanignoreCase,StringnodeValue,
170+
VariableStringsvariableStrings,VariableStringstempVariableStrings) {
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
Matchermatcher = ((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+
StringexistingString =variableStrings.getString(varGroup.second());
194+
if (existingString ==null) {
195+
existingString =tempVariableStrings.getString(varGroup.second());
196+
}
197+
StringmatchedString =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
publicbooleannodeAttrMatch(IndexedWordnode,finalSemanticGraphsg,booleanignoreCase,
206-
VariableStringstempVariableStrings) {
220+
VariableStringsvariableStrings,VariableStringstempVariableStrings) {
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-
booleanmatches =checkMatch(attr,ignoreCase,nodeValue,tempVariableStrings);
254+
booleanmatches =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-
booleanmatches =checkMatch(attr,ignoreCase,nodeValue,tempVariableStrings);
282+
booleanmatches =checkMatch(attr,ignoreCase,nodeValue,variableStrings,tempVariableStrings);
269283
if (!matches) {
270284
returnnegDesc;
271285
}
@@ -519,7 +533,7 @@ private void goToNextNodeMatch() {
519533
}else {
520534
booleanfound =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
booleanfound =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

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
importjava.util.ArrayList;
77
importjava.util.HashMap;
8+
importjava.util.HashSet;
89
importjava.util.List;
910
importjava.util.Map;
1011
importjava.util.Set;
12+
importjava.util.stream.Collectors;
13+
importjava.util.stream.Stream;
1114

1215
importedu.stanford.nlp.ling.CoreAnnotations;
1316
importedu.stanford.nlp.ling.IndexedWord;
@@ -1570,9 +1573,16 @@ public void testBatchUniq() {
15701573
}
15711574

15721575
publicvoidtestVariableGroups() {
1573-
outputResults("{word:/(ate)/#1%name}",
1574-
"[ate subj>Bill obj>[muffins compound>blueberry]]",
1575-
"ate");
1576+
SemgrexPatternpattern =SemgrexPattern.compile("{word:/(.*ill.*)/#1%name}");
1577+
SemanticGraphgraph =SemanticGraph.valueOf("[ate-2 subj> Bill-1 obj>[muffins-5 compound> Blueberry-3 compound> filled-4]]");
1578+
Set<String>matches =newHashSet<>();
1579+
SemgrexMatchermatcher =pattern.matcher(graph);
1580+
while (matcher.find()) {
1581+
assertNotNull(matcher.variableStrings.getString("name"));
1582+
matches.add(matcher.variableStrings.getString("name"));
1583+
}
1584+
Set<String>expectedMatches =Stream.of("Bill","filled").collect(Collectors.toCollection(HashSet::new));
1585+
assertEquals(expectedMatches,matches);
15761586
}
15771587

15781588
publicstaticvoidoutputBatchResults(SemgrexPatternpattern,List<CoreMap>sentences) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp