{"record":{"id":"2bd4d0bb9c629c2c","repo":"stanfordnlp/CoreNLP","slug":"ssurgeon-rule-tried-to-set-root-to-name-but-tha","errorCode":null,"errorMessage":"Ssurgeon rule tried to set root to ${name} but that name does not exist in the semgrex results","messagePattern":"Ssurgeon rule tried to set root to (.+?) but that name does not exist in the semgrex results","errorType":"exception","errorClass":"SsurgeonRuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SetRoots.java","lineNumber":32,"sourceCode":" */\npublic class SetRoots extends SsurgeonEdit {\n  public static final String LABEL = \"setRoots\";\n  List<String> newRootNames;\n  public SetRoots(List<String> newRootNames) {\n    this.newRootNames = newRootNames;\n  }\n\n  /**\n   * If executed twice on the same graph, the second time there\n   * will be no further updates\n   */\n  @Override\n  public boolean evaluate(SemanticGraph sg, SemgrexMatcher sm) {\n    Set<IndexedWord> newRoots = new LinkedHashSet<>();\n    for (String name : newRootNames) {\n      IndexedWord root = getNamedNode(name, sm);\n      if (root == null) {\n        throw new SsurgeonRuntimeException(\"Ssurgeon rule tried to set root to \" + name + \" but that name does not exist in the semgrex results\");\n      }\n      newRoots.add(root);\n    }\n    if (newRoots.equals(sg.getRoots()))\n      return false;\n    sg.setRoots(newRoots);\n    return true;\n  }\n\n  @Override\n  public String toEditString() {\n    StringWriter buf = new StringWriter();\n    buf.write(LABEL);\n    for (String name : newRootNames) {\n      buf.write(\"\\t\");\n      buf.write(name);\n    }\n    return buf.toString();","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SetRoots.java#L14-L50","documentation":"SetRoots.evaluate() resolves each name in newRootNames to a node via getNamedNode(name, sm), which returns the IndexedWord matched by a named semgrex node. If a name has no match, the rule cannot set roots and throws SsurgeonRuntimeException naming the missing node.","triggerScenarios":"An ssurgeon SetRoots operation referencing a -node name (e.g. -root newroot) that the accompanying semgrex pattern never assigns, either because the name is misspelled or because the semgrex match did not capture that node.","commonSituations":"Typo between the semgrex pattern's named node and the SetRoots -root argument; editing a pattern so the named node no longer exists; reusing a hand-written ssurgeon rule file against a changed semgrex expression.","solutions":["Verify the name in the SetRoots operation exactly matches a named node in the semgrex pattern (e.g. node=subject/{pos:NNP})","Check the semgrex pattern actually matches and assigns every name referenced by SetRoots before evaluate runs","Null-check the SemgrexMatcher result in custom pipelines, or wrap evaluate in try-catch for SsurgeonRuntimeException and log the rule name","Regenerate the ssurgeon rule from the current semgrex pattern if the pattern was recently edited"],"exampleFix":"// before: pattern names nothing, rule references 'newroot'\nSsurgeon.setRoots(\"newroot\"); pattern = \"{word:dog}\";\n// after: name the node in the pattern\npattern = \"{word:dog}=newroot\"; Ssurgeon.setRoots(\"newroot\");","handlingStrategy":"validation","validationCode":"// verify all names referenced by SetRoots are present in the pattern string\nfor (String name : newRootNames) {\n  if (!patternString.contains(\"=\" + name)) throw new IllegalArgumentException(\"pattern does not name node: \" + name);\n}","typeGuard":null,"tryCatchPattern":"try { op.evaluate(sg, sm); } catch (SsurgeonRuntimeException e) { if (e.getMessage().contains(\"does not exist in the semgrex results\")) { log.error(\"Fix semgrex pattern to name node: \" + e.getMessage()); } else { throw e; } }","preventionTips":["Keep the semgrex named nodes and ssurgeon operation arguments in one place/generated together","Test the semgrex pattern matches and exposes every named node before wiring ssurgeon ops","Re-check rule files after editing semgrex patterns"],"tags":["ssurgeon","semgrex","named-node"],"backgroundTag":"resource-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}