stanfordnlp/CoreNLP · error · SsurgeonParseException

No ID attribute for element = " + elt

Error message

No ID attribute for element = " + elt

What it means

Ssurgeon.parseTest reads an XML element defining a WordlistTest predicate and requires an 'id' attribute naming the test. When the element has a match name but no id attribute, it throws SsurgeonParseException so the malformed Ssurgeon rule file fails fast at load time.

Solutions

  1. Add the required id="..." attribute to the offending element in the Ssurgeon XML file
  2. Validate the XML against the Ssurgeon schema / check element attributes before loading
  3. Run Ssurgeon.init on the file and fix each reported element until the file parses

Example fix

// before
<wordlist-test type="tag" match-name="NN" resource="mylist.txt"/>
// after
<wordlist-test id="nounTest" type="tag" match-name="NN" resource="mylist.txt"/>
Defensive patterns

Strategy: validation

Validate before calling

for (Element e : ruleEl.getChildren()) {
  if (isTestElement(e) && e.getAttributeValue("id") == null) {
    throw new IllegalArgumentException("Missing id on element: " + e.getName());
  }
}

Type guard

static boolean hasId(Element e) { return e.getAttributeValue("id") != null; }

Try / catch

try {
  Ssurgeon.init(resource);
} catch (SsurgeonParseException e) {
  log.error("Bad Ssurgeon rule XML: " + e.getMessage());
}

Prevention

When it happens

Trigger: Parsing a Ssurgeon .xml rules file where a <wordlist-test>-style element (or similar test node) has a resolvable match name but is missing the required id="..." attribute.

Common situations: Hand-editing or copying rule XML and dropping the id attribute; generating rules programmatically and omitting id; older rule files written for a schema where id was optional.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java:949

      case SsurgeonPattern.PREDICATE_OR_TAG:
        SsurgOrPred orPred = new SsurgOrPred();
        for (Element childElt : getChildElements(elt)) {
          SsurgPred childPred = assemblePredFromXML(childElt);
          orPred.add(childPred);
          return orPred;
        }
        break;
      case SsurgeonPattern.PRED_WORDLIST_TEST_TAG:
        String id = elt.getAttribute(SsurgeonPattern.PRED_ID_ATTR);
        String resourceID = elt.getAttribute("resourceID");
        String typeStr = elt.getAttribute("type");
        String matchName = getEltText(elt).trim(); // node name to match on

        if (matchName == null) {
          throw new SsurgeonParseException("Could not find match name for " + elt);
        }
        if (id == null) {
          throw new SsurgeonParseException("No ID attribute for element = " + elt);
        }
        return new WordlistTest(id, resourceID, typeStr, matchName);
    }

    // Not a valid node, error out!
    throw new SsurgeonParseException("Invalid node encountered during Ssurgeon predicate processing, node name="+eltName);
  }



  /**
   * Reads in the test file and prints readable to string (for debugging).
   * Input file consists of semantic graphs, in compact form.
   */
  public void testRead(File tgtDirPath) throws Exception {
    List<SsurgeonPattern> patterns = readFromDirectory(tgtDirPath);

    System.out.println("Patterns, num = "+patterns.size());

View on GitHub (pinned to 1b7edd19c4)