stanfordnlp/CoreNLP · error · RuntimeException

Can't handle this type of GeneralDataset.

Error message

Can't handle this type of GeneralDataset.

What it means

RuntimeException from GeneralDataset.sampleDataset when the dataset is neither an RVFDataset nor a Dataset. Sampling only knows how to instantiate those two concrete types, so custom GeneralDataset subclasses are rejected.

Solutions

  1. Sample from a Dataset or RVFDataset instead of a custom subclass
  2. Override or extend sampleDataset for custom GeneralDataset types
  3. Convert the dataset to a supported type before sampling
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/edu/stanford/nlp/classify/GeneralDataset.java:411 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/edu/stanford/nlp/classify/GeneralDataset.java:411

      labels[j] = tmpl;

      E tmpE = sideInformation.get(randIndex);
      sideInformation.set(randIndex, sideInformation.get(j));
      sideInformation.set(j, tmpE);
    }
  }

  public GeneralDataset<L,F> sampleDataset(long randomSeed, double sampleFrac, boolean sampleWithReplacement) {
    int sampleSize = (int)(this.size()*sampleFrac);
    Random rand = new Random(randomSeed);
    GeneralDataset<L,F> subset;
    if (this instanceof RVFDataset) {
      subset = new RVFDataset<>();
    } else if (this instanceof Dataset) {
      subset = new Dataset<>();
    }
    else {
      throw new RuntimeException("Can't handle this type of GeneralDataset.");
    }
    if (sampleWithReplacement) {
      for(int i = 0; i < sampleSize; i++){
        int datumNum = rand.nextInt(this.size());
        subset.add(this.getDatum(datumNum));
      }
    } else {
      Set<Integer> indicedSampled = Generics.newHashSet();
      while (subset.size() < sampleSize) {
        int datumNum = rand.nextInt(this.size());
        if (!indicedSampled.contains(datumNum)) {
          subset.add(this.getDatum(datumNum));
          indicedSampled.add(datumNum);
        }
      }
    }
    return subset;
  }

View on GitHub (pinned to 1b7edd19c4)