stanfordnlp/CoreNLP · error · RuntimeException
Error: -train option must have treebankPath as first…
Error message
Error: -train option must have treebankPath as first argument.
What it means
The -train option of ChineseLexiconAndWordSegmenter.main requires at least two sub-arguments, with the treebank path as the first one. If only one (or zero) sub-arguments follow -train, the option parser throws RuntimeException because it cannot determine where the training treebank lives.
Solutions
- Provide the treebank path as the first argument after -train plus at least one more argument, e.g. -train /path/to/treebank 100-9999
- Verify the command line includes the expected number of sub-arguments (the parser reads numSubArgs(args, argIndex) from the value preceding them)
- Consult the usage documentation for -train's expected argument format
Example fix
// before java ... -train /path/to/chineseTreebank // after java ... -train /path/to/chineseTreebank 100-9999
Defensive patterns
Strategy: validation
Validate before calling
if (args contains "-train") { String[] sub = nextArgs(args, idx); if (sub.length < 2) throw new IllegalArgumentException("-train needs treebankPath plus filter args"); } Try / catch
try { ChineseLexiconAndWordSegmenter.main(args); } catch (RuntimeException e) { if (e.getMessage().contains("-train option")) printUsage(); } Prevention
- Always pass treebankPath as the first -train sub-argument
- Build command lines programmatically and validate arg counts before invoking main
When it happens
Trigger: Running the segmenter's main() with a -train flag that lists fewer than 2 arguments, e.g. -train only a file path with no second argument, when the code requires numSubArgs > 1 to read treebankPath.
Common situations: Command-line invocations of the Chinese parser trainer missing the second argument (e.g. tree range/filter parameters), copy-pasted command lines where a filter argument was dropped, or scripting errors.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- No test treebank path specified...
- Error: No dest file provided in properties or via command…
- Error: No training file provided in properties or via…
- Error: No training file provided in properties or via…
- -labels is required
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/16a8107d2d8c3aec.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/ChineseLexiconAndWordSegmenter.java:438
"LexicalizedParser parserFileOrUrl filename*");
return;
}
Options op = new Options();
op.tlpParams = new ChineseTreebankParserParams();
// while loop through option arguments
while (argIndex < args.length && args[argIndex].charAt(0) == '-') {
if (args[argIndex].equalsIgnoreCase("-train")) {
train = true;
saveToSerializedFile = true;
int numSubArgs = numSubArgs(args, argIndex);
argIndex++;
if (numSubArgs > 1) {
treebankPath = args[argIndex];
argIndex++;
} else {
throw new RuntimeException("Error: -train option must have treebankPath as first argument.");
}
if (numSubArgs == 2) {
trainFilter = new NumberRangesFileFilter(args[argIndex++], true);
} else if (numSubArgs >= 3) {
try {
int low = Integer.parseInt(args[argIndex]);
int high = Integer.parseInt(args[argIndex + 1]);
trainFilter = new NumberRangeFileFilter(low, high, true);
argIndex += 2;
} catch (NumberFormatException e) {
// maybe it's a ranges expression?
trainFilter = new NumberRangesFileFilter(args[argIndex], true);
argIndex++;
}
}
} else if (args[argIndex].equalsIgnoreCase("-encoding")) { // sets encoding for TreebankLangParserParams
encoding = args[argIndex + 1];
op.tlpParams.setInputEncoding(encoding);View on GitHub (pinned to 1b7edd19c4)