Class SymSpellModelResolver
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
FieldsModifier and TypeFieldDescriptionstatic final StringDefaultmodel.namefragment used to recognize spellcheck models. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a resolver that scans the defaultopennlp-models-*.jarprefix using aSimpleClassPathModelFinderand 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 TypeMethodDescriptionresolveByLanguage(String language) Resolves a spellcheck model for the given language from the current classpath.resolveByLanguage(String language, boolean reloadCache) Resolves a spellcheck model for the given language from the current classpath.
-
Field Details
-
DEFAULT_NAME_FRAGMENT
Defaultmodel.namefragment used to recognize spellcheck models.- See Also:
-
-
Constructor Details
-
SymSpellModelResolver
public SymSpellModelResolver()Creates a resolver that scans the defaultopennlp-models-*.jarprefix using aSimpleClassPathModelFinderand 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 benullloader- the classpath model loader; must not benullnameFragment- a substring that the candidate'smodel.namemust contain to be considered a spellcheck model; must not benullor blank
-
-
Method Details
-
resolveByLanguage
Resolves a spellcheck model for the given language from the current classpath.- Parameters:
language- the language tag to match againstmodel.language; must not benullor 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 againstmodel.language; must not benullor blankreloadCache-trueto 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.
-