Package opennlp.spellcheck.dictionary

# Class SymSpellModelResolver

java.lang.Object
opennlp.spellcheck.dictionary.SymSpellModelResolver

public final class SymSpellModelResolver extends Object
Resolves packaged `SymSpell models` from the classpath by language.

Production multi-language dictionaries are shipped as separate `opennlp-models-spellcheck-{lang}` jars (not bundled in this module). Each such jar contains a binary `*.bin` model written by `SymSpellModelSerializer` and a matching `model.properties` carrying `model.language`, `model.name`, `model.version` and `model.sha256`.

This resolver reuses the standard OpenNLP model-resolver scanning machinery (`ClassPathModelFinder` + `ClassPathModelLoader`) to discover those jars, selects the entry whose `model.language` matches the requested language (and whose `model.name` identifies a spellcheck model), and deserializes its bytes into a `SymSpellModel`.

The `SymSpellModel` is not an OpenNLP `BaseModel`, so the typed `ClassPathModelProvider.load(...)` path does not apply; this resolver instead consumes the raw `ClassPathModel` (`properties + bytes`) directly.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `DEFAULT_NAME_FRAGMENT`
  Default `model.name` fragment used to recognize spellcheck models.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SymSpellModelResolver()`
  Creates a resolver that scans the default `opennlp-models-*.jar` prefix using a `SimpleClassPathModelFinder` and recognizes spellcheck models by the default name fragment.
  `SymSpellModelResolver(opennlp.tools.models.ClassPathModelFinder finder, opennlp.tools.models.ClassPathModelLoader loader, String nameFragment)`
  Creates a resolver with explicit collaborators.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Optional<SymSpellModel>`
  `resolveByLanguage(String language)`
  Resolves a spellcheck model for the given language from the current classpath.
  `Optional<SymSpellModel>`
  `resolveByLanguage(String language, boolean reloadCache)`
  Resolves a spellcheck model for the given language from the current classpath.

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DEFAULT_NAME_FRAGMENT

    public static final String DEFAULT_NAME_FRAGMENT
    Default `model.name` fragment used to recognize spellcheck models.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### SymSpellModelResolver

    public SymSpellModelResolver()
    Creates a resolver that scans the default `opennlp-models-*.jar` prefix using a `SimpleClassPathModelFinder` and recognizes spellcheck models by the default name fragment.

  - ### SymSpellModelResolver

    public SymSpellModelResolver(opennlp.tools.models.ClassPathModelFinder finder, opennlp.tools.models.ClassPathModelLoader loader, String nameFragment)
    Creates a resolver with explicit collaborators.
    Parameters:
      `finder` - the classpath model finder; must not be `null`
      `loader` - the classpath model loader; must not be `null`
      `nameFragment` - a substring that the candidate's `model.name` must contain to be considered a spellcheck model; must not be `null` or blank

- ## Method Details

  - ### resolveByLanguage

    public Optional<SymSpellModel> resolveByLanguage(String language) throws IOException
    Resolves a spellcheck model for the given language from the current classpath.
    Parameters:
      `language` - the language tag to match against `model.language`; must not be `null` or blank
    Returns:
      the resolved model, or `Optional.empty()` if no matching model jar is present on the classpath
    Throws:
      `IOException` - Thrown on IO errors while reading classpath resources or on a malformed model stream.

  - ### resolveByLanguage

    public Optional<SymSpellModel> resolveByLanguage(String language, boolean reloadCache) throws IOException
    Resolves a spellcheck model for the given language from the current classpath.
    Parameters:
      `language` - the language tag to match against `model.language`; must not be `null` or blank
      `reloadCache` - `true` to force the finder to rescan the classpath
    Returns:
      the resolved model, or `Optional.empty()` if no matching model jar is present on the classpath
    Throws:
      `IOException` - Thrown on IO errors while reading classpath resources or on a malformed model stream.