stanfordnlp/CoreNLP · error · SsurgeonParseException

SplitWord expected at least two -exact or -regex

Error message

SplitWord expected at least two -exact or -regex

What it means

Splitting a word must produce at least two pieces — otherwise the operation is a no-op and ambiguous. If nodePieces has exactly one element, the SplitWord constructor throws SsurgeonParseException telling the user to supply at least two -exact or -regex values.

Solutions

  1. Supply at least two pieces: e.g. -exact micro -exact soft, or a -regex with two or more capture groups
  2. If you truly need no split, remove the SplitWord operation from the rule rather than passing one piece
  3. Count the capture groups in your -regex; each group becomes a piece, so use a group count >= 2

Example fix

// before
new SplitWord("w", List.of("soft"), 0, reln, null, true);
// after
new SplitWord("w", List.of("micro", "soft"), 0, reln, null, true);
Defensive patterns

Strategy: validation

Validate before calling

if (nodePieces != null && nodePieces.size() < 2) throw new IllegalArgumentException("SplitWord needs at least two pieces; remove the operation if no split is wanted");

Try / catch

try { SplitWord sw = new SplitWord(node, pieces, headIndex, reln, names, exact); } catch (SsurgeonParseException e) { log.error("Need >= 2 -exact/-regex: " + e.getMessage()); }

Prevention

When it happens

Trigger: Calling new SplitWord(...) with a single-element nodePieces list, or specifying exactly one -exact/-regex flag on the ssurgeon command.

Common situations: Testing a split with a single piece to see what happens; an XML rule where the second -exact line was accidentally deleted; a regex with no capture groups producing one effective piece.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SplitWord.java:58

  final String node;
  final List<Pattern> nodeRegex;
  final List<String> exactPieces;
  final int headIndex;
  final GrammaticalRelation relation;
  final Map<Integer, String> nodeNames;

  public SplitWord(String node, List<String> nodePieces, Integer headIndex, GrammaticalRelation relation, String nodeNames, boolean exactSplit) {
    if (node == null) {
      throw new SsurgeonParseException("SplitWord expected -node with the name of the matched node to split");
    }
    this.node = node;

    if (nodePieces == null || nodePieces.size() == 0) {
      throw new SsurgeonParseException("SplitWord expected -exact or -regex with regex to determine which pieces to split the word into");
    }
    if (nodePieces.size() == 1) {
      throw new SsurgeonParseException("SplitWord expected at least two -exact or -regex");
    }
    if (exactSplit) {
      this.exactPieces = new ArrayList<>(nodePieces);
      this.nodeRegex = null;
    } else {
      this.nodeRegex = new ArrayList<>();
      for (int i = 0; i < nodePieces.size(); ++i) {
        this.nodeRegex.add(Pattern.compile(nodePieces.get(i)));
      }
      this.exactPieces = null;
    }

    if (headIndex == null) {
      throw new SsurgeonParseException("SplitWord expected a -headIndex, 0-indexed for the word piece to use when chopping up the word");
    }
    this.headIndex = headIndex;

    if (relation == null) {

View on GitHub (pinned to 1b7edd19c4)