stanfordnlp/CoreNLP · error · NumberFormatException
Bad number put into wordToNumber. Word is: \"" + curPart +…
Error message
Bad number put into wordToNumber. Word is: \"" + curPart + "\", originally part of \"" + originalString + "\", piece # " + curIndex
What it means
wordToNumber treats pieces ending in 'ths'/'rds' (mid-string) as fractions by stripping the final 's' and looking up ordWord2NumMap; if the lookup misses it throws NumberFormatException naming the piece, original string, and piece index. This is the fractional-word guard inside the multi-piece branch.
Solutions
- Rewrite the fraction into numeric form ('three fourths' -> '0.75') before normalization.
- Catch NumberFormatException and leave the token unnormalized.
- Verify the ordinal spelling is supported by ordWord2NumMap (fourths, thirds, halves, etc.).
Example fix
// before
Number n = NumberNormalizer.wordToNumber("sevens ths");
// after
Number n = NumberNormalizer.wordToNumber("0.75"); // pre-normalized fraction Defensive patterns
Strategy: try-catch
Validate before calling
static boolean isKnownFractionWord(String part) {
return part.matches("(half|halves|third|thirds|fourth|fourths|fifth|fifths|...)s?");
} Try / catch
try {
Number n = NumberNormalizer.wordToNumber(input);
} catch (NumberFormatException e) {
Number n = null; // unsupported fraction word; skip
} Prevention
- Use only fraction spellings present in the ordinal word map.
- Pre-convert unusual fractions to decimal form.
- Catch NumberFormatException and leave tokens unnormalized.
When it happens
Trigger: A mid-string piece ending in 'ths' or 'rds' whose base form is not in the ordinal map, e.g. 'sixteenths' combined with other pieces, or misspelled ordinals like 'oneths'.
Common situations: Tokenizing unusual numeric phrases ('thirds half'), ordinal forms not present in the built-in word map (rare fractions like 'fifths' in some versions), or text with typos.
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
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
- ERROR: Invalid line " + lineCount + " in regexner file " +…
- Doesn't do k best yet
- Doesn't do best parses yet
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/fa06d58b18b3b00a.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/NumberNormalizer.java:374
Matcher m = alphaPattern.matcher(curPart);
if (m.find()) {
// Some part of the word has alpha characters
Number curNum;
if (word2NumMap.containsKey(curPart)) {
curNum = word2NumMap.get(curPart);
} else if (ordWord2NumMap.containsKey(curPart)) {
if (curIndex == numWords-1){
curNum = ordWord2NumMap.get(curPart);
} else {
throw new NumberFormatException("Error in wordToNumber function.");
}
} else if (curIndex > 0 && (curPart.endsWith("ths") || curPart.endsWith("rds"))) {
// Fractions?
curNum = ordWord2NumMap.get(curPart.substring(0, curPart.length()-1));
if (curNum != null) {
curNum = 1/curNum.doubleValue();
} else {
throw new NumberFormatException("Bad number put into wordToNumber. Word is: \"" + curPart + "\", originally part of \"" + originalString + "\", piece # " + curIndex);
}
} else if (Character.isDigit(curPart.charAt(0)) || curPart.charAt(0) == '.') {
if (curPart.endsWith("th") || curPart.endsWith("rd") || curPart.endsWith("nd") || curPart.endsWith("st")) {
curPart = curPart.substring(0, curPart.length()-2).trim();
}
curNum = parseNumberPart(curPart, originalString, curIndex);
} else {
throw new NumberFormatException("Bad number put into wordToNumber. Word is: \"" + curPart + "\", originally part of \"" + originalString + "\", piece # " + curIndex);
}
numFields[curIndex] = curNum;
} else {
// Word is all numeric
Matcher matcher = digitsPatternExtended.matcher(curPart);
if (matcher.matches()) {
numFields[curIndex] = parseNumberPart(curPart, originalString, curIndex);
} else if (numPattern.matcher(curPart).matches()) {
numFields[curIndex] = new BigDecimal(curPart);
} else {View on GitHub (pinned to 1b7edd19c4)