stanfordnlp/CoreNLP · error · IllegalArgumentException

Relative word pattern not defined for

Error message

Relative word pattern not defined for 

What it means

ProcessUniversalEnhancerRequest.getRelativePronouns maps a request language to a relative-pronoun regex pattern; for languages with no defined mapping (any case other than English/Arabic/etc. and the Chinese variants that return null deliberately) it throws IllegalArgumentException("Relative word pattern not defined for <language>").

Solutions

  1. Use a supported language (e.g. English) in the ProcessUniversalEnhancerRequest
  2. Add a RELATIVIZING_WORD_PATTERN case for the language before using it with the enhancer
  3. Check Language enum vs. request configuration consistency after a library upgrade
  4. Pre-validate the language and skip enhancement for unsupported languages

Example fix

// before
request.setLanguage(Language.Germanic); // no pattern defined
enhancer.process(request);
// after
if (request.getLanguage() == Language.English) {
  enhancer.process(request);
}
Defensive patterns

Strategy: validation

Validate before calling

Set<Language> supported = Set.of(Language.English, Language.Arabic, Language.UniversalEnglish);
if (!supported.contains(request.getLanguage())) {
  throw new IllegalArgumentException("No relative pronoun pattern for " + request.getLanguage());
}

Try / catch

try { enhancer.process(request); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Relative word pattern not defined")) { skipEnhancement(request); } else throw e; }

Prevention

When it happens

Trigger: Calling relativePronounsPattern/getRelativePronouns with a request whose language enum/setting is a language the enhancer has no RELATIVIZING_WORD_PATTERN for.

Common situations: Configuring the UD enhancer for an unsupported language; a new Language enum value added by an upgrade without a pattern entry; passing default/unset language to the enhancer request.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/d3e6706da27921f3. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/trees/ud/ProcessUniversalEnhancerRequest.java:84

  /**
   * Figure out a relative patterns pronoun to use based on the information given in the request
   */
  public static Pattern getRelativePronouns(CoreNLPProtos.DependencyEnhancerRequest request) {
    if (request.hasRelativePronouns()) {
      return Pattern.compile(request.getRelativePronouns());
    }
    if (request.hasLanguage()) {
      switch(request.getLanguage()) {
      case English:
      case UniversalEnglish:
        return EnglishPatterns.RELATIVIZING_WORD_PATTERN;
      case Chinese:
      case UniversalChinese:
        // there are no relative pronouns in Chinese!
        return null;
      default:
        throw new IllegalArgumentException("Relative word pattern not defined for " + request.getLanguage());
      }
    }
    throw new IllegalArgumentException("Could not find Language or predefined relative pronouns pattern in the request");
  }

  /**
   * Process a single request, adding enhanced dependencies to each sentence in the document
   */
  @Override
  public void processInputStream(InputStream in, OutputStream out) throws IOException {
    CoreNLPProtos.DependencyEnhancerRequest request = CoreNLPProtos.DependencyEnhancerRequest.parseFrom(in);

    Pattern relativePronounsPattern = getRelativePronouns(request);

    CoreNLPProtos.Document response = processRequest(relativePronounsPattern, request);
    response.writeTo(out);
  }

View on GitHub (pinned to 1b7edd19c4)