{"record":{"id":"b6e96f6d3a9b494e","repo":"stanfordnlp/CoreNLP","slug":"error-a-relation-was-marked-between-two-words-whe","errorCode":null,"errorMessage":"Error: a relation was marked between two words where one of the words was not a named entity.  Line causing this error: '${currentLine}'","messagePattern":"Error: a relation was marked between two words where one of the words was not a named entity\\.  Line causing this error: '(.+?)'","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/machinereading/domains/roth/RothCONLL04Reader.java","lineNumber":122,"sourceCode":"    while (lineIterator.hasNext() && numBlankLinesSeen < 2) {\n      String currentLine = lineIterator.next();\n      currentLine = currentLine.replace(\"COMMA\", \",\");\n\n      List<String> pieces = StringUtils.split(currentLine);\n      String identifier;\n\n      int size = pieces.size();\n      switch (size) {\n      case 1: // blank line between sentences or relations\n        numBlankLinesSeen++;\n        break;\n      case 3: // relation\n        String type = pieces.get(2);\n        List<ExtractionObject> args = new ArrayList<>();\n        EntityMention entity1 = indexToEntityMention.get(pieces.get(0));\n        EntityMention entity2 = indexToEntityMention.get(pieces.get(1));\n        if (entity1 == null || entity2 == null) {\n          throw new NullPointerException(\"Error: a relation was marked between two words where one of the words was not a named entity.  Line causing this error: '\" + currentLine + \"'\");\n        }\n        args.add(entity1);\n        args.add(entity2);\n        Span span = new Span(entity1.getExtentTokenStart(), entity2.getExtentTokenEnd());\n        // identifier = \"relation\" + sentenceID + \"-\" + sentence.getAllRelations().size();\n        identifier = RelationMention.makeUniqueId();\n        RelationMention relationMention = new RelationMention(identifier,\n            sentence, span, type, null, args);\n        AnnotationUtils.addRelationMention(sentence, relationMention);\n        break;\n      case 9: // token\n        /*\n         * Roth token lines look like this:\n         *\n         * 19 Peop 9 O NNP/NNP Jamal/Ghosheh O O O\n         */\n\n        // Entities may be multiple words joined by '/'; we split these up","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/machinereading/domains/roth/RothCONLL04Reader.java#L104-L140","documentation":"When readSentence parses a relation line (column type 3), it looks up the two argument word indices in the sentence's entity mentions. If either side is not a recognized named entity, it throws this NullPointerException, since relations must connect two named entities in the CoNLL04 format.","triggerScenarios":"A relation line (e.g. '3 5 Work_For') whose indices (3, 5) do not appear as entity words earlier in the same sentence — because the word was tagged 'Other'/not annotated as an entity, or entity indices shifted by parsing errors.","commonSituations":"Corrupted or hand-edited CoNLL04 files, relation annotations disagreeing with the NER column, feeding partially stripped files where entity lines were removed but relation lines kept.","solutions":["Fix the data file so every relation argument index refers to a word tagged as an entity (Peop/Loc/Org).","Regenerate relations from the corrected NER annotations.","Pre-validate the file: check each relation line's two indices exist in the sentence's entity set before reading.","Wrap readSentence in error handling to skip the offending sentence and continue."],"exampleFix":"// before\nRelation r = reader.readSentence(...);\n// after\ntry {\n  Relation r = reader.readSentence(...);\n} catch (NullPointerException e) {\n  logger.warning(\"skipping sentence: \" + e.getMessage());\n}","handlingStrategy":"validation","validationCode":"// per relation line 'i1 i2 Type': ensure both indices were seen as entities earlier in the sentence\nif (!entityIndices.contains(i1) || !entityIndices.contains(i2)) {\n  logger.warning(\"relation over non-entity word, skipping line: \" + line);\n}","typeGuard":null,"tryCatchPattern":"try { readSentence(...); } catch (NullPointerException e) { logger.warning(\"skipping sentence: \" + e.getMessage()); }","preventionTips":["Validate that every relation argument index maps to an entity-tagged word in the same sentence.","Regenerate relations after any change to NER annotations.","Skip-and-log bad sentences instead of failing the whole corpus read."],"tags":["java","stanford-nlp","conll04","relation-extraction"],"backgroundTag":"entity-not-found","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"}