stanfordnlp/CoreNLP · error · UnsupportedOperationException

No GrammaticalStructureFactory (typed dependencies)…

Error message

No GrammaticalStructureFactory (typed dependencies) available for language/treebank 

What it means

AbstractTreebankLanguagePack.grammaticalStructureFactory() is a stub that must be overridden by concrete language packs that support typed dependencies. The base implementation always throws UnsupportedOperationException, telling the caller this language/treebank has no GrammaticalStructureFactory — i.e. it cannot produce GrammaticalStructures (typed dependency graphs).

Solutions

  1. Use a language pack that supports dependencies (e.g. EnglishTreebankLanguagePack, UniversalEnglishTreebankLanguagePack) for the pipeline.
  2. If you own the subclass, implement grammaticalStructureFactory() returning the appropriate GrammaticalStructureFactory.
  3. Skip typed-dependency generation for this treebank or configure the pipeline to not request SemanticGraphs.

Example fix

// before
class MyTreebankLanguagePack extends AbstractTreebankLanguagePack { }
// after
@Override
public GrammaticalStructureFactory grammaticalStructureFactory() {
  return new MyGrammaticalStructureFactory(MyGrammaticalStructure::new);
}
Defensive patterns

Strategy: try-catch

Validate before calling

GrammaticalStructureFactory gsf = null; try { gsf = tlp.grammaticalStructureFactory(); } catch (UnsupportedOperationException e) { /* no dep support */ }

Type guard

boolean supportsDeps(TreebankLanguagePack tlp) { try { tlp.grammaticalStructureFactory(); return true; } catch (UnsupportedOperationException e) { return false; } }

Try / catch

try { gsf = tlp.grammaticalStructureFactory(); } catch (UnsupportedOperationException e) { log.warn("No typed dependencies for {}", tlp.getClass()); gsf = null; }

Prevention

When it happens

Trigger: Calling tlp.grammaticalStructureFactory() (directly or via SemanticGraphFactory / parsing pipelines that request typed dependencies) on a TreebankLanguagePack subclass that does not override the method, e.g. a generic or custom language pack.

Common situations: Building a SemanticGraph from trees parsed with a custom/minimal language pack; running dependency conversion on a treebank whose pack lacks dependency support; copying a language pack stub without implementing the factory.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/trees/AbstractTreebankLanguagePack.java:604

   * will be used with this Treebank/Language pair, without tokenizing carriage returns (i.e., treating them as white space).  The implementation in AbstractTreebankLanguagePack
   * returns a factory for {@link WhitespaceTokenizer}.
   *
   * @return A tokenizer
   */
  @Override
  public TokenizerFactory<? extends HasWord> getTokenizerFactory() {
    return WhitespaceTokenizer.factory(false);
  }

  /**
   * Return a GrammaticalStructureFactory suitable for this language/treebank.
   * (To be overridden in subclasses.)
   *
   * @return A GrammaticalStructureFactory suitable for this language/treebank
   */
  @Override
  public GrammaticalStructureFactory grammaticalStructureFactory() {
    throw new UnsupportedOperationException(
            "No GrammaticalStructureFactory (typed dependencies) available for language/treebank " +
                    getClass().getName());
  }

  /**
   * Return a GrammaticalStructureFactory suitable for this language/treebank.
   * (To be overridden in subclasses.)
   *
   * @return A GrammaticalStructureFactory suitable for this language/treebank
   */
  @Override
  public GrammaticalStructureFactory grammaticalStructureFactory(Predicate<String> puncFilt) {
    return grammaticalStructureFactory();
  }

  /**
   * Return a GrammaticalStructureFactory suitable for this language/treebank.
   * (To be overridden in subclasses.)

View on GitHub (pinned to 1b7edd19c4)