stanfordnlp/CoreNLP · error · SemgrexParseException

Semgrex pattern asked for uniq of node which does not…

Error message

Semgrex pattern asked for uniq of node  which does not exist in the pattern

What it means

SemgrexParser validates the 'uniq' feature against the set of variables named elsewhere in the pattern. If a uniq key does not correspond to any named node in the pattern, Root() throws this SemgrexParseException because uniq can only reference nodes the pattern actually matched and named.

Solutions

  1. Add the missing node name to the pattern with '=' (e.g. '=missingNode') so uniq has a valid target.
  2. Correct the uniq key spelling to exactly match an existing named node in the pattern.
  3. Remove the stale uniq entry if the node no longer exists in the pattern.
  4. Note the related TODO in the source: keys must also be unique between node and edge names — avoid reusing identifiers across both.

Example fix

// before
SemgrexPattern.compile("{} > (nsubj) {} : uniq(ghost)");
// after
SemgrexPattern.compile("{}=src > (nsubj) {} : uniq(src)");
Defensive patterns

Strategy: validation

Validate before calling

Set<String> names = new HashSet<>();
Matcher m = Pattern.compile("=([A-Za-z_][\\w-]*)").matcher(semgrex);
while (m.find()) names.add(m.group(1));
Matcher u = Pattern.compile("uniq\\(([^)]+)\\)").matcher(semgrex);
while (u.find()) if (!names.contains(u.group(1).trim())) throw new IllegalArgumentException("uniq key not in pattern: " + u.group(1));

Try / catch

try { SemgrexPattern.compile(semgrex); } catch (SemgrexParseException e) { throw new IllegalArgumentException("uniq references unknown node: " + semgrex, e); }

Prevention

When it happens

Trigger: Compiling a pattern with a uniq(...) clause listing an identifier that never appears as a named node in the pattern, e.g. 'UniqPattern' keys not present in knownVariables — such as '{}' > uniq(missingNode) where no node was named 'missingNode'.

Common situations: Typos in uniq key names after renaming nodes; refactoring a pattern and deleting a named node but leaving its uniq entry; hand-writing uniq keys without naming nodes with '='; patterns generated programmatically with stale key lists.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.java:125

uniqKeys = new ArrayList<>();
      label_2:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
        case UNIQ:
        case IDENTIFIER:{
          ;
          break;
          }
        default:
          jj_la1[2] = jj_gen;
          break label_2;
        }
        nextIdentifier = identifier();
uniqKeys.add(nextIdentifier.image);
      }
for (String key : uniqKeys) {
          if (!knownVariables.contains(key)) {
            {if (true) throw new SemgrexParseException("Semgrex pattern asked for uniq of node " + key + " which does not exist in the pattern");}
          }
        }
        // TODO: can error check that the keys are unique between node and edge names
        // that might require keeping edge names in a known set
        // TODO: edge names might need some upgrades anyway - shouldn't name them under negation, for example
        node = new UniqPattern(node, uniqKeys);
      break;
      }
    default:
      jj_la1[3] = jj_gen;
      ;
    }
    jj_consume_token(12);
{if ("" != null) return node;}
    throw new Error("Missing return statement in function");
}

  final public SemgrexPattern SubNode(GraphRelation r) throws ParseException {SemgrexPattern result =  null;

View on GitHub (pinned to 1b7edd19c4)