languagetool-org/languagetool · error · UnsupportedPatternRuleException

Neither POS tag nor term set for element: + patternToken

Error message

Neither POS tag nor term set for element: + patternToken

What it means

Search-index guard in makeQuery: the pattern element has neither a POS tag nor a literal term, so no index query can be built for it. Reached via the relaxed build path when all tokens are unusable.

Source

Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/index/PatternRuleQueryBuilder.java:118

    if (termQuery != null && posQuery != null) {
      // if both term and POS are set, we create a query where both are at the same position
      if (mustOccur(termQuery) && mustOccur(posQuery)) {
        SpanQuery spanQueryForTerm = asSpanQuery(termQuery);
        SpanQuery spanQueryForPos = asSpanQuery(posQuery);
        SpanQuery[] spanClauses = {spanQueryForTerm, spanQueryForPos};
        return new BooleanClause(new SpanNearQuery(spanClauses, 0, false), BooleanClause.Occur.MUST);
      } else {
        // should not happen, we always use Occur.MUST:
        throw new UnsupportedPatternRuleException("Term/POS combination not supported yet: " + patternToken);
      }
    
    } else if (termQuery != null) {
      return termQuery;

    } else if (posQuery != null) {
      return posQuery;
    }
    throw new UnsupportedPatternRuleException("Neither POS tag nor term set for element: " + patternToken);
  }

  private SpanQuery asSpanQuery(BooleanClause query) {
    if (query.getQuery() instanceof MultiTermQuery) {
      return new SpanMultiTermQueryWrapper<>((MultiTermQuery) query.getQuery());
    } else {
      Set<Term> terms = new HashSet<>();
      try {
        indexSearcher.createWeight(query.getQuery(), false).extractTerms(terms);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      if (terms.size() != 1) {
        throw new RuntimeException("Expected term set of size 1: " + terms);
      }
      return new SpanTermQuery(terms.iterator().next());
    }
  }

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Set a term or POS tag on that pattern element
  2. Remove the empty element from the rule
  3. Skip the rule when building index queries
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/index/PatternRuleQueryBuilder.java:118 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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