|
3 | 3 | import junit.framework.AssertionFailedError;
|
4 | 4 | import junit.framework.TestCase;
|
5 | 5 |
|
| 6 | +import java.util.ArrayList; |
6 | 7 | import java.util.HashMap;
|
| 8 | +import java.util.List; |
7 | 9 | import java.util.Map;
|
8 | 10 | import java.util.Set;
|
9 | 11 |
|
|
13 | 15 | import edu.stanford.nlp.trees.UniversalEnglishGrammaticalRelations;
|
14 | 16 | import edu.stanford.nlp.trees.Tree;
|
15 | 17 | 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; |
16 | 21 | import edu.stanford.nlp.semgraph.SemanticGraph;
|
| 22 | +import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations; |
17 | 23 | import edu.stanford.nlp.semgraph.SemanticGraphEdge;
|
18 | 24 | import edu.stanford.nlp.semgraph.SemanticGraphFactory;
|
19 | 25 |
|
@@ -1442,6 +1448,40 @@ public void testBrackets() {
|
1442 | 1448 | "[ate/VBD subj>Billz/NNP obj>[muffins compound>strawberry]]");
|
1443 | 1449 | }
|
1444 | 1450 |
|
| 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 | + |
1445 | 1485 | public static void outputResults(String pattern, String graph,
|
1446 | 1486 | String ... ignored) {
|
1447 | 1487 | outputResults(SemgrexPattern.compile(pattern),
|
|
0 commit comments