stanfordnlp/CoreNLP · error · ParseException

Unrecognized simple relation

Error message

Unrecognized simple relation 

What it means

Relation.getRelation() maps a simple tregex relation symbol (like <, >, <#, etc.) to a Relation object; an unknown symbol reaches the default branch and throws ParseException. It means a tregex query string contains a relation the parser does not recognize.

Solutions

  1. Correct the relation symbol in the tregex query to a documented simple relation (e.g. <, >, <<, >>, <#, $++, ...)
  2. Check the Relation class docs for the exact symbol list in your CoreNLP version
  3. Upgrade CoreNLP if the query uses a relation introduced after your current version
  4. Verify quoting/escaping did not mangle the symbol before it reaches getRelation

Example fix

// before
String rel = "<>"; // unknown
Relation r = Relation.getRelation(rel, "NP", null, headFinder);
// after
String rel = "<<"; // documented relation
Relation r = Relation.getRelation(rel, "NP", null, headFinder);
Defensive patterns

Strategy: try-catch

Validate before calling

Set<String> simpleRels = Set.of("<", ">", "<<", ">>", "<<,", ">>,", "<#",">#", "$+", "$-", "$++", "$--", ".", ",", "..", ",:", ":", "<:", ">:");
if (!simpleRels.contains(rel)) throw new IllegalArgumentException("Unknown simple relation: " + rel);

Try / catch

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

Prevention

When it happens

Trigger: A tregex expression contains a misspelled or unsupported simple relation symbol, passed via getRelation(String s, ...) during query parsing.

Common situations: Typos in tregex queries (e.g. '<> ' instead of '<<'); using relation syntax from other tree-query tools; using a relation added in a newer CoreNLP version than the one on the classpath.

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/e0fcce3e60f08934. Report an issue: GitHub.

Appendix: source

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

    }

    // finally try relations with headFinders
    Relation r;
    switch (s) {
      case ">>#":
        r = new Heads(headFinder);
        break;
      case "<<#":
        r = new HeadedBy(headFinder);
        break;
      case ">#":
        r = new ImmediatelyHeads(headFinder);
        break;
      case "<#":
        r = new ImmediatelyHeadedBy(headFinder);
        break;
      default:
        throw new ParseException("Unrecognized simple relation " + s);
    }

    return Interner.globalIntern(r);
  }

  /**
   * Static factory method for relations requiring an argument, including
   * HAS_ITH_CHILD, ITH_CHILD_OF, UNBROKEN_CATEGORY_DOMINATES,
   * UNBROKEN_CATEGORY_DOMINATED_BY, ANCESTOR_OF_ITH_LEAF.
   *
   * @param s The String representation of the relation
   * @param arg The argument to the relation, as a string; could be a node
   *          description or an integer
   * @return The singleton static relation of the specified type with the
   *         specified argument. Uses Interner to insure singleton-ity
   * @throws ParseException If bad relation s
   */
  static Relation getRelation(String s, String arg,

View on GitHub (pinned to 1b7edd19c4)