{"record":{"id":"f8a1a38d948ef209","repo":"stanfordnlp/CoreNLP","slug":"semgrex-pattern-asked-for-uniq-of-node","errorCode":null,"errorMessage":"Semgrex pattern asked for uniq of node ","messagePattern":"Semgrex pattern asked for uniq of node ","errorType":"exception","errorClass":"SemgrexParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj","lineNumber":119,"sourceCode":"    )\n    {\n      if (children.size() > 1)\n        node = new CoordinationPattern(true, children, true, true);\n      if (deprecatedAmp) {\n        throw new SemgrexParseException(\"Use of & in semgrex patterns is now illegal.  It is equivalent to the same expression without the &.  Offending expression: \" + startToken);\n      }\n      if (deprecatedNodeConj) {\n        throw new SemgrexParseException(\"Use of node conjugation (expressions such as '< [foo bar]' or '< [foo & bar]') is now illegal.  The issue is that expressions such as '[foo bar] < zzz' may intuitively mean that foo < zzz, bar < zzz, zzz the same for both cases, but that is not the way the parser interpreted this expression.  Changing the functionality might break existing expressions, and anyway this can be rewritten in various ways such as 'zzz > foo > bar' or 'foo < zzz=a : bar < zzz=a'.  Offending expression: \" + startToken);\n      }\n    }\n  )\n  (\n    (\n      \"::\" <UNIQ> { uniqKeys = new ArrayList<>(); }  (nextIdentifier = identifier() { uniqKeys.add(nextIdentifier.image); })*\n      {\n        for (String key : uniqKeys) {\n          if (!knownVariables.contains(key)) {\n            throw new SemgrexParseException(\"Semgrex pattern asked for uniq of node \" + key + \" which does not exist in the pattern\");\n          }\n        }\n        // TODO: can error check that the keys are unique between node and edge names\n        // that might require keeping edge names in a known set\n        // TODO: edge names might need some upgrades anyway - shouldn't name them under negation, for example\n        node = new UniqPattern(node, uniqKeys);\n      }\n    )?\n  )\n  (\n    \"\\n\"\n  )\n  {\n    return node;\n  }\n\n}\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj#L101-L137","documentation":"The '::' unique operator in semgrex requires the listed keys to be node names already declared elsewhere in the pattern. If a key after '::' was never defined as a node variable, the parser throws SemgrexParseException saying the pattern asked for uniq of a node that does not exist.","triggerScenarios":"Compiling a pattern like '::x {}' or '::a,b {...}' where 'x' (or 'a'/'b') never appears as '=x' on any node in the pattern.","commonSituations":"Typos in node variable names; referring to edge names or attribute names in '::'; reordering a pattern so the '::' clause references variables defined later than expected.","solutions":["Define the node with '=key' somewhere in the pattern before/alongside using '::key'","Fix the spelling so the '::' key matches an existing node variable","Remove the non-existent key from the '::' list"],"exampleFix":"// before\nSemgrexPattern p = SemgrexPattern.compile(\"::x {} >nsubj =y\");\n// after\nSemgrexPattern p = SemgrexPattern.compile(\"::y {} >nsubj =y\");","handlingStrategy":"validation","validationCode":"Set<String> declared = new HashSet<>();\nMatcher m = Pattern.compile(\"=(\\\\w+)\").matcher(pattern.substring(pattern.indexOf(\"::\") + 2));\n// collect node vars outside '::' and check each '::key' is in the declared set before compiling","typeGuard":null,"tryCatchPattern":"try {\n  p = SemgrexPattern.compile(pattern);\n} catch (SemgrexParseException e) {\n  if (e.getMessage().startsWith(\"Semgrex pattern asked for uniq\")) { /* fix or drop the bad '::key' */ }\n  throw e;\n}","preventionTips":["Ensure every '::key' has a matching '=key' node binding in the pattern","Keep node variable names in a small, consistent naming scheme","Test patterns with SemgrexPattern.compile in unit tests before deploying"],"tags":["semgrex","parser","undefined-variable"],"backgroundTag":"undefined-variable","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}