stanfordnlp/CoreNLP · error · RuntimeException

Couldn't read function word file

Error message

Couldn't read function word file 

What it means

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>'.

Solutions

  1. Verify the function word file path exists and is readable from the process working directory
  2. Check file permissions and that the filename option/property is set to the intended absolute path
  3. Regenerate or re-download the function word file if it is corrupt

Example fix

// before
new ChineseMaxentLexicon(op, "funcwords.txt"); // file not on disk
// after
new ChineseMaxentLexicon(op, "/absolute/path/to/funcwords.txt");
Defensive patterns

Strategy: try-catch

Validate before calling

File f = new File(functionWordsPath); if (!f.isFile() || !f.canRead()) throw new IllegalStateException("Function word file missing/unreadable: " + f.getAbsolutePath());

Try / catch

try { new ChineseMaxentLexicon(op, fnFile); } catch (RuntimeException e) { if (e.getMessage().startsWith("Couldn't read function word file")) { fixPathOrRecreate(e); } }

Prevention

When it happens

Trigger: Constructing ChineseMaxentLexicon with a functionWords filename pointing to a nonexistent, unreadable, or corrupt file, so FileInputStream throws IOException inside the constructor.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/fe39fc9c35aa25c9. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/ChineseMaxentLexicon.java:203

  }

  public ChineseMaxentLexicon(Options op, Index<String> wordIndex, Index<String> tagIndex, int featureLevel) {
    this.op = op;
    this.tlpParams = op.tlpParams;
    this.ctlp = op.tlpParams.treebankLanguagePack();;
    this.wordIndex = wordIndex;
    this.tagIndex = tagIndex;
    this.featureLevel = featureLevel;
    if (fixUnkFunctionWords) {
      String filename = "unknown_function_word-simple.gb";
      try {
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "GB18030"));
        for (String line = in.readLine(); line != null; line = in.readLine()) {
          String[] parts = line.split("\\s+", 2);
          functionWordTags.put(parts[0], parts[1]);
        }
      } catch (IOException e) {
        throw new RuntimeException("Couldn't read function word file " + filename);
      }
    }
  }

  // only used at training time
  transient IntCounter<TaggedWord> datumCounter;

  @Override
  public void initializeTraining(double numTrees) {
    verbose("Training ChineseMaxentLexicon.");
    verbose("trainOnLowCount = " + trainOnLowCount + ", trainByType = " + trainByType + ", featureLevel = " + featureLevel + ", tuneSigma = " + tuneSigma);
    verbose("Making dataset...");

    if (featExtractor == null) {
      featExtractor = new ChineseWordFeatureExtractor(featureLevel);
    }

    this.datumCounter = new IntCounter<>();

View on GitHub (pinned to 1b7edd19c4)