stanfordnlp/CoreNLP · error · edu.stanford.nlp.util.RuntimeIOException

Couldn't read RegexNER from " + mapping

Error message

Couldn't read RegexNER from " + mapping

What it means

The string-mapping constructor of RegexNERSequenceClassifier opens the mapping (file path or classpath resource) with IOUtils.readerFromString; any IOException while opening or reading it is rethrown as RuntimeIOException with this message. Without the mapping entries, the classifier cannot be constructed.

Solutions

  1. Verify the mapping path exists and is readable; use an absolute path.
  2. If it's a classpath resource, ensure it's packaged and the resource string is correct.
  3. Validate the mapping file format (regex<TAB>type[<TAB>overwritable][<TAB>priority]) — malformed parse content can also surface as IOException in readEntries.
  4. Check the wrapped IOException cause for the exact failure.

Example fix

// before
props.setProperty("regexner.mapping", "my_rules.txt");
// after
props.setProperty("regexner.mapping", "/etc/stanford/my_rules.txt");
Defensive patterns

Strategy: validation

Validate before calling

Path mapping = Paths.get(mappingPath);
if (!Files.isReadable(mapping))
  throw new IllegalArgumentException("regexner mapping not readable: " + mappingPath);
// optional: validate format lines
long bad = Files.lines(mapping).filter(l -> !l.trim().isEmpty() && !l.startsWith("#"))
    .filter(l -> { String[] p = l.split("\t"); return p.length < 2 || p.length > 4; }).count();
if (bad > 0) throw new IllegalStateException(bad + " malformed mapping lines");

Try / catch

try {
  classifier = new RegexNERSequenceClassifier(props, mapping, true, false);
} catch (RuntimeIOException e) {
  log.severe("RegexNER mapping unreadable: " + mapping + " cause: " + e.getCause());
  throw e;
}

Prevention

When it happens

Trigger: Constructing RegexNERSequenceClassifier (or setting regexner.mapping in a pipeline) with a path that doesn't exist, isn't readable, or isn't a valid classpath reference.

Common situations: Relative path that breaks when the pipeline runs from a different working directory, mapping resource missing from the jar, typo in the property regexner.mapping, or permission problems.

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/54422969509f4f15. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/regexp/RegexNERSequenceClassifier.java:115

   *                          RegexNERSequenceClassifier is run successively over the same
   *                          text (e.g., to overwrite some older annotations).
   * @param validPosRegex May be null or an empty String, in which case any (or no) POS is valid
   *                      in matching. Otherwise, this is a regex which is matched with find()
   *                      [not matches()] and which must be matched by the POS of at least one
   *                      word in the sequence for it to be labeled via any matching rules.
   *                      (Note that this is a postfilter; using this will not speed up matching.)
   */
  public RegexNERSequenceClassifier(String mapping, boolean ignoreCase, boolean overwriteMyLabels, String validPosRegex) {
    super(new Properties());
    if (validPosRegex != null && !validPosRegex.equals("")) {
      validPosPattern = Pattern.compile(validPosRegex);
    } else {
      validPosPattern = null;
    }
    try (BufferedReader rd = IOUtils.readerFromString(mapping)) {
      entries = readEntries(rd, ignoreCase);
    } catch (IOException e) {
      throw new RuntimeIOException("Couldn't read RegexNER from " + mapping, e);
    }

    this.ignoreCase = ignoreCase;
    myLabels = Generics.newHashSet();
    // Can always override background or none.
    myLabels.add(flags.backgroundSymbol);
    myLabels.add(null);
    if (overwriteMyLabels) {
      for (Entry entry: entries) myLabels.add(entry.type);
    }
    // log.info("RegexNER using labels: " +  myLabels);
  }

  /**
   * Make a new instance of this classifier. The ignoreCase option allows case-insensitive
   * regular expression matching, allowing the idea that the provided file might just
   * be a manual list of the possible entities for each type.
   *

View on GitHub (pinned to 1b7edd19c4)