stanfordnlp/CoreNLP · warning
Could not read Regex mapping
Error message
Could not read Regex mapping: ${mappingFile} What it means
readRegexnerGazette loads a TSV regexner mapping file line by line (key TAB target). The file could not be read (missing path, unreadable, or IO problem), so the parser logs a warning and returns whatever partial map was accumulated (possibly empty). This is non-fatal by design: the NER pipeline continues with fewer/no regexner entries.
Solutions
- Verify the regexner.mapping path exists and is readable from the process working directory (ls -l the file).
- Use an absolute path or a classpath-qualified resource URL in the ner.regexner.mapping property.
- Check file permissions and that the user running the JVM can read it.
- If intentional absence, silence is fine — but confirm the map contents by logging mapping.size() and ensure downstream NER quality is acceptable.
Example fix
// before ner.regexner.mapping=gazetteers/regexner.txt // after ner.regexner.mapping=/absolute/path/to/gazetteers/regexner.txt
Defensive patterns
Strategy: validation
Validate before calling
File f = new File(mappingPath);
if (!f.isFile() || !f.canRead()) {
throw new IllegalArgumentException("regexner mapping not readable: " + mappingPath);
} Try / catch
try {
Map<String,String> m = readRegexnerGazette(path);
if (m.isEmpty()) log.warn("regexner map empty — check path " + path);
} catch (IOException e) {
log.warn("falling back to default gazetteer", e);
} Prevention
- Use absolute paths for mapping files in production configs.
- Check file existence/readability at startup before building the pipeline.
- Load gazetteer resources via getResourceAsStream when shipping inside a jar.
When it happens
Trigger: Calling NERClassifierCombiner setup with a regexner.mapping property pointing to a nonexistent, unreadable, or empty file; or a file with a bad encoding/unreadable permissions that throws IOException during readLines.
Common situations: Relative path resolved against the wrong working directory when launching from an IDE or service; model jar path typo (resource inside jar not addressable as a file path); file deleted after config was written.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Error reading threshold file
- TokensRegexNERAnnotator
- Unknown default unit
- Error loading classifier from
- edu.stanford.nlp.io.RuntimeIOException
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/70baa12c7b48f86e.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/NERClassifierCombiner.java:403
/**
* Read a gazette mapping in TokensRegex format from the given path
* The format is: 'case_sensitive_word \t target_ner_class' (additional info is ignored).
*
* @param mappingFile The mapping file to read from, as a path either on the filesystem or in your classpath.
*
* @return The mapping from word to NER tag.
*/
private static Map<String, String> readRegexnerGazette(String mappingFile) {
Map<String, String> mapping = new HashMap<>();
try (BufferedReader reader = IOUtils.readerFromString(mappingFile.trim())){
for (String line : IOUtils.slurpReader(reader).split("\n")) {
String[] fields = line.split("\t");
String key = fields[0];
String target = fields[1];
mapping.put(key, target);
}
} catch (IOException e) {
log.warn("Could not read Regex mapping: " + mappingFile);
}
return Collections.unmodifiableMap(mapping);
}
/** The main method. */
public static void main(String[] args) throws Exception {
StringUtils.logInvocationString(log, args);
Properties props = StringUtils.argsToProperties(args);
SeqClassifierFlags flags = new SeqClassifierFlags(props, false); // false for print probs as printed in next code block
String loadPath = props.getProperty("loadClassifier");
NERClassifierCombiner ncc;
if (loadPath != null) {
// note that when loading a serialized classifier, the philosophy is override
// any settings in props with those given in the commandline
// so if you dumped it with useSUTime = false, and you say -useSUTime atView on GitHub (pinned to 1b7edd19c4)