languagetool-org/languagetool · error · RuntimeException

Could not tag and disambiguate '<token>'

Error message

Could not tag and disambiguate '<token>'

What it means

NoDisambiguationRussianPartialPosTagFilter.tag() calls the Russian base-form tagger (BaseTagger.tag) on a single token; if the tagger throws IOException (dictionary/resource read failure), the method wraps it in a RuntimeException with this message. The filter cannot produce part-of-speech readings for the token, so rule evaluation fails for that match.

Source

Thrown at languagetool-language-modules/ru/src/main/java/org/languagetool/rules/ru/NoDisambiguationRussianPartialPosTagFilter.java:45

import java.util.*;

/**
 * A {@link PartialPosTagFilter} for Russian that does not run the disambiguator.
 * @since 5.1
 * @see RussianPartialPosTagFilter
 */
public class NoDisambiguationRussianPartialPosTagFilter extends PartialPosTagFilter {

  private final Tagger tagger = Languages.getLanguageForShortCode("ru").getTagger();

  @Override
  protected List<AnalyzedTokenReadings> tag(String token) {
    try {
      List<AnalyzedTokenReadings> tags = tagger.tag(Collections.singletonList(token));
      AnalyzedTokenReadings[] atr = tags.toArray(new AnalyzedTokenReadings[tags.size()]);
      return Arrays.asList(atr);
    } catch (IOException e) {
      throw new RuntimeException("Could not tag and disambiguate '" + token + "'", e);
    }
  }
}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Verify the Russian tagger dictionary resources exist in the ru module jar / distribution (check languagetool-language-modules/ru/src/main/resources) and rebuild with 'mvn package' if missing
  2. Check the wrapped IOException (the cause in the stack trace) for the exact missing resource path and restore it to the classpath
  3. Reinstall or re-extract the full LanguageTool distribution; ensure no jars were excluded and files are readable by the runtime user
  4. If you maintain a fork, pre-validate dictionary availability at startup instead of failing per-token inside tag()

Example fix

// before
} catch (IOException e) {
  throw new RuntimeException("Could not tag and disambiguate '" + token + "'", e);
}
// after
} catch (IOException e) {
  LOGGER.error("Tagger resource lookup failed for token '{}': {}", token, e.getMessage(), e);
  return Collections.singletonList(new AnalyzedTokenReadings(token, 0));
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before rule evaluation, verify the ru tagger dictionary is loadable
URL dict = getClass().getResource("/ru/russian.dict");
if (dict == null) {
  throw new IllegalStateException("Russian tagger dictionary missing from classpath — rebuild/extract the full distribution");
}

Type guard

boolean taggerResourcesAvailable() {
  try (InputStream in = getClass().getResourceAsStream("/ru/russian.dict")) {
    return in != null;
  } catch (IOException e) {
    return false;
  }
}

Try / catch

try {
  analyzed = posFilter.tag(token);
} catch (RuntimeException e) {
  Throwable cause = e.getCause();
  if (cause instanceof IOException) {
    log.error("Tagger dictionary unreadable ({}): check ru module resources/classpath", cause.getMessage());
    return new AnalyzedTokenReadings(token, 0); // untagged reading, skip POS rules
  }
  throw e;
}

Prevention

When it happens

Trigger: An IOException from tagger.tag() — typically the Russian POS dictionary/lookup resource (e.g. the hunspell/dict files under languagetool-language-modules/ru resources) missing or unreadable at runtime; also occurs when running LanguageTool from a build whose ru module resources were not packaged, or an underlying stream error while loading tagger data lazily on first use.

Common situations: Running a partial/custom build that omitted the ru tagger dictionaries; deploying only some jars so resource files are not on the classpath; file-permission or corrupt-jar issues in an extracted distribution; first token tagged triggers lazy dictionary load which fails.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/6d893d5aee6438bb. Report an issue: GitHub.