{"record":{"id":"b0dabbf981d502eb","repo":"stanfordnlp/CoreNLP","slug":"problem-reading-similar-words-file","errorCode":null,"errorMessage":"Problem reading similar words file!","messagePattern":"Problem reading similar words file!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ChineseSimWordAvgDepGrammar.java","lineNumber":79,"sourceCode":"        Matcher m = linePattern.matcher(wordMapLine);\n        if (!m.matches()) {\n          log.info(\"Ill-formed line in similar word map file: \" + wordMapLine);\n          continue;\n        }\n\n        Pair<Integer, String> iTW = new Pair<>(wordIndex.addToIndex(m.group(1)), m.group(2));\n        double score = Double.parseDouble(m.group(5));\n\n        List<Triple<Integer, String, Double>> tripleList = hashMap.get(iTW);\n        if (tripleList == null) {\n          tripleList = new ArrayList<>();\n          hashMap.put(iTW, tripleList);\n        }\n\n        tripleList.add(new Triple<>(wordIndex.addToIndex(m.group(3)), m.group(4), score));\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(\"Problem reading similar words file!\");\n    }\n\n    return hashMap;\n  }\n\n  @Override\n  public double scoreTB(IntDependency dependency) {\n    //return op.testOptions.depWeight * Math.log(probSimilarWordAvg(dependency));\n    return op.testOptions.depWeight * Math.log(probTBwithSimWords(dependency));\n  }\n\n  public void setLex(Lexicon lex) {\n    this.lex = lex;\n  }\n\n  private ClassicCounter<String> statsCounter = new ClassicCounter<>();\n\n  public void dumpSimWordAvgStats() {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ChineseSimWordAvgDepGrammar.java#L61-L97","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nnew ChineseSimWordAvgDepGrammar(...); // similar-words file missing\n// after\n// ensure the file referenced by the model (e.g. chineseSimilarWords.txt) is present in the working directory\nnew File(similarWordsPath).canRead() check before constructing","handlingStrategy":"try-catch","validationCode":"if (!new File(similarWordsFile).canRead()) throw new IllegalStateException(\"Similar words file not readable: \" + similarWordsFile);","typeGuard":null,"tryCatchPattern":"try { new ChineseSimWordAvgDepGrammar(...); } catch (RuntimeException e) { if (e.getMessage().equals(\"Problem reading similar words file!\")) { log.fatal(\"Check similar-words data file presence/permissions\"); } }","preventionTips":["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"],"tags":["java","io","file-read-failed","parser"],"backgroundTag":"file-read-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}