stanfordnlp/CoreNLP · error · IllegalArgumentException
Need to give a pattern location with -patterns
Error message
Need to give a pattern location with -patterns
What it means
Ssurgeon's main() command-line driver requires the -patterns argument pointing at the Ssurgeon rules location. When argument parsing finishes without a pattern directory/file set, it throws IllegalArgumentException before any processing begins.
Solutions
- Add -patterns <path> (rules file or directory) to the command line
- Check the flag spelling and that the variable holding the path is non-empty in your script
- Run without args / consult the usage message to see required flags
Example fix
// before java Ssurgeon -treebank trees/ -type interactive // after java Ssurgeon -treebank trees/ -type interactive -patterns rules/ssurgeon-rules.xml
Defensive patterns
Strategy: validation
Validate before calling
if (args == null || Arrays.stream(args).noneMatch(a -> a.equals("-patterns"))) {
throw new IllegalArgumentException("-patterns is required");
} Try / catch
try {
Ssurgeon.main(args);
} catch (IllegalArgumentException e) {
log.error("Usage: Ssurgeon -patterns <rules> ...");
} Prevention
- Wrap Ssurgeon CLI runs in scripts that assert required flags exist
- Echo the full command line before invocation
- Check that path variables are non-empty before substituting into the command
When it happens
Trigger: Running java edu.stanford.nlp.semgraph.semgrex.ssurgeon.Ssurgeon without -patterns, or misspelling the flag so it is not consumed.
Common situations: CLI invocations copied from docs that omitted -patterns; shell scripts where the variable holding the path is empty; confusing -patterns with other flag names.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- args: treebankPath trainNums testNums
- Must specify input file with -input
- Parsing Ssurgeon args: unknown flag
- Unknown argument " + newArgs[argIndex]
- Bad character encoding
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/18cff00cb87632cc.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java:1160
/**
* Performs a simple test and print of a given file.
* Usage Ssurgeon [-info infoFile] -patterns patternDir [-type interactive|testinfo]
*/
public static void main(String[] args) {
for (int argIndex = 0; argIndex < args.length; ++argIndex) {
if (args[argIndex].equalsIgnoreCase("-info")) {
argsBox.info = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-patterns")) {
argsBox.patternDirStr = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-type")) {
argsBox.type = RUNTYPE.valueOf(args[argIndex + 1]);
argIndex += 2;
}
}
if (argsBox.patternDirStr == null) {
throw new IllegalArgumentException("Need to give a pattern location with -patterns");
}
argsBox.init();
System.out.println(argsBox);
try {
if (argsBox.type == RUNTYPE.interactive) {
Ssurgeon.inst().testRead(argsBox.patternDir);
}
} catch (Exception e) {
log.error(e);
}
}
}
View on GitHub (pinned to 1b7edd19c4)