{"record":{"id":"efd850f5fef910ae","repo":"languagetool-org/languagetool","slug":"not-found-in-set","errorCode":null,"errorMessage":"Not found in set '","messagePattern":"Not found in set '","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/rules/ngrams/ConfusionProbabilityRule.java","lineNumber":318,"sourceCode":"    return getBetterAlternativeOrNull(token, tokens, other, factor);\n  }\n\n  private ConfusionString getAlternativeTerm(List<ConfusionString> confusionSet, GoogleToken token) {\n    for (ConfusionString s : confusionSet) {\n      if (!s.getString().equals(token.token)) {\n        return s;\n      }\n    }\n    throw new RuntimeException(\"No alternative found for: \" + token);\n  }\n\n  private ConfusionString getConfusionString(List<ConfusionString> confusionSet, GoogleToken token) {\n    for (ConfusionString s : confusionSet) {\n      if (s.getString().equalsIgnoreCase(token.token)) {\n        return s;\n      }\n    }\n    throw new RuntimeException(\"Not found in set '\" + confusionSet + \"': \" + token);\n  }\n\n  private ConfusionString getBetterAlternativeOrNull(GoogleToken token, List<GoogleToken> tokens, ConfusionString otherWord, long factor) {\n    String word = token.token;\n    double p1;\n    double p2;\n    if (grams == 3) {\n      p1 = LanguageModelUtils.get3gramProbabilityFor(language, lm, token, tokens, word);\n      p2 = LanguageModelUtils.get3gramProbabilityFor(language, lm, token, tokens, otherWord.getString());\n    } else if (grams == 4) {\n      p1 = LanguageModelUtils.get4gramProbabilityFor(language, lm, token, tokens, word);\n      p2 = LanguageModelUtils.get4gramProbabilityFor(language, lm, token, tokens, otherWord.getString());\n    } else {\n      throw new RuntimeException(\"Only 3grams and 4grams are supported\");\n    }\n    debug(\"%.90f <- P(\" + word + \") \\n\", p1);\n    debug(\"%.90f <- P(\" + otherWord + \")\\n\", p2);\n    return p2 >= MIN_PROB && p2 > p1 * factor ? otherWord : null;","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/rules/ngrams/ConfusionProbabilityRule.java#L300-L336","documentation":"getConfusionString looks up the confusion-set entry that case-insensitively equals the token from the text. This RuntimeException is thrown when no entry matches, meaning the token extracted from text is not present in its expected confusion set.","triggerScenarios":"stringFromText extracts a token (often uppercase or differently inflected) that does not case-insensitively equal any confusion-set entry, then getConfusionString fails.","commonSituations":"Case conversion differences (e.g. sentence-initial capitalization combined with all-uppercase tokens); language data updates removing a word still matched by the rule pattern.","solutions":["Inspect the token and set in the message; verify the token's exact casing/content.","Check the confusion data for the missing word and re-add it if removed.","Adjust token normalization before lookup if case/locale transformations change the token."],"exampleFix":"// before (data updated but word removed)\n// confusion set: {there} while text token is 'their'\n// after\n// re-add to confusion data:\ntheir","handlingStrategy":"try-catch","validationCode":"// pre-check that the token appears in the confusion set before matching\nboolean present = set.stream().anyMatch(s -> s.getString().equalsIgnoreCase(token));\nif (!present) log.warn(\"Token not in confusion set: \" + token);","typeGuard":null,"tryCatchPattern":"try { rule.match(...); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Not found in set\")) { log.error(\"Token missing from confusion data: \" + e.getMessage()); } throw e; }","preventionTips":["Keep rule patterns and confusion data in sync","Re-add removed words when data files change","Test rules against sample text covering case variants"],"tags":["java","ngrams","lookup-failure","languagetool"],"backgroundTag":"record-not-found","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}