stanfordnlp/CoreNLP · error · RuntimeException

ERROR: unknown dependency type

Error message

ERROR: unknown dependency type: ${dependencyType}

What it means

addDependencyPathFeatures selects a SemanticGraph annotation based on the configured dependencyType. The if/else-if chain only handles SEMANTIC (untyped/collapsed-ccprocessed), COLLAPSED, and BASIC; any other DEPENDENCY_TYPE value hits the else and throws RuntimeException. It is an internal enum-coverage failure, not user input directly.

Solutions

  1. Use one of the supported types: SEMANTIC (CollapsedCCProcessed), COLLAPSED, or BASIC.
  2. Extend the if/else chain in addDependencyPathFeatures to handle any new DEPENDENCY_TYPE constant you added.
  3. Replace the enum's unhandled values with a switch that throws at compile-checkable points or defaults to CollapsedCCProcessed.
  4. Validate dependencyType early (constructor/init) so failures surface before per-sentence feature extraction.

Example fix

// before
else
  throw new RuntimeException("ERROR: unknown dependency type: " + dependencyType);
// after
else if(dependencyType == DEPENDENCY_TYPE.ENHANCED)
  graph = rel.getSentence().get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
else
  throw new RuntimeException("ERROR: unknown dependency type: " + dependencyType);
Defensive patterns

Strategy: validation

Validate before calling

if (dependencyType != DEPENDENCY_TYPE.SEMANTIC
    && dependencyType != DEPENDENCY_TYPE.COLLAPSED
    && dependencyType != DEPENDENCY_TYPE.BASIC) {
  throw new IllegalArgumentException("Unsupported dependencyType: " + dependencyType);
}

Try / catch

try {
  addDependencyPathFeatures(rel, sent, depType, features, domain);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().contains("unknown dependency type")) {
    log.warning("Falling back to COLLAPSED dependency type");
    addDependencyPathFeatures(rel, sent, DEPENDENCY_TYPE.COLLAPSED, features, domain);
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking addFeatures with a feature set that includes dependency-path features and a DEPENDENCY_TYPE constant outside the three supported values (e.g. a newly added enum constant or an uninitialized/custom value).

Common situations: Extending DEPENDENCY_TYPE with new constants (e.g. ENHANCED) without updating this method; reflection/config code assigning an out-of-range value; merging code from different CoreNLP versions with divergent enums.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ie/machinereading/BasicRelationFeatureFactory.java:597

  protected void addDependencyPathFeatures(
          Counter<String> features,
          RelationMention rel,
          EntityMention arg0,
          EntityMention arg1,
          List<String> types,
          List<String> checklist,
          Logger logger) {
    SemanticGraph graph = null;
    if(dependencyType == null) dependencyType = DEPENDENCY_TYPE.COLLAPSED_CCPROCESSED; // needed for backwards compatibility. old serialized models don't have it
    if(dependencyType == DEPENDENCY_TYPE.COLLAPSED_CCPROCESSED)
      graph = rel.getSentence().get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);
    else if(dependencyType == DEPENDENCY_TYPE.COLLAPSED)
      graph = rel.getSentence().get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
    else if(dependencyType == DEPENDENCY_TYPE.BASIC)
      graph = rel.getSentence().get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
    else
      throw new RuntimeException("ERROR: unknown dependency type: " + dependencyType);

    if (graph == null) {
      Tree tree = rel.getSentence().get(TreeAnnotation.class);
      if(tree == null){
        log.info("WARNING: found sentence without TreeAnnotation. Skipped dependency-path features.");
        return;
      }
      try {
        graph = SemanticGraphFactory.makeFromTree(tree, Mode.COLLAPSED, GrammaticalStructure.Extras.NONE, null, true);

      } catch(Exception e){
        log.info("WARNING: failed to generate dependencies from tree " + tree.toString());
        e.printStackTrace();
        log.info("Skipped dependency-path features.");
        return;
      }
    }

View on GitHub (pinned to 1b7edd19c4)