stanfordnlp/CoreNLP · error · RuntimeException

ERROR: typed SINGLETON feature.

Error message

ERROR: typed SINGLETON feature.

What it means

When parsing a typed morphological feature line, a SINGLETON entry hits a case the code does not handle: single-character features cannot be typed as prefix/suffix, so getFeatures throws a RuntimeException. It indicates malformed or unsupported content in the .gb feature file.

Solutions

  1. Remove or fix the SINGLETON entry in the typed feature section of the .gb file
  2. Declare singleton features in the single-feature section (matched by singleFeatPattern), not as typed features
  3. Verify the feature file matches the format expected by this library version

Example fix

// before (in .gb typed section)
S:好
// after: move singleton chars to the untyped/single feature list
好
Defensive patterns

Strategy: validation

Validate before calling

// pre-validate .gb lines: no typed line may declare a SINGLETON feature
for (String line : Files.readAllLines(gbFile.toPath(), StandardCharsets.UTF_8)) {
  if (line.matches("^[PS]:.") ) throw new IllegalStateException("Typed SINGLETON-like line in " + gbFile);
}

Try / catch

try { fs = new ChineseMorphFeatureSets(dir); }
catch (RuntimeException e) { if (e.getMessage().contains("SINGLETON")) { log.error("Malformed .gb file at line-level: fix typed SINGLETON entry"); } throw e; }

Prevention

When it happens

Trigger: A feature file line parsed as a typed feature whose FeatType resolves to SINGLETON, i.e. a typed line declaring a singleton feature in the .gb morphological feature data.

Common situations: Hand-edited or corrupted .gb feature files; feature files from a different format version being fed to this loader; mixing typed and singleton feature declarations incorrectly.

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

Appendix: source

Thrown at src/edu/stanford/nlp/ie/ChineseMorphFeatureSets.java:114

      }

      Matcher typedSingleFeatMatcher = typedSingleFeatPattern.matcher(line);
      if (typedSingleFeatMatcher.matches()) {
        String featName = typedSingleFeatMatcher.group(1);
        featIndex.add(featName);
        String featIndexString = Integer.toString(featIndex.indexOf(featName));
        String charString = typedSingleFeatMatcher.group(2);
        switch (featType) {
          case PREFIX:
            addTypedFeature(featIndexString, charString.charAt(0), true);
            break;

          case SUFFIX:
            addTypedFeature(featIndexString, charString.charAt(0), false);
            break;

          case SINGLETON:
            throw new RuntimeException("ERROR: typed SINGLETON feature.");
        }
        continue;
      }

      Matcher singleFeatMatcher = singleFeatPattern.matcher(line);
      if (singleFeatMatcher.matches()) {
        String charString = singleFeatMatcher.group();
        featureSet.add(charString.charAt(0));
        continue;
      }

      if (line.startsWith("prefix") || line.startsWith("suffix")) {
        if (featureSet.size() > 0) {
          Pair<Set<Character>, Set<Character>> p = affixFeatures.get(singleFeatIndexString);
          if (p == null) {
            affixFeatures.put(singleFeatIndexString, p = new Pair<>());
          }
          if (featType == FeatType.PREFIX) {

View on GitHub (pinned to 1b7edd19c4)