{"record":{"id":"7fa61f3677309e4f","repo":"stanfordnlp/CoreNLP","slug":"cannot-combine-mwt-out-of-only-names-size-wor","errorCode":null,"errorMessage":"Cannot combine MWT out of only ${names.size()} words","messagePattern":"Cannot combine MWT out of only (.+?) words","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/CombineMWT.java","lineNumber":35,"sourceCode":" *<br>\n * For the most part, the nodes themselves are unchanged, but the\n * nodes now have the CoreAnnotations representing MWTness added\n *<br>\n * This is a convenience operation which exists because the basic\n * version of it using EditNode is a bit of a pain\n *\n * @author John Bauer\n */\npublic class CombineMWT extends SsurgeonEdit {\n  public static final String LABEL = \"combineMWT\";\n  final List<String> names;\n  final String word;\n\n  public CombineMWT(List<String> names, String word) {\n    this.names = new ArrayList<>(names);\n    this.word = word;\n    if (names.size() < 2) {\n      throw new SsurgeonParseException(\"Cannot combine MWT out of only \" + names.size() + \" words\");\n    }\n  }\n\n  /**\n   * Emits a parseable instruction string.\n   */\n  @Override\n  public String toEditString() {\n    StringWriter buf = new StringWriter();\n    buf.write(LABEL);\n    for (String name : names) {\n      buf.write(\"\\t\");\n      buf.write(name);\n    }\n    if (word != null && !word.equals(\"\")) {\n      buf.write(\"\\t\");\n      buf.write(word);\n    }","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/CombineMWT.java#L17-L53","documentation":"CombineMWT joins at least two adjacent words into one multi-word token (MWT). The constructor throws SsurgeonParseException if fewer than two node names are supplied, because a \"combination\" of a single word is meaningless and would corrupt MWT bookkeeping.","triggerScenarios":"Constructing new CombineMWT(List.of(\"one\"), word) or writing an Ssurgeon combinemwt instruction with only one node name; thrown from the CombineMWT constructor.","commonSituations":"Programmatically generating combinemwt rules where an empty/short match list slips through; hand-editing .ssurgeon files and deleting one of the node names.","solutions":["Supply at least two node names in the list passed to CombineMWT.","Add a size check (names.size() >= 2) before constructing the operation and emit a clearer error earlier.","If only one word matches, skip emitting the combinemwt instruction entirely."],"exampleFix":"// before\nnew CombineMWT(Collections.singletonList(\"w1\"), \"combined\");\n\n// after\nList<String> names = List.of(\"w1\", \"w2\");\nif (names.size() >= 2) {\n  new CombineMWT(names, \"combined\");\n}","handlingStrategy":"validation","validationCode":"// Java\nif (names == null || names.size() < 2) {\n  throw new IllegalArgumentException(\"CombineMWT requires at least 2 node names\");\n}","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n  CombineMWT op = new CombineMWT(names, word);\n} catch (SsurgeonParseException e) {\n  log.warning(\"Skipping combinemwt: \" + e.getMessage());\n}","preventionTips":["Only emit combinemwt instructions when the semgrex pattern matches at least two distinct nodes.","Assert list size >= 2 in rule-generation code before constructing the operation."],"tags":["java","ssurgeon","mwt","validation"],"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"}