stanfordnlp/CoreNLP · error · RuntimeException
Invalid morphology string:
Error message
Invalid morphology string:
What it means
MorphoFeatureSpecification.splitMorphString expects a morphological string of the form 'lemma^featureString' (split on the LEMMA_MARK separator '^'). It throws a RuntimeException when the string is non-empty but does not split into exactly two parts, i.e. the separator is missing or appears more than once.
Solutions
- Ensure each morph string uses the '^' separator exactly once: 'lemma^features'
- Fix malformed entries in the morpho input file
- Pre-validate lines before calling splitMorphString
- Check which LEMMA_MARK constant the loaded specification uses and match it in your data
Example fix
// before splitMorphString(word, "courir VER:pres"); // after splitMorphString(word, "courir^VER:pres");
Defensive patterns
Strategy: validation
Validate before calling
if (morphStr != null && !morphStr.trim().isEmpty() && morphStr.split("\\^").length != 2) throw new IllegalArgumentException("Expected 'lemma^features': " + morphStr); Type guard
boolean isValidMorphString(String s) { return s == null || s.trim().isEmpty() || s.split("\\^").length == 2; } Try / catch
try { pair = MorphoFeatureSpecification.splitMorphString(word, morphStr); } catch (RuntimeException e) { log.warn("Bad morph string, using NO_ANALYSIS: " + morphStr); pair = new Pair<>(word, MorphoFeatureSpecification.NO_ANALYSIS); } Prevention
- Always emit morph entries as 'lemma^features' with exactly one '^'
- Pre-validate morpho files during corpus preparation
- Fall back to NO_ANALYSIS for recoverable malformed entries
When it happens
Trigger: Calling splitMorphString (directly or via addMorphologicalFeatures processing) with a morph string lacking the '^' separator, containing multiple '^', or being whitespace-with-content other than expected.
Common situations: Misformatted morphological analysis files where lemma and features are separated by a different character; hand-edited entries; preprocessed files that stripped the '^' character.
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
- Dependencies should be for the format 'type(arg-idx…
- Expected left paren!
- Expected right paren!
- invalid format: ||
- Tag did not end with >
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/cf3f375953c7d455.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/international/morph/MorphoFeatureSpecification.java:63
activeFeatures.add(feat);
}
public boolean isActive(MorphoFeatureType feat) { return activeFeatures.contains(feat); }
public abstract List<String> getValues(MorphoFeatureType feat);
public abstract MorphoFeatures strToFeatures(String spec);
/**
* Returns the lemma as pair.first() and the morph analysis as pair.second().
*/
public static Pair<String,String> splitMorphString(String word, String morphStr) {
if (morphStr == null || morphStr.trim().equals("")) {
return new Pair<>(word, NO_ANALYSIS);
}
String[] toks = morphStr.split(Pattern.quote(LEMMA_MARK));
if (toks.length != 2) {
throw new RuntimeException("Invalid morphology string: " + morphStr);
}
return new Pair<>(toks[0], toks[1]);
}
@Override
public String toString() { return activeFeatures.toString(); }
}
View on GitHub (pinned to 1b7edd19c4)