stanfordnlp/CoreNLP · error · RuntimeException
Error creating ChineseMaxentLexicon
Error message
Error creating ChineseMaxentLexicon{e} What it means
ChineseMorphFeatureSets' constructor scans a feature directory for .gb files and calls getFeatures on each; an IOException while reading any file is rethrown as a RuntimeException 'Error creating ChineseMaxentLexicon...'. It signals the morphological feature data could not be loaded from disk.
Solutions
- Verify the feature directory exists and contains .gb files
- Check the wrapped IOException message for the exact failing file
- Fix file permissions or copy the .gb feature files into the expected location
- Use the correct path to the resources bundled with the model distribution
Example fix
// before
new ChineseMorphFeatureSets("/models/chinese-features"); // dir missing
// after
File dir = new File("/models/chinese-features");
if (!dir.isDirectory() || dir.listFiles((d,n)->n.endsWith(".gb")) == null)
throw new IllegalArgumentException("Feature dir missing or no .gb files: " + dir);
new ChineseMorphFeatureSets(dir.getPath()); Defensive patterns
Strategy: try-catch
Validate before calling
File dir = new File(featureDir);
if (!dir.isDirectory()) throw new IllegalStateException("Missing feature dir: " + featureDir);
File[] gb = dir.listFiles((d, n) -> n.endsWith(".gb"));
if (gb == null || gb.length == 0) throw new IllegalStateException("No .gb feature files in " + featureDir); Try / catch
try { fs = new ChineseMorphFeatureSets(featureDir); }
catch (RuntimeException e) { log.error("Feature load failed: {}", e.getMessage(), e); throw new IllegalStateException("Fix chinese feature data path", e); } Prevention
- Package .gb feature files with the model and resolve paths from the classpath
- Check directory readability at startup
- Pin the exact feature-data layout the library expects
When it happens
Trigger: Constructing ChineseMorphFeatureSets with a featureDir that does not exist, is unreadable, or whose .gb files fail I/O while being read (also note listFiles may return null and cause an NPE in the same try block).
Common situations: Wrong path to the Chinese morphological feature dictionary files; data files missing from deployment (not in classpath/resources); permission problems reading the directory.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Could not read from double initial LOP weights file
- Couldn't read RegexNER from " + mapping
- Couldn't read function word file
- No input file provided (use -textFile)
- TokensRegexNERAnnotator
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/32965baa5188ac60.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/ChineseMorphFeatureSets.java:43
private Map<String, Pair<Set<Character>, Set<Character>>> affixFeatures = Generics.newHashMap();
public Map<String, Set<Character>> getSingletonFeatures() {
return singletonFeatures;
}
public Map<String, Pair<Set<Character>, Set<Character>>> getAffixFeatures() {
return affixFeatures;
}
public ChineseMorphFeatureSets(String featureDir) {
try {
File dir = new File(featureDir);
File[] files = dir.listFiles((dir1, name) -> name.endsWith(".gb"));
for (File file : files) {
getFeatures(file);
}
} catch (IOException e) {
throw new RuntimeException("Error creating ChineseMaxentLexicon" + e);
}
}
private enum FeatType {
PREFIX, SUFFIX, SINGLETON
}
private void getFeatures(File file) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GB18030"));
String filename = file.getName();
String singleFeatName = filename;
if (singleFeatName.indexOf('.') >= 0) {
singleFeatName = singleFeatName.substring(0, filename.lastIndexOf('.'));
}
FeatType featType = null;
for (FeatType ft : FeatType.values()) {
if (filename.contains(ft.toString().toLowerCase())) {View on GitHub (pinned to 1b7edd19c4)