Class HunspellDictionary
.aff and .dic files. OpenNLP includes no dictionary data.
Supported affix features are PFX and SFX rules with strip
strings, character-class conditions, cross-product combinations, and continuation
classes. COMPLEXPREFIXES selects 2 prefixes and 1 suffix instead of
1 prefix and 2 suffixes. FLAG, AF, AM, and SET
declarations apply throughout the file. Input and output conversions, ignored
characters, case restrictions, compound flags and patterns, and word breaks are
applied during stemming. The blocking flags
NEEDAFFIX (also named PSEUDOROOT), ONLYINCOMPOUND, and
FORBIDDENWORD, plus CIRCUMFIX and FULLSTRIP, are also
applied.
Loading defaults to HunspellDictionary.LoadMode.STRICT: unsupported affix directives
cause an IOException. Recognized metadata and suggestion settings that
do not affect stemming are ignored. HunspellDictionary.LoadMode.ALLOW_PARTIAL skips other
directives and reports them through getUnsupportedDirectives().
Morphological stems use st:, sp:, and ds: fields.
SYLLABLENUM supports Hungarian compound syllable adjustments.
LEMMA_PRESENT is accepted and has no effect. Strict loading validates
declarations; it does not establish that every result matches Hunspell.
Instances are immutable and safe to share between threads.
- Since:
- 3.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumControls whether unsupported affix directives prevent dictionary loading.static final recordThe first occurrence of an unsupported affix directive. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe file suffix for a Hunspell affix file.static final StringThe file suffix for a Hunspell word-list file.static final intInclusive upper bound on bytes buffered from one affix or dictionary stream duringload(InputStream, InputStream). -
Method Summary
Modifier and TypeMethodDescriptionReturns skipped unsupported directives, one entry per name in encounter order.static HunspellDictionaryload(InputStream affixStream, InputStream dictionaryStream) Loads affix and dictionary streams usingHunspellDictionary.LoadMode.STRICT.static HunspellDictionaryload(InputStream affixStream, InputStream dictionaryStream, HunspellDictionary.LoadMode mode) Loads affix and dictionary streams with the selected directive policy.static HunspellDictionaryLoads affix and dictionary files usingHunspellDictionary.LoadMode.STRICT.static HunspellDictionaryload(Path affixFile, Path dictionaryFile, HunspellDictionary.LoadMode mode) Loads affix and dictionary files with the selected directive policy.
-
Field Details
-
AFFIX_FILE_SUFFIX
-
DICTIONARY_FILE_SUFFIX
The file suffix for a Hunspell word-list file.- See Also:
-
MAX_STREAM_BYTES
public static final int MAX_STREAM_BYTESInclusive upper bound on bytes buffered from one affix or dictionary stream duringload(InputStream, InputStream). The limit is 64 MiB. Larger streams fail withIOException.- See Also:
-
-
Method Details
-
load
Loads affix and dictionary files usingHunspellDictionary.LoadMode.STRICT.- Parameters:
affixFile- The.affaffix file. Must not benull.dictionaryFile- The.dicword list. Must not benull.- Returns:
- The loaded dictionary. Never
null. - Throws:
IOException- Thrown if reading fails, a file is malformed, or an affix directive is unsupported.IllegalArgumentException- Thrown if a parameter isnull.
-
load
public static HunspellDictionary load(Path affixFile, Path dictionaryFile, HunspellDictionary.LoadMode mode) throws IOException Loads affix and dictionary files with the selected directive policy.- Parameters:
affixFile- The.affaffix file. Must not benull.dictionaryFile- The.dicword list. Must not benull.mode- The loading policy. Must not benull.- Returns:
- The loaded dictionary. Never
null. - Throws:
IOException- Thrown if reading fails, a file exceedsMAX_STREAM_BYTES, a file is malformed, orHunspellDictionary.LoadMode.STRICTencounters an unsupported affix directive.IllegalArgumentException- Thrown if a parameter isnull.
-
load
public static HunspellDictionary load(InputStream affixStream, InputStream dictionaryStream) throws IOException Loads affix and dictionary streams usingHunspellDictionary.LoadMode.STRICT. Each stream is buffered up toMAX_STREAM_BYTESbytes; a larger stream fails withIOException.- Parameters:
affixStream- The.affaffix content. Must not benull. Not closed.dictionaryStream- The.dicword list content. Must not benull. Not closed.- Returns:
- The loaded dictionary. Never
null. - Throws:
IOException- Thrown if reading fails, a stream exceedsMAX_STREAM_BYTES, the content is malformed, or an affix directive is unsupported.IllegalArgumentException- Thrown if a parameter isnull.
-
load
public static HunspellDictionary load(InputStream affixStream, InputStream dictionaryStream, HunspellDictionary.LoadMode mode) throws IOException Loads affix and dictionary streams with the selected directive policy. Each stream is buffered up toMAX_STREAM_BYTESbytes.- Parameters:
affixStream- The.affaffix content. Must not benull. Not closed.dictionaryStream- The.dicword list content. Must not benull. Not closed.mode- The loading policy. Must not benull.- Returns:
- The loaded dictionary. Never
null. UnderHunspellDictionary.LoadMode.ALLOW_PARTIALit reports skipped directives throughgetUnsupportedDirectives(). - Throws:
IOException- Thrown if reading fails, a stream exceedsMAX_STREAM_BYTES, the content is malformed, orHunspellDictionary.LoadMode.STRICTencounters an unsupported affix directive.IllegalArgumentException- Thrown if a parameter isnull.
-
getUnsupportedDirectives
Returns skipped unsupported directives, one entry per name in encounter order. Recognized settings outside stemming, such as suggestion tables, are excluded.- Returns:
- An immutable list; empty for a dictionary loaded in strict mode.
-