Skip to content

Commit d622867

Browse files
committed
Add a test of the numbers of things returned by a batch search over a set of graphs
1 parent 570af1f commit d622867

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import junit.framework.AssertionFailedError;
44
import junit.framework.TestCase;
55

6+
import java.util.ArrayList;
67
import java.util.HashMap;
8+
import java.util.List;
79
import java.util.Map;
810
import java.util.Set;
911

@@ -13,7 +15,11 @@
1315
import edu.stanford.nlp.trees.UniversalEnglishGrammaticalRelations;
1416
import edu.stanford.nlp.trees.Tree;
1517
import edu.stanford.nlp.trees.ud.CoNLLUFeatures;
18+
import edu.stanford.nlp.util.ArrayCoreMap;
19+
import edu.stanford.nlp.util.CoreMap;
20+
import edu.stanford.nlp.util.Pair;
1621
import edu.stanford.nlp.semgraph.SemanticGraph;
22+
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
1723
import edu.stanford.nlp.semgraph.SemanticGraphEdge;
1824
import edu.stanford.nlp.semgraph.SemanticGraphFactory;
1925

@@ -1442,6 +1448,40 @@ public void testBrackets() {
14421448
"[ate/VBD subj>Billz/NNP obj>[muffins compound>strawberry]]");
14431449
}
14441450

1451+
/**
1452+
* A simple test of the batch search - should return 3 of the 4 sentences
1453+
*/
1454+
public void testBatchSearch() {
1455+
String[] parses = {
1456+
"[foo-1 nmod> bar-2]",
1457+
"[foo-1 obj> bar-2]",
1458+
"[bar-1 compound> baz-2]",
1459+
"[foo-1 nmod> baz-2 obj> bar-3]",
1460+
};
1461+
List<CoreMap> sentences = new ArrayList<>();
1462+
for (String parse : parses) {
1463+
SemanticGraph graph = SemanticGraph.valueOf(parse);
1464+
CoreMap sentence = new ArrayCoreMap();
1465+
sentence.set(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class, graph);
1466+
sentence.set(CoreAnnotations.TextAnnotation.class, parse);
1467+
sentences.add(sentence);
1468+
}
1469+
1470+
SemgrexPattern semgrex = SemgrexPattern.compile("{word:foo}=x > {}=y");
1471+
List<Pair<CoreMap, List<SemgrexMatch>>> matches = semgrex.matchSentences(sentences);
1472+
String[] expectedMatches = {
1473+
parses[0],
1474+
parses[1],
1475+
parses[3],
1476+
};
1477+
int[] expectedCount = {1, 1, 2};
1478+
assertEquals(expectedMatches.length, matches.size());
1479+
for (int i = 0; i < expectedMatches.length; ++i) {
1480+
assertEquals(expectedMatches[i], matches.get(i).first().get(CoreAnnotations.TextAnnotation.class));
1481+
assertEquals(expectedCount[i], matches.get(i).second().size());
1482+
}
1483+
}
1484+
14451485
public static void outputResults(String pattern, String graph,
14461486
String ... ignored) {
14471487
outputResults(SemgrexPattern.compile(pattern),

0 commit comments

Comments
 (0)