{"record":{"id":"e4105ab24256e5c3","repo":"stanfordnlp/CoreNLP","slug":"removecodetrees-only-works-on-a-single-file","errorCode":null,"errorMessage":"-removeCodeTrees only works on a single file","messagePattern":"-removeCodeTrees only works on a single file","errorType":"console","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/Treebanks.java","lineNumber":311,"sourceCode":"        }\n      });\n    }\n\n    if (decimate) {\n      Writer w1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(decimatePrefix + \"-train.txt\"), encoding));\n      Writer w2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(decimatePrefix + \"-dev.txt\"), encoding));\n      Writer w3 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(decimatePrefix + \"-test.txt\"), encoding));\n      treebank.decimate(w1, w2, w3);\n    }\n\n    if (timing) {\n      runTiming(treebank);\n    }\n\n    if (removeCodeTrees) {\n      // this is a bit of a hack. It only works on an individual file\n      if (new File(args[i]).isDirectory()) {\n        throw new RuntimeException(\"-removeCodeTrees only works on a single file\");\n      }\n      String treebankStr = IOUtils.slurpFile(args[i]);\n      treebankStr = treebankStr.replaceAll(\"\\\\( \\\\(CODE <[^>]+>\\\\)\\\\)\", \"\");\n      Writer w = new OutputStreamWriter(new FileOutputStream(args[i]), encoding);\n      w.write(treebankStr);\n      w.close();\n    }\n  } // end main()\n\n\n  private static void printPunct(Treebank treebank, TreebankLanguagePack tlp, PrintWriter pw) {\n    if (tlp == null) {\n      log.info(\"The -punct option requires you to specify -tlp\");\n    } else {\n      Predicate<String> punctTagFilter = tlp.punctuationTagAcceptFilter();\n      for (Tree t : treebank) {\n        List<TaggedWord> tws = t.taggedYield();\n        for (TaggedWord tw : tws) {","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/Treebanks.java#L293-L329","documentation":"The -removeCodeTrees option of Treebanks.main strips \"(CODE ...)\" pseudo-trees via a whole-file string replacement, so it can only operate on a single file. If the treebank argument is a directory, it throws RuntimeException.","triggerScenarios":"Running Treebanks with -removeCodeTrees while the treebank path (args[i]) points to a directory instead of one file.","commonSituations":"Pointing command-line treebank options at the standard directory-of-files corpus layout; scripting bulk cleanup over a folder expecting recursive handling.","solutions":["Pass a single file path as the treebank when using -removeCodeTrees.","Script a loop that applies the tool to each file in the directory individually.","Pre-concatenate directory files into one file, then run with -removeCodeTrees."],"exampleFix":"// before\njava ... Treebanks -removeCodeTrees wsj/  // directory\n// after\njava ... Treebanks -removeCodeTrees wsj/0001.mrg  // single file","handlingStrategy":"validation","validationCode":"if (removeCodeTrees && new File(treebankPath).isDirectory()) { throw new IllegalArgumentException(\"-removeCodeTrees requires a single file\"); }","typeGuard":null,"tryCatchPattern":"try { Treebanks.main(args); } catch (RuntimeException e) { /* rerun per-file over directory contents */ }","preventionTips":["Check the option's file-only constraint before pointing it at corpus directories.","Iterate directory files in a wrapper script.","Document the flag's single-file limitation in build scripts."],"tags":["cli","nlp","file-handling"],"backgroundTag":"invalid-cli-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}