{"record":{"id":"fe39fc9c35aa25c9","repo":"stanfordnlp/CoreNLP","slug":"couldn-t-read-function-word-file","errorCode":null,"errorMessage":"Couldn't read function word file ","messagePattern":"Couldn't read function word file ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ChineseMaxentLexicon.java","lineNumber":203,"sourceCode":"  }\n\n  public ChineseMaxentLexicon(Options op, Index<String> wordIndex, Index<String> tagIndex, int featureLevel) {\n    this.op = op;\n    this.tlpParams = op.tlpParams;\n    this.ctlp = op.tlpParams.treebankLanguagePack();;\n    this.wordIndex = wordIndex;\n    this.tagIndex = tagIndex;\n    this.featureLevel = featureLevel;\n    if (fixUnkFunctionWords) {\n      String filename = \"unknown_function_word-simple.gb\";\n      try {\n        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename), \"GB18030\"));\n        for (String line = in.readLine(); line != null; line = in.readLine()) {\n          String[] parts = line.split(\"\\\\s+\", 2);\n          functionWordTags.put(parts[0], parts[1]);\n        }\n      } catch (IOException e) {\n        throw new RuntimeException(\"Couldn't read function word file \" + filename);\n      }\n    }\n  }\n\n  // only used at training time\n  transient IntCounter<TaggedWord> datumCounter;\n\n  @Override\n  public void initializeTraining(double numTrees) {\n    verbose(\"Training ChineseMaxentLexicon.\");\n    verbose(\"trainOnLowCount = \" + trainOnLowCount + \", trainByType = \" + trainByType + \", featureLevel = \" + featureLevel + \", tuneSigma = \" + tuneSigma);\n    verbose(\"Making dataset...\");\n\n    if (featExtractor == null) {\n      featExtractor = new ChineseWordFeatureExtractor(featureLevel);\n    }\n\n    this.datumCounter = new IntCounter<>();","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ChineseMaxentLexicon.java#L185-L221","documentation":"ChineseMaxentLexicon's constructor reads an optional function-word file (format: word tag per line, GB18030 encoding). If an IOException occurs while reading that file — missing file, bad path, or I/O error — it is rethrown as RuntimeException 'Couldn't read function word file <filename>'.","triggerScenarios":"Constructing ChineseMaxentLexicon with a functionWords filename pointing to a nonexistent, unreadable, or corrupt file, so FileInputStream throws IOException inside the constructor.","commonSituations":"Typoed or relative path that doesn't resolve from the working directory; file created with a different encoding or permissions; option wiring passing the wrong property value for the function-word file.","solutions":["Verify the function word file path exists and is readable from the process working directory","Check file permissions and that the filename option/property is set to the intended absolute path","Regenerate or re-download the function word file if it is corrupt"],"exampleFix":"// before\nnew ChineseMaxentLexicon(op, \"funcwords.txt\"); // file not on disk\n// after\nnew ChineseMaxentLexicon(op, \"/absolute/path/to/funcwords.txt\");","handlingStrategy":"try-catch","validationCode":"File f = new File(functionWordsPath); if (!f.isFile() || !f.canRead()) throw new IllegalStateException(\"Function word file missing/unreadable: \" + f.getAbsolutePath());","typeGuard":null,"tryCatchPattern":"try { new ChineseMaxentLexicon(op, fnFile); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Couldn't read function word file\")) { fixPathOrRecreate(e); } }","preventionTips":["Verify the function word file path (absolute preferred) before construction","Check file permissions and GB18030 encoding integrity of the file"],"tags":["java","io","file-not-found","parser"],"backgroundTag":"file-not-found","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"}