{"record":{"id":"8d52db58092ac00d","repo":"stanfordnlp/CoreNLP","slug":"could-not-find-matching-word-from-lattice-in-parse","errorCode":null,"errorMessage":"could not find matching word from lattice in parse reconstruction","messagePattern":"could not find matching word from lattice in parse reconstruction","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ExhaustivePCFGParser.java","lineNumber":1590,"sourceCode":"\n        } else if (lr != null) {\n          List<LatticeEdge> latticeEdges = lr.getEdgesOverSpan(start, end);\n          for (LatticeEdge edge : latticeEdges) {\n            IntTaggedWord itw = new IntTaggedWord(edge.word, stateIndex.get(goal), wordIndex, tagIndex);\n\n            float tagScore = (floodTags) ? -1000.0f : lex.score(itw, start, edge.word, null);\n            if (matches(bestScore, tagScore + (float) edge.weight)) {\n              wordNode = tf.newLeaf(edge.word);\n              if(wordNode.label() instanceof CoreLabel) {\n              \tCoreLabel cl = (CoreLabel) wordNode.label();\n              \tcl.setBeginPosition(start);\n              \tcl.setEndPosition(end);\n              }\n              break;\n            }\n          }\n          if (wordNode == null) {\n            throw new RuntimeException(\"could not find matching word from lattice in parse reconstruction\");\n          }\n\n        } else {\n          throw new RuntimeException(\"attempt to get word when sentence and lattice are null!\");\n        }\n        Tree tagNode = tf.newTreeNode(goalStr, Collections.singletonList(wordNode));\n        tagNode.setScore(bestScore);\n        if (originalTags[start] != null) {\n          tagNode.label().setValue(originalTags[start].tag());\n        }\n        return tagNode;\n      } else {  // normal lexicon is single words case\n        IntTaggedWord tagging = new IntTaggedWord(words[start], tagIndex.indexOf(goalStr));\n        String contextStr = getCoreLabel(start).originalText();\n        float tagScore = lex.score(tagging, start, wordIndex.get(words[start]), contextStr);\n        if (tagScore > Float.NEGATIVE_INFINITY || floodTags) {\n          // return a pre-terminal tree\n          CoreLabel terminalLabel = getCoreLabel(start);","sourceCodeStart":1572,"sourceCodeEnd":1608,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ExhaustivePCFGParser.java#L1572-L1608","documentation":"During parse reconstruction from a word lattice, ExhaustivePCFGParser searches the lattice for a node matching the word at a given position. If no lattice node matches (wordNode remains null), it throws this RuntimeException, indicating the lattice and the reconstructed parse are inconsistent.","triggerScenarios":"Calling getBestParse()/parse reconstruction on a sentence parsed with a lattice (setInput with a List<HasWord> lattice / SRILM-style lattice) where the word expected at position `start` does not exactly match any node in the lattice segment (e.g. word string, start/end positions mismatch).","commonSituations":"Using lattice input where the lattice was built with different tokenization or normalization than the tag sequence the parser emits; malformed lattice edges; mismatched word/POS naming conventions.","solutions":["Ensure the lattice words exactly match the tokens passed to the parser (same strings and tokenization).","Rebuild the lattice so every position covered by the parse has a matching word node with consistent start/end positions.","Verify lattice construction code (word values, positions) before parsing; validate with the library's lattice-reading utilities."],"exampleFix":"// before\nparserQuery.parse(latticeWords); // lattice built with different tokenizer\n// after\nList<HasWord> tokens = tokenizer.tokenize(text); // same tokenizer used to build lattice\nList<WordLattice> lat = latticeBuilder.build(tokens);\nparserQuery.setInputs(lat, tokens);","handlingStrategy":"validation","validationCode":"// before parsing with a lattice, verify coverage\nfor (int i = 0; i < tokens.size(); i++)\n  if (!latticeWordAtCovers(lat, i, tokens.get(i).word()))\n    throw new IllegalArgumentException(\"lattice missing word at pos \" + i);","typeGuard":null,"tryCatchPattern":"try { Tree t = pq.getBestParse(); } catch (RuntimeException e) { if (e.getMessage().contains(\"lattice\")) rebuildLattice(); else throw e; }","preventionTips":["Build lattices with the same tokenizer/normalizer used for parsing.","Validate lattice words and positions before calling parse.","Avoid hand-built lattices; use the library's lattice readers."],"tags":["java","nlp","parsing","lattice"],"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"}