stanfordnlp/CoreNLP · error · java.lang.RuntimeException

Error loading prefixes from " + options.prefixFilename

Error message

Error loading prefixes from " + options.prefixFilename

What it means

QuantifiableEntityExtractor.initEnv calls UnitPrefix.registerPrefixes(env, options.prefixFilename); an IOException reading that file is wrapped in a RuntimeException naming the prefix file. Unit prefix definitions (kilo, milli, etc.) are mandatory for quantity extraction, so init fails fast.

Solutions

  1. Verify options.prefixFilename resolves correctly; use an absolute path.
  2. Check file existence/readability before constructing the extractor.
  3. Include the prefixes file in the deployment and reference it via classpath.
  4. Inspect the wrapped IOException cause for the underlying read error.

Example fix

// before
props.setProperty("qe.prefixFile", "prefixes.txt");
// after
props.setProperty("qe.prefixFile", "/opt/models/qe/prefixes.txt");
Defensive patterns

Strategy: validation

Validate before calling

File prefixes = new File(options.prefixFilename);
if (!prefixes.isFile() || !prefixes.canRead())
  throw new IllegalArgumentException("Prefix file missing/unreadable: " + options.prefixFilename);

Try / catch

try {
  extractor.init(props);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("Error loading prefixes from")) {
    log.severe("Fix qe prefix path: " + e.getCause());
  }
  throw e;
}

Prevention

When it happens

Trigger: Initializing the QE extractor with options.prefixFilename pointing to a missing/unreadable/malformed prefixes file.

Common situations: Missing QE models/resources directory, wrong working directory when launching the pipeline, or resource files not packaged in the jar.

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/8247000519c95a0c. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/qe/QuantifiableEntityExtractor.java:77

    return CoreMapExpressionExtractor.createExtractorFromFiles(env, filenames);
  }

  private void initEnv() {
    env = TokenSequencePattern.getNewEnv();
    env.setDefaultTokensAnnotationKey(CoreAnnotations.NumerizedTokensAnnotation.class);

    // Do case insensitive matching
    env.setDefaultStringMatchFlags(Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
    env.setDefaultStringPatternFlags(Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
    try {
      Units.registerUnits(env, options.unitsFilename);
    } catch (IOException ex)  {
      throw new RuntimeException("Error loading units from " + options.unitsFilename, ex);
    }
    try {
      UnitPrefix.registerPrefixes(env, options.prefixFilename);
    } catch (IOException ex)  {
      throw new RuntimeException("Error loading prefixes from " + options.prefixFilename, ex);
    }
    env.bind("options", options);

    env.bind("numcomptype", CoreAnnotations.NumericCompositeTypeAnnotation.class);
    env.bind("numcompvalue", CoreAnnotations.NumericCompositeValueAnnotation.class);
  }

  private static void generatePrefixDefs(String infile, String outfile) throws IOException {
    List<UnitPrefix> prefixes = UnitPrefix.loadPrefixes(infile);
    PrintWriter pw = IOUtils.getPrintWriter(outfile);
    pw.println("SI_PREFIX_MAP = {");
    List<String> items = new ArrayList<>();
    for (UnitPrefix prefix : prefixes) {
      if ("SI".equals(prefix.system)) {
        items.add("\"" + prefix.name + "\": " + prefix.getName().toUpperCase());
      }
    }
    pw.println(StringUtils.join(items, ",\n"));

View on GitHub (pinned to 1b7edd19c4)