Skip to content

Commit bad259f

Browse files
committed
Test works now. Was missing a check against null for the map
1 parent 7bb9a99 commit bad259f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,15 @@ public boolean nodeAttrMatch(IndexedWord node, final SemanticGraph sg, boolean i
239239

240240
Class clazz = Env.lookupAnnotationKey(env, annotation);
241241
Object rawmap = node.get(clazz);
242+
// if the map is null, it can't possibly match...
243+
if (rawmap == null) {
244+
return negDesc;
245+
}
242246
if (!(rawmap instanceof Map))
243247
throw new RuntimeException("Can only use partial attributes with Maps... this should have been checked at creation time!");
244248
Map<String, ?> map = (Map) rawmap;
245249

250+
// TODO: allow for regex match on the keys?
246251
Object value = map.get(attr.key);
247252
final String nodeValue = (value == null) ? null : value.toString();
248253
boolean matches = checkMatch(attr, ignoreCase, nodeValue);

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Map;
88
import java.util.Set;
99

10+
import edu.stanford.nlp.ling.CoreAnnotations;
1011
import edu.stanford.nlp.ling.IndexedWord;
1112
import edu.stanford.nlp.stats.IntCounter;
1213
import edu.stanford.nlp.trees.UniversalEnglishGrammaticalRelations;
@@ -242,9 +243,10 @@ public void testContainsExpression() {
242243
if (iw.value().equals("D") || iw.value().equals("F")) {
243244
CoNLLUFeatures feats = new CoNLLUFeatures();
244245
feats.put("foo", "bar");
246+
iw.set(CoreAnnotations.CoNLLUFeats.class, feats);
245247
}
246248
}
247-
//outputResults(pattern, graph);
249+
runTest(pattern, graph, "D", "F");
248250
}
249251

250252
public void testReferencedRegex() {

0 commit comments

Comments
 (0)