stanfordnlp/CoreNLP · error · SsurgeonParseException
Cannot manually change the sentence index. If you need an…
Error message
Cannot manually change the sentence index. If you need an operation to change an entire sentence's sentIndex, please file an issue on github.
What it means
checkIllegalAttributes also rejects the "sentIndex" attribute: the sentence index a node belongs to is maintained by the surrounding sentence structures, and changing it per-node would desynchronize the SemanticGraph from its sentence. Setting it manually throws SsurgeonParseException; changing a whole sentence's index requires a dedicated (not-yet-provided) operation.
Solutions
- Delete the "sentIndex" entry from the attributes map.
- Whitelist only node-content attributes (word, lemma, tag, feats, etc.).
- If whole-sentence reordering is needed, do it outside Ssurgeon by manipulating the CoreDocument/List<CoreMap> before running Ssurgeon.
Example fix
// before
attrs.put("sentIndex", "2");
attrs.put("word", "cat");
// after
attrs.put("word", "cat"); // sentIndex is managed by the graph Defensive patterns
Strategy: validation
Validate before calling
// Java
if (attributes.containsKey("sentIndex")) {
throw new IllegalArgumentException("sentIndex cannot be set per-node; change it at the sentence level");
} Try / catch
// Java
try {
AddDep.checkIllegalAttributes(attrs);
} catch (SsurgeonParseException e) {
log.warning("Attribute map rejected: " + e.getMessage());
} Prevention
- Treat sentIndex as sentence-level metadata, never a node attribute.
- Filter attribute maps to a fixed whitelist before passing them to Ssurgeon operations.
When it happens
Trigger: An AddDep/Ssurgeon edit whose attributes map contains the key "sentIndex"; thrown during rule construction from the AddDep constructor via checkIllegalAttributes.
Common situations: Copy-pasting all keys of a CoreLabel (including sentIndex) into an Ssurgeon attribute map; trying to move a node to another sentence inside one Ssurgeon rule; confusing sentIndex with the editable sentid/docid-style metadata in other tools.
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
- Cannot manually set the index attribute. If you need a…
- Unknown position in AddDep operation
- Cannot manually change a document ID. If you need an…
- Unable to process node attribute keys for Ssurgeon operation
- Subtree cannot contain cycle leading back to root node!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/104bbdfce941a569.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java:159
// the payoff for tempIndex == maxIndex + 2:
// everything will be moved one higher, unless it's the new node
SsurgeonUtils.moveNodes(sg, sm, x -> (x >= newIndex && x != tempIndex), x -> x+1, true);
SsurgeonUtils.moveNode(sg, sm, newNode, newIndex);
}
return true;
}
/**
* Certain attributes cannot be edited, especially docid, sentid, idx,
* or they mess up the hashmaps in the SemanticGraph
*/
public static void checkIllegalAttributes(Map<String, String> attributes) {
if (attributes.containsKey("idx")) {
throw new SsurgeonParseException("Cannot manually set the index attribute. If you need a moveWord operation, please file an issue on github.");
}
if (attributes.containsKey("sentIndex")) {
throw new SsurgeonParseException("Cannot manually change the sentence index. If you need an operation to change an entire sentence's sentIndex, please file an issue on github.");
}
if (attributes.containsKey("docID")) {
throw new SsurgeonParseException("Cannot manually change a document ID. If you need an operation to change an entire sentence's document ID, please file an issue on github.");
}
// if there's an exception, we'll barf when creating the pattern rather than at runtime
try {
CoreLabel newNodeObj = fromCheapStrings(attributes);
} catch (UnsupportedOperationException e) {
throw new SsurgeonParseException("Unable to process node attribute keys for Ssurgeon operation", e);
}
}
/**
* Given the keys and values of the CoreAnnotation attributes,
* build a CoreLabel to use as the new word
*/
public static CoreLabel fromCheapStrings(Map<String, String> attributes) {View on GitHub (pinned to 1b7edd19c4)