{"record":{"id":"f3a1ceea42e4daf7","repo":"stanfordnlp/CoreNLP","slug":"found-a-relation-with-a-missing-entity-p","errorCode":null,"errorMessage":"Found a relation with a missing entity: ${p}","messagePattern":"Found a relation with a missing entity: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/ie/KBPSemgrexExtractor.java","lineNumber":121,"sourceCode":"        tokens.get(i).setNER(input.subjectType.name);\n      }\n    }\n    for (int i : input.objectSpan) {\n      if (\"O\".equals(tokens.get(i).ner())) {\n        tokens.get(i).setNER(input.objectType.name);\n      }\n    }\n\n    for (SemgrexPattern p : rulesForRel) {\n\n      SemgrexMatcher n = p.matcher(graph);\n      while (n.find()) {\n        IndexedWord entity = n.getNode(\"entity\");\n        IndexedWord slot = n.getNode(\"slot\");\n        if (entity == null) {\n          // really this is a hideous bug, right?  these rules\n          // should all have entity and slot set\n          logger.warn(\"Found a relation with a missing entity: \" + p);\n          continue;\n        }\n        if (slot == null) {\n          logger.warn(\"Found a relation with a missing slot: \" + p);\n          continue;\n        }\n        boolean hasSubject = entity.index() >= input.subjectSpan.start() + 1 && entity.index() <= input.subjectSpan.end();\n        boolean hasObject  = slot.index() >= input.objectSpan.start() + 1 && slot.index() <= input.objectSpan.end();\n        \n        if (hasSubject && hasObject) {\n          return p;\n        } \n      }\n    }\n    return null;\n  }\n\n","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/KBPSemgrexExtractor.java#L103-L139","documentation":"KBPSemgrexExtractor.matches iterates SemgrexMatcher node matches and expects named nodes 'entity' and 'slot' in each pattern. If the 'entity' named node is absent from the matched graph, it warns with the pattern p and skips that match, treating it as a rule-authoring bug rather than a runtime failure.","triggerScenarios":"A Semgrex pattern used for KBP extraction that does not (or conditionally does not) bind the 'entity' named node, e.g. pattern string missing '{word:/.../}=entity' naming, and the matcher finds a hit without that node.","commonSituations":"Hand-written or edited Semgrex rules missing one of the required named groups; rules copied from other pipelines with different group names; optional groups that fail to bind on some matches.","solutions":["Add the named node '=entity' to the Semgrex pattern (e.g. add \"{...}=entity\")","Check the rule resources/patterns file for missing group names and fix the authoring","Log the offending pattern and remove/disable it if it's obsolete","Verify with a small Semgrex test that getNode(\"entity\") returns non-null for intended matches"],"exampleFix":"// before\nString p = \"{tag:/NN.*/}=slot <nsubj {tag:/NN.*/}\";\n// after\nString p = \"{tag:/NN.*/}=entity <nsubj {tag:/NN.*/}=slot\";","handlingStrategy":"validation","validationCode":"SemgrexPattern p = SemgrexPattern.compile(pattern);\n// ensure required named groups exist in the pattern string\nif (!pattern.contains(\"=entity\")) throw new IllegalArgumentException(\"pattern missing =entity: \" + pattern);","typeGuard":null,"tryCatchPattern":"SemgrexMatcher m = p.matcher(graph);\nwhile (m.find()) {\n  IndexedWord entity = m.getNode(\"entity\");\n  if (entity == null) { log.warn(\"no entity for \" + pattern); continue; }\n  // ...\n}","preventionTips":["Always name both =entity and =slot groups in KBP Semgrex rules","Unit-test each rule on annotated sample sentences","Review rule resource files after edits for dropped group names","Log and quarantine patterns that repeatedly produce null nodes"],"tags":["java","nlp","semgrex","rule-authoring"],"backgroundTag":"internal-invariant-violation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}