{"record":{"id":"104bbdfce941a569","repo":"stanfordnlp/CoreNLP","slug":"cannot-manually-change-the-sentence-index-if-you","errorCode":null,"errorMessage":"Cannot manually change the sentence index.  If you need an operation to change an entire sentence's sentIndex, please file an issue on github.","messagePattern":"Cannot manually change the sentence index\\.  If you need an operation to change an entire sentence's sentIndex, please file an issue on github\\.","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java","lineNumber":159,"sourceCode":"      // the payoff for tempIndex == maxIndex + 2:\n      // everything will be moved one higher, unless it's the new node\n      SsurgeonUtils.moveNodes(sg, sm, x -> (x >= newIndex && x != tempIndex), x -> x+1, true);\n      SsurgeonUtils.moveNode(sg, sm, newNode, newIndex);\n    }\n\n    return true;\n  }\n\n  /**\n   * Certain attributes cannot be edited, especially docid, sentid, idx,\n   * or they mess up the hashmaps in the SemanticGraph\n   */\n  public static void checkIllegalAttributes(Map<String, String> attributes) {\n    if (attributes.containsKey(\"idx\")) {\n      throw new SsurgeonParseException(\"Cannot manually set the index attribute.  If you need a moveWord operation, please file an issue on github.\");\n    }\n    if (attributes.containsKey(\"sentIndex\")) {\n      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.\");\n    }\n    if (attributes.containsKey(\"docID\")) {\n      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.\");\n    }\n\n    // if there's an exception, we'll barf when creating the pattern rather than at runtime\n    try {\n      CoreLabel newNodeObj = fromCheapStrings(attributes);\n    } catch (UnsupportedOperationException e) {\n      throw new SsurgeonParseException(\"Unable to process node attribute keys for Ssurgeon operation\", e);\n    }\n  }\n\n  /**\n   * Given the keys and values of the CoreAnnotation attributes,\n   * build a CoreLabel to use as the new word\n   */\n  public static CoreLabel fromCheapStrings(Map<String, String> attributes) {","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java#L141-L177","documentation":"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.","triggerScenarios":"An AddDep/Ssurgeon edit whose attributes map contains the key \"sentIndex\"; thrown during rule construction from the AddDep constructor via checkIllegalAttributes.","commonSituations":"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.","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."],"exampleFix":"// before\nattrs.put(\"sentIndex\", \"2\");\nattrs.put(\"word\", \"cat\");\n\n// after\nattrs.put(\"word\", \"cat\"); // sentIndex is managed by the graph","handlingStrategy":"validation","validationCode":"// Java\nif (attributes.containsKey(\"sentIndex\")) {\n  throw new IllegalArgumentException(\"sentIndex cannot be set per-node; change it at the sentence level\");\n}","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n  AddDep.checkIllegalAttributes(attrs);\n} catch (SsurgeonParseException e) {\n  log.warning(\"Attribute map rejected: \" + e.getMessage());\n}","preventionTips":["Treat sentIndex as sentence-level metadata, never a node attribute.","Filter attribute maps to a fixed whitelist before passing them to Ssurgeon operations."],"tags":["java","ssurgeon","validation","graph"],"backgroundTag":"invalid-argument-value","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"}