{"record":{"id":"4e3524dce4bcd4dd","repo":"stanfordnlp/CoreNLP","slug":"mismatch-between-number-of-morpho-analyses-and-num","errorCode":null,"errorMessage":"Mismatch between number of morpho analyses and number of input lines.","messagePattern":"Mismatch between number of morpho analyses and number of input lines\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/international/morph/AddMorphoAnnotations.java","lineNumber":172,"sourceCode":"      log.info(usage());\n      System.exit(-1);\n    }\n    \n    YieldIterator morphIter = new YieldIterator(parsedArgs[0], isMorphTreeFile);\n    YieldIterator lemmaIter = new YieldIterator(parsedArgs[1], false);\n    \n    final Pattern pParenStripper = Pattern.compile(\"[\\\\(\\\\)]\");\n        \n    try {\n      BufferedReader brIn = new BufferedReader(new InputStreamReader(System.in, encoding));\n      TreeReaderFactory trf = new ArabicTreeReaderFactory.ArabicRawTreeReaderFactory(true);\n\n      int nTrees = 0;\n      for(String line; (line = brIn.readLine()) != null; ++nTrees) {\n        Tree tree = trf.newTreeReader(new StringReader(line)).readTree();\n        List<Tree> leaves = tree.getLeaves();\n        if(!morphIter.hasNext()) {\n          throw new RuntimeException(\"Mismatch between number of morpho analyses and number of input lines.\");\n        }\n        List<String> morphTags = morphIter.next();\n        if (!lemmaIter.hasNext()) {\n          throw new RuntimeException(\"Mismatch between number of lemmas and number of input lines.\");\n        }\n        List<String> lemmas = lemmaIter.next();\n         \n        // Sanity checks\n        assert morphTags.size() == lemmas.size();\n        assert lemmas.size() == leaves.size();\n        \n        for(int i = 0; i < leaves.size(); ++i) {\n          String morphTag = morphTags.get(i);\n          if (pParenStripper.matcher(morphTag).find()) {\n            morphTag = pParenStripper.matcher(morphTag).replaceAll(\"\");\n          }\n          String newLeaf = String.format(\"%s%s%s%s%s\", leaves.get(i).value(),\n              MorphoFeatureSpecification.MORPHO_MARK,","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/international/morph/AddMorphoAnnotations.java#L154-L190","documentation":"AddMorphoAnnotations main loop reads trees one per line and consumes morphological analyses from a parallel iterator; it throws this RuntimeException when trees remain but the morpho iterator is exhausted, i.e. there are more input trees than morpho analyses.","triggerScenarios":"Running AddMorphoAnnotations where the morpho analyses file has fewer entries than the tree file has lines; loop iteration reaches a tree with !morphIter.hasNext().","commonSituations":"Truncated morpho file, mismatched line counts between tree and morpho inputs, blank lines filtered from one file but not the other.","solutions":["Recount lines in both input files and ensure the morpho file has one entry per tree line","Regenerate the morpho analyses file against the same tree input","Skip/check for blank lines that desynchronize the two files","Exit early with a clear message if counts differ before processing"],"exampleFix":"// before\nwc -l trees.txt  # 1000\nwc -l morpho.txt # 998\n// after\nwc -l morpho.txt # 1000 (regenerate to match)","handlingStrategy":"validation","validationCode":"if (nTreeLines != nMorphoLines) throw new IllegalStateException(\"trees=\" + nTreeLines + \" morpho=\" + nMorphoLines);","typeGuard":null,"tryCatchPattern":"try { process(); } catch (RuntimeException e) { log.error(\"Input length mismatch: \" + e.getMessage()); System.exit(2); }","preventionTips":["Run `wc -l` on all parallel input files before processing","Generate lemma/morpho files from the same treebank version","Filter blank lines uniformly across all files"],"tags":["corpus","annotation","data-mismatch"],"backgroundTag":"empty-result-set","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"}