stanfordnlp/CoreNLP · error · RuntimeException
Problem reading similar words file!
Error message
Problem reading similar words file!
What it means
ChineseSimWordAvgDepGrammar.getMap parses a 'similar words' file into a map of similar-word triples used by the dependency grammar. Any IOException while reading that file is converted into RuntimeException 'Problem reading similar words file!', losing the filename in the message.
Solutions
- Confirm the similar words file exists at the expected (usually relative to working directory) location and is readable
- Fix file permissions or supply the file that ships with the Chinese parser model
- Add debugging by wrapping the read with your own IO handling to surface the actual path being opened
Example fix
// before new ChineseSimWordAvgDepGrammar(...); // similar-words file missing // after // ensure the file referenced by the model (e.g. chineseSimilarWords.txt) is present in the working directory new File(similarWordsPath).canRead() check before constructing
Defensive patterns
Strategy: try-catch
Validate before calling
if (!new File(similarWordsFile).canRead()) throw new IllegalStateException("Similar words file not readable: " + similarWordsFile); Try / catch
try { new ChineseSimWordAvgDepGrammar(...); } catch (RuntimeException e) { if (e.getMessage().equals("Problem reading similar words file!")) { log.fatal("Check similar-words data file presence/permissions"); } } Prevention
- Ship the similar-words file with model distributions and verify working directory
- Run I/O smoke tests on model data files before long training jobs
When it happens
Trigger: Constructing ChineseSimWordAvgDepGrammar when the similar-words data file cannot be opened or read: missing file, wrong path, permission problem, or I/O error during line parsing (readLine/regex processing loop).
Common situations: Distributing models without the required similar-words data file; running from a different working directory so the relative path breaks; the file failing mid-read due to encoding/corruption.
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
- Couldn't read function word file
- Error loading classifier from
- edu.stanford.nlp.io.RuntimeIOException
- Error creating data exporter
- Error reading saved links
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/b0dabbf981d502eb.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/ChineseSimWordAvgDepGrammar.java:79
Matcher m = linePattern.matcher(wordMapLine);
if (!m.matches()) {
log.info("Ill-formed line in similar word map file: " + wordMapLine);
continue;
}
Pair<Integer, String> iTW = new Pair<>(wordIndex.addToIndex(m.group(1)), m.group(2));
double score = Double.parseDouble(m.group(5));
List<Triple<Integer, String, Double>> tripleList = hashMap.get(iTW);
if (tripleList == null) {
tripleList = new ArrayList<>();
hashMap.put(iTW, tripleList);
}
tripleList.add(new Triple<>(wordIndex.addToIndex(m.group(3)), m.group(4), score));
}
} catch (IOException e) {
throw new RuntimeException("Problem reading similar words file!");
}
return hashMap;
}
@Override
public double scoreTB(IntDependency dependency) {
//return op.testOptions.depWeight * Math.log(probSimilarWordAvg(dependency));
return op.testOptions.depWeight * Math.log(probTBwithSimWords(dependency));
}
public void setLex(Lexicon lex) {
this.lex = lex;
}
private ClassicCounter<String> statsCounter = new ClassicCounter<>();
public void dumpSimWordAvgStats() {View on GitHub (pinned to 1b7edd19c4)