Skip to content

Commit ef889a6

Browse files
committed
Check that the annotation used for key/value is actually a Map
1 parent 8a2bb78 commit ef889a6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.regex.Matcher;
99
import java.util.regex.Pattern;
1010

11+
import edu.stanford.nlp.ling.AnnotationLookup;
1112
import edu.stanford.nlp.ling.IndexedWord;
1213
import edu.stanford.nlp.semgraph.SemanticGraph;
1314
import edu.stanford.nlp.semgraph.SemanticGraphEdge;
@@ -95,6 +96,12 @@ public NodePattern(GraphRelation r, boolean negDesc,
9596
String key = entry.second();
9697
String value = entry.third();
9798

99+
Class<?> clazz = AnnotationLookup.getValueType(AnnotationLookup.toCoreKey(annotation));
100+
boolean isMap = clazz != null && Map.class.isAssignableFrom(clazz);
101+
if (!isMap) {
102+
throw new SemgrexParseException("Cannot process a single key/value from annotation " + annotation + " as it is not a Map");
103+
}
104+
98105
final Attribute attr;
99106
// Add the attributes for this key
100107
if (value.equals("__")) {
@@ -229,6 +236,7 @@ public boolean nodeAttrMatch(IndexedWord node, final SemanticGraph sg, boolean i
229236
for (Pair<String, Attribute> partialAttribute : partialAttributes) {
230237
String annotation = partialAttribute.first();
231238
Attribute attr = partialAttribute.second();
239+
Class clazz = Env.lookupAnnotationKey(env, annotation);
232240
// TODO
233241
}
234242

0 commit comments

Comments
 (0)