stanfordnlp/CoreNLP · error · RuntimeException

Wrong format:

Error message

Wrong format: 

What it means

TrueCaseAnnotator.loadMixedCaseMap loads the mixed-case word map ('truecase.mixedcasefile'). Each non-empty line must contain exactly two whitespace-separated tokens: the word and its true-cased form. Any line with a different token count causes this RuntimeException identifying the map file.

Solutions

  1. Edit the map file so every line has exactly two fields: word<TAB or space>truecased-form
  2. Remove comment lines or inline comments — the loader does not strip them
  3. Replace multi-word true-case values with single tokens or underscores
  4. Check for double spaces/tabs that inflate the split count on some lines

Example fix

// before (mixedcase map line)
iphone iPhone the sequel
// after
iphone	iPhone
Defensive patterns

Strategy: validation

Validate before calling

// Validate mixed-case map file lines before use
try (BufferedReader br = Files.newBufferedReader(Paths.get(mapFile))) {
  int lineNo = 0;
  for (String line : (Iterable<String>) br.lines()::iterator) {
    lineNo++;
    if (!line.trim().isEmpty() && line.trim().split("\\s+").length != 2)
      throw new IllegalStateException(mapFile + ":" + lineNo + " must have exactly 2 fields");
  }
}

Try / catch

try {
  pipeline = new StanfordCoreNLP(props);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Wrong format:")) {
    log.error("Mixed-case map file lines must be 'word truecasedForm': " + e.getMessage());
  }
  throw e;
}

Prevention

When it happens

Trigger: A mixed-case map file where some line splits into more or fewer than 2 whitespace-separated fields — e.g. a line with trailing comment text, multiple words per line, or blank-ish lines with stray tokens.

Common situations: Hand-built or machine-generated map files with comments ('# entry extra'), tabs plus spaces combining into >2 fields, or lines where the true-case form itself contains spaces.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/TrueCaseAnnotator.java:167

    }
    // System.err.println(text + " was classified as " + trueCase + " and so became " + trueCaseText);

    l.set(CoreAnnotations.TrueCaseTextAnnotation.class, trueCaseText);

    if (overwriteText) {
      l.set(CoreAnnotations.TextAnnotation.class, trueCaseText);
      l.set(CoreAnnotations.ValueAnnotation.class, trueCaseText);
    }
  }

  private static Map<String,String> loadMixedCaseMap(String mapFile) {
    Map<String,String> map = Generics.newHashMap();
    try (BufferedReader br = IOUtils.readerFromString(mapFile)) {
      for (String line : ObjectBank.getLineIterator(br)) {
        line = line.trim();
        String[] els = line.split("\\s+");
        if (els.length != 2) {
          throw new RuntimeException("Wrong format: " + mapFile);
        }
        map.put(els[0], els[1]);
      }
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }
    return map;
  }

  @Override
  public Set<Class<? extends CoreAnnotation>> requires() {
    return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(
        CoreAnnotations.TextAnnotation.class,
        CoreAnnotations.TokensAnnotation.class,
        CoreAnnotations.PositionAnnotation.class,
        CoreAnnotations.SentencesAnnotation.class
    )));
  }

View on GitHub (pinned to 1b7edd19c4)