stanfordnlp/CoreNLP · error · ParseException

Unrecognized compound relation

Error message

Unrecognized compound relation ${s} ${arg}

What it means

Relation.getRelation() also handles compound relations that take an argument (e.g. <<#, <<:, <<<); an unrecognized compound symbol combined with its argument falls to the default branch and throws ParseException naming both the symbol and the argument. It indicates an invalid compound relation in a tregex query.

Solutions

  1. Fix the compound relation symbol to a supported one (e.g. <<:, <<#, <<<, <<,), keeping its argument intact
  2. Validate the argument (e.g. integer index for <<<) along with the symbol
  3. Consult the Relation switch cases for the exact supported symbols in your version
  4. Upgrade CoreNLP if the query syntax comes from a newer release

Example fix

// before
Relation r = Relation.getRelation("<<<x", "3", basicCatFunction, headFinder); // throws
// after
Relation r = Relation.getRelation("<<<", "3", basicCatFunction, headFinder);
Defensive patterns

Strategy: try-catch

Validate before calling

Set<String> compoundRels = Set.of("<<#", "<<,", ">>#", ">>,", "<<:", ">>:", "<<<", "<<:");
if (!compoundRels.contains(s)) throw new IllegalArgumentException("Unknown compound relation: " + s);

Try / catch

try {
  Relation r = Relation.getRelation(s, arg, basicCatFunction, headFinder);
} catch (ParseException e) {
  throw new TregexQueryException("Invalid compound relation '" + s + "' with arg '" + arg + "'", e);
}

Prevention

When it happens

Trigger: A tregex query contains a compound relation symbol not in the supported set, e.g. getRelation("<<x", "NP", basicCatFunction, headFinder) with a typo or version-mismatched operator.

Common situations: Typos such as '<<<' vs '<<' variants; copying queries from tregex tutorials for other languages/tools; running queries written for newer CoreNLP releases.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/trees/tregex/Relation.java:166

        r = new IthChildOf(Integer.parseInt(arg));
        break;
      case "<+":
        r = new UnbrokenCategoryDominates(arg, basicCatFunction);
        break;
      case ">+":
        r = new UnbrokenCategoryIsDominatedBy(arg, basicCatFunction);
        break;
      case ".+":
        r = new UnbrokenCategoryPrecedes(arg, basicCatFunction);
        break;
      case ",+":
        r = new UnbrokenCategoryFollows(arg, basicCatFunction);
        break;
      case "<<<":
        r = new AncestorOfIthLeaf(Integer.parseInt(arg));
        break;
      default:
        throw new ParseException("Unrecognized compound relation " + s + ' '
            + arg);
    }
    return Interner.globalIntern(r);
  }

  /**
   * Produce a TregexPattern which represents the given MULTI_RELATION
   * and its children
   */
  static TregexPattern constructMultiRelation(String s, List<DescriptionPattern> children,
                                              Function<String, String> basicCatFunction,
                                              HeadFinder headFinder) throws ParseException {
    if (s.equals("<...")) {
      List<TregexPattern> newChildren = Generics.newArrayList();
      for (int i = 0; i < children.size(); ++i) {
        Relation rel = getRelation("<", Integer.toString(i + 1), basicCatFunction, headFinder); 
        DescriptionPattern oldChild = children.get(i);
        TregexPattern newChild = new DescriptionPattern(rel, oldChild);

View on GitHub (pinned to 1b7edd19c4)