{"record":{"id":"588c1dd6e1873e31","repo":"stanfordnlp/CoreNLP","slug":"unmatched-ne-labels-in-muc-file-ner-v-ner1","errorCode":null,"errorMessage":"Unmatched NE labels in MUC file: {ner} v. {ner1}","messagePattern":"Unmatched NE labels in MUC file: (.+?) v\\. (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/dcoref/MUCMentionExtractor.java","lineNumber":177,"sourceCode":"              word.set(CoreAnnotations.NamedEntityTagAnnotation.class, \"O\");\n            }\n          }\n          sentence.add(word);\n        }\n        // found the start SGML tag for a NE, e.g., \"<ORGANIZATION>\"\n        else if (w.startsWith(\"<\") && !w.startsWith(\"<COREF\") && !w.startsWith(\"</\")) {\n          Pattern nerPattern = Pattern.compile(\"<(.*?)>\");\n          Matcher m = nerPattern.matcher(w);\n          m.find();\n          ner = m.group(1);\n        }\n        // found the end SGML tag for a NE, e.g., \"</ORGANIZATION>\"\n        else if (w.startsWith(\"</\") && !w.startsWith(\"</COREF\")) {\n          Pattern nerPattern = Pattern.compile(\"</(.*?)>\");\n          Matcher m = nerPattern.matcher(w);\n          m.find();\n          String ner1 = m.group(1);\n          if (ner != null && !ner.equals(ner1)) throw new RuntimeException(\"Unmatched NE labels in MUC file: \" + ner + \" v. \" + ner1);\n          ner = null;\n        }\n        // found the start SGML tag for a coref mention\n        else if (w.startsWith(\"<COREF\")) {\n          Mention mention = new Mention();\n          // position of this mention in the sentence\n          mention.startIndex = sentence.size();\n\n          // extract GOLD info about this coref chain. needed for eval\n          Pattern idPattern = Pattern.compile(\"ID=\\\"(.*?)\\\"\");\n          Pattern refPattern = Pattern.compile(\"REF=\\\"(.*?)\\\"\");\n\n          Matcher m = idPattern.matcher(w);\n          m.find();\n          mention.mentionID = Integer.parseInt(m.group(1));\n\n          m = refPattern.matcher(w);\n          if (m.find()) {","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/dcoref/MUCMentionExtractor.java#L159-L195","documentation":"nextDoc parses MUC-format SGML documents token by token; when it closes a named-entity tag it compares the closing label with the currently open one and throws RuntimeException(\"Unmatched NE labels in MUC file: X v. Y\") on mismatch. It means the MUC file's NE SGML tags are nested or malformed — an opening tag was left unclosed or closed with the wrong name.","triggerScenarios":"MUCMentionExtractor.nextDoc reads a MUC file where </SOMETHING> appears while a different <SOMETHING> tag is still open (e.g. <ORGANIZATION> ... </PERSON>), or the tokenizer splits tags unexpectedly.","commonSituations":"Hand-edited or machine-generated MUC files with mismatched SGML tags, incorrectly nested NE markup, HTML-ish entities confusing the simple tokenizer, or files converted from another format with broken tags.","solutions":["Fix the MUC file so every NE open tag is closed by the matching close tag with proper nesting","Re-generate the MUC file from a reliable source/converter","Check for stray/typo'd close tags (e.g. </ORGANISATION> vs </ORGANIZATION>)","Pre-validate SGML tag balance before feeding the file to the mention extractor"],"exampleFix":"// before\n<ORGANIZATION>Apple <PERSON>Tim Cook</ORGANIZATION></PERSON> <!-- bad nesting -->\n// after\n<ORGANIZATION>Apple</ORGANIZATION> <PERSON>Tim Cook</PERSON>","handlingStrategy":"validation","validationCode":"// check NE tag balance before feeding a MUC file to MUCMentionExtractor\nDeque<String> stack = new ArrayDeque<>();\nMatcher m = Pattern.compile(\"</?([A-Z]+)>\").matcher(mucFileText);\nwhile (m.find()) {\n    if (m.group(0).startsWith(\"</\")) {\n        if (stack.isEmpty() || !stack.pop().equals(m.group(1))) {\n            throw new IllegalStateException(\"Unmatched NE tag: \" + m.group(0));\n        }\n    } else {\n        stack.push(m.group(1));\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    extractor.nextDoc();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unmatched NE labels\")) {\n        log.error(\"Malformed MUC SGML: \" + e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Pre-validate SGML tag nesting in MUC files","Use a standard converter to generate MUC format","Watch for tag-name typos and case mismatches","Test one document through the extractor before batch processing"],"tags":["java","corenlp","sgml","muc-format","data-corruption"],"backgroundTag":"invalid-argument-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}