stanfordnlp/CoreNLP · error · RuntimeException
only support settings for CTB and PKU now.
Error message
only support settings for CTB and PKU now.
What it means
NonDict2's constructor builds the non-dictionary (unseen word) feature dictionary based on corpus flags. It only supports CTB and PKU: if flags.useAs, useHk, or useMsr is set, it refuses and throws RuntimeException('only support settings for CTB and PKU now.') because no .non dictionary resource exists for those corpora.
Solutions
- Set dict2name to a custom non-dictionary file path so the constructor builds NonDict2 from your resource
- Disable useAs/useHk/useMsr and use CTB or PK settings instead
- Supply your own corpus-specific .non dictionary file and adjust the constructor path
Example fix
// before (Properties) useAs=true // after (Properties) dict2name=asbc.non useAs=false
Defensive patterns
Strategy: validation
Validate before calling
Properties p = /* segmenter props */;
boolean unsupported = Boolean.parseBoolean(p.getProperty("useAs","false"))
|| Boolean.parseBoolean(p.getProperty("useHk","false"))
|| Boolean.parseBoolean(p.getProperty("useMsr","false"));
if (unsupported && (p.getProperty("dict2name") == null || p.getProperty("dict2name").isEmpty())) {
throw new IllegalArgumentException("Set dict2name or use CTB/PK settings (NonDict2 limitation)");
} Try / catch
try {
segmenter.initialize();
} catch (RuntimeException e) {
if (e.getMessage().contains("CTB and PKU")) {
props.setProperty("dict2name", "custom.non");
segmenter.initialize();
} else throw e;
} Prevention
- For ASBC/HK/MSR data, always provide dict2name pointing to a valid .non dictionary
- Don't combine corpus flags; choose CTB or PK for NonDict2 features
- Verify dictionary files exist under corporaDict/dict/ at startup
When it happens
Trigger: Instantiating NonDict2 (during segmenter setup) with useAs=true, useHk=true, or useMsr=true and no custom dict2name specified.
Common situations: Segmenting ASBC (Taiwan), HK, or MSR Sighan data with the NonDict2 feature enabled; mixing corpus flags; users assuming all Sighan corpora are supported like CTB/PK.
Related errors
- none of flags.useXXXChar2 are on
- only support settings for CTB and PK now.
- only support settings for CTB and PK now.
- only support settings for CTB and PK now.
- Both parse.model and parse.executable properties must be…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/80308ee6d3c21cb1.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/wordseg/NonDict2.java:42
public final String corporaDict;
private final CorpusDictionary cd;
private static Redwood.RedwoodChannels logger = Redwood.channels(NonDict2.class);
public NonDict2(SeqClassifierFlags flags) {
if (flags.sighanCorporaDict != null) {
corporaDict = flags.sighanCorporaDict; // use the same flag for Sighan 2005,
// but our list is extracted from ctb
} else {
corporaDict = DEFAULT_HOME;
}
String path;
if (flags.dict2name != null && !flags.dict2name.equals("")) {
path = corporaDict + "/dict/" + flags.dict2name;
logger.info("INFO: dict2name specified | building NonDict2 from "+path);
} else if (flags.useAs || flags.useHk || flags.useMsr) {
throw new RuntimeException("only support settings for CTB and PKU now.");
} else if ( flags.usePk ) {
path = corporaDict+"/dict/pku.non";
logger.info("INFO: flags.usePk=true | building NonDict2 from "+path);
} else { // CTB
path = corporaDict+"/dict/ctb.non";
logger.info("INFO: flags.usePk=false | building NonDict2 from "+path);
}
cd = new CorpusDictionary(path);
}
public String checkDic(String c2, SeqClassifierFlags flags) {
if (cd.getW(c2).equals("1")) {
return "1";
}
return "0";
}
View on GitHub (pinned to 1b7edd19c4)