{"record":{"id":"57ca0615306e13e0","repo":"stanfordnlp/CoreNLP","slug":"cannot-find-matching-labelled-span-for","errorCode":null,"errorMessage":"Cannot find matching labelled span for ","messagePattern":"Cannot find matching labelled span for ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/coref/docreader/CoNLLDocumentReader.java","lineNumber":426,"sourceCode":"                openParenIndex = -1;\n              }\n              isDelimiter = true;\n            }\n            if (c == '(') {\n              openParenIndex = j;\n            } else if (c == ')') {\n              Triple<Integer, Integer, String> t = openSpans.pop();\n              if (checkEndLabel) {\n                // NOTE: end parens may cross (usually because mention either start or end on the same token\n                // and it is just an artifact of the ordering\n                String s = val.substring(lastDelimiterIndex+1, j);\n                if (!s.equals(t.third())) {\n                  Stack<Triple<Integer,Integer, String>> saved = new Stack<>();\n                  while (!s.equals(t.third())) {\n                    // find correct match\n                    saved.push(t);\n                    if (openSpans.isEmpty()) {\n                      throw new RuntimeException(\"Cannot find matching labelled span for \" + s);\n                    }\n                    t = openSpans.pop();\n                  }\n                  while (!saved.isEmpty()) {\n                    openSpans.push(saved.pop());\n                  }\n                  assert(s.equals(t.third()));\n                }\n              }\n              t.setSecond(wordPos);\n              spans.add(t);\n            }\n            if (isDelimiter) {\n              lastDelimiterIndex = j;\n            }\n          }\n          if (openParenIndex >= 0) {\n            String s = val.substring(openParenIndex+1, val.length());","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/docreader/CoNLLDocumentReader.java#L408-L444","documentation":"getLabelledSpans builds spans from bracket-style CoNLL labels (e.g. coref and NER columns). While scanning a token's label set against the currently open spans, a close marker arrived whose label does not match any open span, and openSpans ran out without finding a match. This means the bracket annotations in the corpus column are unbalanced or mismatched, so the library throws a RuntimeException.","triggerScenarios":"A token carries a closing label (or an Openify/Closeify mismatch) such that popping openSpans never yields the expected label s; i.e. malformed coref or NER bracket encoding in a line of the CoNLL file.","commonSituations":"Hand-edited or truncated CoNLL files where an opening bracket was deleted; column-shifting edits (tabs/space changed) so labels are read from the wrong column; custom-preprocessed corpora that closed spans out of order.","solutions":["Validate the annotation file: every opening label like (LABEL must have a matching closing LABEL) in the same column","Regenerate the file from the original CoNLL-2012 distribution rather than hand-editing","Check that your preprocessing did not merge or reorder tokens within a sentence, breaking bracket pairing","Log the sentence and column (concatField) at failure to locate the offending line before fixing it"],"exampleFix":"// before (hand-edited line)\n token (ARG0)\n token )\n token ARG0)   <- closing without open\n// after\n token (ARG0\n token ARG0)    <- balanced brackets in the coref column","handlingStrategy":"validation","validationCode":"// Pre-check a coref/NER column for balanced brackets\nstatic boolean bracketsBalanced(String col) { int opens=0; for (String tok : col.split(\"\\\\s+\")) { for (String part : tok.split(\"(?=\\\\()|(?<=\\\\))\")) { if (part.startsWith(\"(\")) opens++; if (part.endsWith(\"))\")) opens-=2; else if (part.endsWith(\")\")) opens--; if (opens<0) return false; } } return opens==0; }","typeGuard":null,"tryCatchPattern":"try { spans = reader.getLabelledSpans(...); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Cannot find matching labelled span\")) { throw new CorruptAnnotationException(e.getMessage() + \" — fix brackets in the column\", e); } throw e; }","preventionTips":["Validate CoNLL files with the official scripts before loading","Never hand-edit bracket annotations","Keep tokens and their annotations aligned when preprocessing","Diff against original gold files after any transformation"],"tags":["java","conll","annotation-parsing","malformed-input"],"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"}