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 TypeClassDescription(package private) static final recordOne parsed affix rule of aPFXorSFXblock.private static final classThe parsed affix file content.private static final classAn immutable index of affix rules keyed by the boundary code point of their affix material, answering each lookup by binary search so the per-word scans inHunspellStemmerallocate nothing.(package private) static enumThe capitalization classes of a word.(package private) static final recordA compound-boundary restriction and optional spelling replacement.(package private) static enumThe place a part takes in a compound, deciding which positional flag admits it.private static enumThe flag encodings a dictionary may declare with theFLAGdirective.static enumControls whether unsupported affix directives prevent dictionary loading.static final recordThe first occurrence of an unsupported affix directive.(package private) static final recordOneBREAKdeclaration: a separator and the anchors that bind it to the start or end of the word. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe file suffix for a Hunspell affix file.private static final Stringprivate static final StringThe directive that defines the file-wide flag alias table.(package private) static final StringTheBREAKanchor that binds a separator to the end of the word.(package private) static final StringTheBREAKanchor that binds a separator to the start of the word.private static final Stringprivate static final Stringprivate static final Stringprivate final booleanprivate final booleanprivate final booleanprivate final booleanprivate final booleanprivate final intprivate static final StringPrefix used by comment lines.private static final Stringprivate final booleanprivate static final String(package private) static final StringField prefix of a compound part in an analysis.private static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate final intprivate final intprivate final intprivate final intprivate final intprivate final intprivate final booleanprivate final List<HunspellDictionary.CompoundPattern> private final intprivate final intprivate final List<HunspellCompoundRule> private final Stringprivate final intprivate static final List<HunspellDictionary.WordBreak> The separators used when the affix file declares noBREAKtable: a hyphen inside the word, at its start, and at its end.private static final Stringstatic final StringThe file suffix for a Hunspell word-list file.private static final String(package private) static final StringThe dotted capital I, the uppercase ofiin the Turkic languages.(package private) static final StringThe uppercase double s that an all-uppercase sharp s entry is written with.(package private) static final StringThe lowercase double s that a sharp s expands to.private static final Stringprivate static final StringThe directive that selects the file-wide flag representation.private static final Stringprivate final intprivate final booleanprivate static final Stringprivate final intprivate final booleanThe capitalized forms of mixed-case and flagged all-uppercase entries, kept as hidden homonyms so that all-uppercase input matches them.private final booleanprivate static final int[]The flags Hungarian dictionaries reserve for the hyphen rule: an entry carrying one of them may open a compound written before a hyphen.private static final Stringprivate final Stringprivate static final Stringprivate final HunspellConversionprivate static final Stringprivate final intprivate static final Stringprivate static final Stringprivate final intprivate static final intLargestCOMPOUNDMINvalue that can be doubled without overflow.private static final intLargest flag value permitted byFLAG num: the full unsigned 16-bit range.static final intInclusive upper bound on bytes buffered from one affix or dictionary stream duringload(InputStream, InputStream).private final intprivate static final Stringprivate final intprivate static final List<HunspellDictionary.Affix> The shared empty bucket answered for characters no affix rule is keyed under.(package private) static final StringThe affix format's marker for absent strip or affix material.private final intprivate static final Stringprivate final HunspellConversion(package private) static final StringThe word-list field that lists a misspelling of its entry.private static final StringThe line tag of a prefix block and of every rule line inside it.private final HunspellDictionary.BoundaryIndexprivate final List<HunspellDictionary.Affix> (package private) static final StringThe suggestion table whose replacementsCHECKCOMPOUNDREPapplies to compounds.private final HunspellConversionprivate static final StringTheSETdirective followed by a space.private static final StringTheSETdirective followed by a tab.private static final StringThe affix-file directive that declares the character encoding.(package private) static final StringThe sharp s, whichCHECKSHARPSrelates to a double s.private static final Stringprivate final booleanprivate static final Stringprivate static final StringThe line tag of a suffix block and of every rule line inside it.private final HunspellDictionary.BoundaryIndexprivate final List<HunspellDictionary.Affix> private static final Stringprivate static final Stringprivate final booleanprivate final booleanprivate final List<HunspellDictionary.UnsupportedDirective> private static final Stringprivate final intprivate final List<HunspellDictionary.WordBreak> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateHunspellDictionary(Map<String, List<int[]>> entries, HunspellDictionary.AffixFile affix, List<HunspellDictionary.UnsupportedDirective> unsupportedDirectives) Initializes the dictionary from the two parsed files. -
Method Summary
Modifier and TypeMethodDescription(package private) booleanacceptsCase(int[] flags, String surface, String variant, HunspellDictionary.Affix... affixes) Checks case-sensitive and warning restrictions for a selected entry.(package private) booleanacceptsRulePart(int[] flags, boolean last, HunspellDictionary.Affix... affixes) Checks blocking flags on a compound-rule part.(package private) booleanaffixAdmits(HunspellDictionary.Affix affix, HunspellDictionary.CompoundPosition position) Checks whether an affix admits its derived form at a compound position: its continuation classes carry the general compounding flag or the position's dedicated flag.private static StringasciiField(byte[] bytes, int from, int to) Extracts one ASCII field.private static HunspellDictionary.BoundaryIndexbucketByBoundary(List<HunspellDictionary.Affix> rules, boolean suffix, List<HunspellDictionary.Affix> withoutMaterial) Buckets affix rules by the boundary code point of their affix material, the last code point for a suffix rule and the first for a prefix rule.private static intbyteOrderMarkLength(byte[] bytes) Measures a leading UTF-8 byte order mark, which the byte-level scans skip so that the first line's directive is read without it.(package private) static HunspellDictionary.CaseTypeClassifies a word's capitalization, judging the initial by the first character.(package private) booleanReturns whetherCHECKCOMPOUNDCASEforbids uppercase at part boundaries.(package private) booleanReturns whetherCHECKCOMPOUNDDUPforbids a part repeating its neighbor.(package private) booleanReturns whetherCHECKCOMPOUNDTRIPLEforbids triple letters at boundaries.(package private) booleanReturns whether uppercase SS may represent a German sharp s.(package private) booleanChecks whether an affix is one half of a circumfix: it carries theCIRCUMFIXflag among its continuation classes, so it is only valid on a word that also carries a circumfix-marked affix of the other kind, the Germange...tparticiple being the model.(package private) booleanReturns whether prefix continuation allows an additional prefix level.(package private) booleancompoundCaseAllowed(int[] flags, String word) Checks a closing entry's capitalization requirement.(package private) intReturns the smallest length a compound part may have.(package private) booleanReturns whether compounds permit an additional suffix level.(package private) booleanChecks whether an affix applies only inside compounds: it carries theONLYINCOMPOUNDflag among its continuation classes.(package private) List<HunspellDictionary.CompoundPattern> Returns the compound-boundary patterns.(package private) List<HunspellCompoundRule> Returns the parsed independent compound flag patterns.(package private) booleanReturns whether the affix file declares any compounding flag at all.(package private) booleancompoundSizeAllowed(int syllables, int units) Checks word and syllable limits on a completed compound.(package private) intcompoundSyllables(String part, int[] flags, List<HunspellDictionary.Affix> affixes, boolean last) Calculates a component's contribution to the compound syllable limit.(package private) intcompoundUnits(int[] flags, List<HunspellDictionary.Affix> affixes) Counts an entry toward COMPOUNDWORDMAX.(package private) intReturns the largest number of parts a compound may have.(package private) static booleancontains(int[] flags, int flag) Checks one flag set for a flag.private intcountSyllables(String text) Counts code points listed by COMPOUNDSYLLABLE.private static CharsetdeclaredCharset(byte[] affixBytes) Finds theSETdeclaration by scanning the raw affix bytes as ASCII, which is safe because the declaration itself is ASCII in every supported encoding.private static StringConverts file content without replacing malformed or unmappable input.private StringfieldValue(List<String> fields, String tag, String fallback) Finds a morphological field value.private static intfindAsciiFields(byte[] bytes, int from, int to, int[] starts, int[] fieldEnds) Finds the fields needed to classify one raw line.private static intfirstCommentField(byte[] bytes, List<int[]> fields, String directive) Finds the first field index a trailing comment may occupy.(package private) booleanfirstForbidden(List<int[]> flagSets) Checks whether a spelling is forbidden as a whole.private booleanforbiddenAtCompoundPosition(int[] flags, HunspellDictionary.CompoundPosition position) Checks whether an entry marked withCOMPOUNDFORBIDFLAGis barred from this compound position.(package private) booleanforbidsAffixed(int[] flags, int flag) Checks whether one homonym carries both an affix flag and the forbidden flag.(package private) booleanforbidsAffixed(List<int[]> flagSets, int flag) Checks whether an affix analysis reaches a forbidden entry, which forbids the affixed spelling and thereby its compound and break readings.(package private) booleanforbidsCompoundStart(List<int[]> flagSets) Checks whether a spelling may not open a compound part sequence: its first listed homonym carriesCOMPOUNDFORBIDFLAG, which applies to every part but the last and overrides affixed readings of the same spelling.(package private) booleanChecks whether an affix bars its derived form from compounds altogether: it carries theCOMPOUNDFORBIDFLAGamong its continuation classes.(package private) booleanReturns whetherFULLSTRIPallows an affix rule to strip a whole stem.Returns skipped unsupported directives, one entry per name in encounter order.private static booleanhasAffixDirective(byte[] bytes, String directive) Finds a directive before metadata is removed or decoded.private booleanChecks for a morphological field.(package private) static booleanChecks whether any of a word's flag sets carries a flag.hiddenCapitalizedEntries(Map<String, List<int[]>> listed) Derives the hidden capitalized forms of mixed-case entries and of all-uppercase entries carrying flags, so that all-uppercase input such asEBOOKSforeBookorACME'SforACMEmatches them.private List<int[]> The flag sets of a root's entries, listed or hidden capitalized.(package private) booleanReturns whether the Hungarian moving rule applies.immutableFlagSets(Map<String, List<int[]>> flagSets) Replaces every flag-set list with an immutable copy so that lookups can return the stored lists directly.(package private) StringApplies input conversion followed by ignored-character removal.private static booleanisAffixHeader(byte[] bytes, List<int[]> fields) Distinguishes an affix block header, which carries a cross-product marker and a rule count, from a rule line.private static booleanisAsciiFieldSpace(byte value) Tests an affix field separator.private static booleanChecks whether a line consists purely of decimal digits, which identifies the optional entry-count header of a word list.private static booleanisFieldSeparator(char c) Checks one character against the word-list format's field separators, space and tabulator.private static booleanisIgnoredAffixDirective(String directive) Identifies metadata, suggestion and command-line settings unused by stemming.private static booleanisParsedAffixDirective(String directive) Tests whether a directive is supported by the parser.private static booleanisSingleFlagDirective(String directive) Tests for a directive with one flag argument.(package private) booleanlicensesCrossProduct(int[] flags, HunspellDictionary.Affix prefix, HunspellDictionary.Affix suffix) Checks cross-product flags within a single entry.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.private static HunspellDictionaryloadStreams(InputStream affixStream, InputStream dictionaryStream, HunspellDictionary.LoadMode mode, String source) Loads validated streams without closing them.private static intlongestSpacedForm(Set<String> words, List<HunspellDictionary.Affix> prefixes, List<HunspellDictionary.Affix> suffixes) Bounds the length of a word containing a space that can have a reading.(package private) List<int[]> Looks up a word's flag sets among the listed entries.(package private) List<int[]> Looks up a word's flag sets, optionally including the hidden capitalized forms that all-uppercase input outside compounds may match.(package private) StringApplies the dictionary's lowercase mapping.(package private) StringlowerCaseInitial(String word) Converts the initial code point to lowercase with the dictionary's case mapping.private static List<HunspellDictionary.UnsupportedDirective> maskIgnoredAffixLines(byte[] bytes, HunspellDictionary.LoadMode mode, String source) Replaces comments and unused directive lines with ASCII spaces before strict decoding.private static voidmaskInlineComment(byte[] bytes, int from, int to, String directive) Replaces a trailing comment with spaces.(package private) booleanmayReadSpacedForm(int length) Tests whether a word containing a space can have a reading, so that the compound word-pair check can skip texts no reading can match.(package private) booleanmayStand(int[] flags, HunspellDictionary.CompoundPosition position) Checks whether one homonym may stand as a bare compound part at a position.(package private) booleanmayStand(List<int[]> flagSets, HunspellDictionary.CompoundPosition position) Checks whether a listed word may stand at a compound position: some homonym's flag set contains the general compound flag or the position's dedicated flag and is not forbidden.morphologicalAnalyses(String root, int[] flags, boolean compoundEnd, HunspellDictionary.Affix... affixes) Returns morphological fields for matching dictionary entries and applied rules: prefix fields, then entry fields, then suffix fields.private StringmorphologicalStem(String root, List<String> fields, HunspellDictionary.Affix... affixes) Applies morphological stem and affix fields to one dictionary entry.morphologicalStems(String root, int[] flags, HunspellDictionary.Affix... affixes) Returns a stem after applying entry and affix morphology.private static intmorphologyIndex(String line) Finds where the trailing morphological fields of a word-list entry begin, which terminates the word and its flag run.(package private) booleanChecks whether a form made with this affix alone is still a virtual stem: the affix carries theNEEDAFFIXflag among its continuation classes, so a further affix must join before the form is a word.private static byte[]normalizeDictionaryByteFlags(byte[] bytes) Converts raw flag bytes after the flag separator of each dictionary entry.private static byte[]normalizeUtf8ByteFlags(byte[] bytes, Charset charset) Converts raw one-byte flags in a UTF-8 affix file to equivalent Unicode code points before decoding.(package private) booleanopensHyphenatedCompound(int[] flags) Checks whether an entry may open a compound under the Hungarian moving rule.(package private) StringoutputForm(String stem) Applies output conversion to a recognized stem.private static HunspellDictionary.AffixFileparseAffix(String content) Parses the affix file: theFLAGdeclaration, theAFflag alias table, the compound and blocking flag declarations, and thePFXandSFXblocks.private static intparseAffixBlock(String[][] fieldsByLine, int index, String[] header, HunspellDictionary.AffixFile result) Parses onePFXorSFXblock: the header line naming the flag, the cross-product marker, and the rule count, followed by exactly that many rule lines.private static int[]parseAliasedFlags(String text, HunspellDictionary.FlagMode mode, List<int[]> aliases, int lineNumber) Resolves a numericAFalias or parses a direct flag run when no alias applies.private static intparseFlag(String text, HunspellDictionary.FlagMode mode, int lineNumber) Parses a field that must contain exactly one flag, such as the flag name in an affix block header.private static int[]parseFlags(String text, HunspellDictionary.FlagMode mode, int lineNumber) Parses a flag run according to the declared flag mode: single characters incharmode, character pairs packed into oneintinlongmode, and comma-separated decimal numbers innummode.parseMorphology(String[] fields, List<List<String>> aliases, int line) Expands an optional morphology alias.private static intparseValue(String[] fields, int lineNumber) Parses the integer value of a directive that carries exactly one.parseWordList(String content, HunspellDictionary.AffixFile affix) Parses the word list: an optional leading entry count, then one entry per line consisting of the word, an optional/flagsrun, and optional trailing morphological fields.(package private) booleanChecks whether an affix may sit at a compound-internal boundary: it carries theCOMPOUNDPERMITFLAGamong its continuation classes.(package private) booleanReturns whether positional or general compound flags are configured.private intThe flag admitting a part at a compound position, next to the general compounding flag.(package private) List<HunspellDictionary.Affix> prefixesStartingWith(int first) The prefix rules whose affix material starts with the given code point, which are the only material-bearing rules that can be undone from a word starting with it.(package private) List<HunspellDictionary.Affix> Returns the strip-only prefix rules, applicable to any word.(package private) static byte[]readBounded(InputStream in, int maxBytes, String label) Reads an input stream into a byte array, failing when more thanmaxBytesarrive.private static List<HunspellDictionary.CompoundPattern> readCompoundPatterns(String[][] lines, HunspellDictionary.FlagMode mode) Parses CHECKCOMPOUNDPATTERN restrictions and replacements.private static List<HunspellCompoundRule> readCompoundRules(String[][] lines, HunspellDictionary.FlagMode mode) Parses and validates the COMPOUNDRULE table.private static booleanreadCompoundSetting(String[] fields, int line, HunspellDictionary.AffixFile result) Reads a compound setting: the size limits, the boundary checks, the syllable rules, and the compound switches.private static List<int[]> readFlagAliases(String[][] fieldsByLine, HunspellDictionary.FlagMode mode) Parses the file-wide flag alias table before parsing affix continuation flags.private static booleanreadFlagDeclaration(String[] fields, int line, HunspellDictionary.AffixFile result) Reads a directive that declares one flag, such asCOMPOUNDFLAGorNEEDAFFIX.private static HunspellDictionary.FlagModereadFlagMode(String[][] fieldsByLine) Finds the file-wide flag mode before parsing directives that contain flags.private static voidreadGeneralSetting(String[] fields, int line, HunspellDictionary.AffixFile result) Reads a general setting outside compounding: the affix switches, the sharp-s and warning rules, and the language.readMorphologyAliases(String[][] lines) Parses the complete AM alias table before entries and affixes.private static List<HunspellDictionary.WordBreak> readWordBreaks(String[][] lines) Parses BREAK declarations, using hyphen rules when no table is configured.(package private) booleanrejectsCompoundReplacement(String word, Predicate<String> recognized) Tests CHECKCOMPOUNDREP with the configured replacement table.private static StringremoveIgnored(String text, String ignored) Removes characters listed in the affix file's IGNORE setting.(package private) booleanReturns whether simplified triple-letter junctions are enabled.private static String[]splitLines(String content) Splits text into lines with a single character scan.(package private) List<HunspellDictionary.Affix> suffixesEndingWith(int last) The suffix rules whose affix material ends in the given code point, which are the only material-bearing rules that can be undone from a word ending in it.(package private) List<HunspellDictionary.Affix> Returns the strip-only suffix rules, applicable to any word.(package private) booleansupports(int[] flags, int flag) Checks whether one homonym supports an affix analysis, under the conditions ofsupports(List, int).(package private) booleanChecks whether some homonym supports an affix analysis: its flag set carries the affix's flag and is neither compound-only nor forbidden.(package private) booleansupportsCompoundCrossProduct(int[] flags, HunspellDictionary.CompoundPosition position, HunspellDictionary.Affix prefix, HunspellDictionary.Affix suffix, HunspellDictionary.Affix... additional) Checks a compound cross-product reading.(package private) booleansupportsCrossProduct(int[] flags, HunspellDictionary.Affix prefix, HunspellDictionary.Affix suffix) Checks whether one homonym supports a cross-product analysis, under the conditions ofsupportsCrossProduct(List, Affix, Affix).(package private) booleansupportsCrossProduct(List<int[]> flagSets, HunspellDictionary.Affix prefix, HunspellDictionary.Affix suffix) Checks whether some homonym supports a cross-product analysis.(package private) booleansupportsPart(int[] flags, int affixFlag, HunspellDictionary.CompoundPosition position, boolean affixAdmits) Checks whether one homonym supports an affixed compound part, under the conditions ofsupportsPart(List, int, CompoundPosition, boolean).(package private) booleansupportsPart(List<int[]> flagSets, int affixFlag, HunspellDictionary.CompoundPosition position, boolean affixAdmits) Checks whether some homonym supports an affixed compound part.private static StringRemoves leading and trailing whitespace, using the whitespace definition the rest of the parser scans with.private static intunescapedSlash(String line) Finds the first/that is not escaped as\/, which separates the word from its flag run in a word-list entry.(package private) StringupperCaseInitial(String word) Converts the initial code point to uppercase with the dictionary's case mapping.private static booleanusesUnicodeOrNumericFlags(byte[] bytes) Tests for UTF-8 or numeric flag encoding.(package private) booleanvalidStandalone(int[] flags) Checks whether one homonym stands on its own: its flag set carries none of the blocking flags named invalidStandalone(List).(package private) booleanvalidStandalone(List<int[]> flagSets) Checks whether a listed word is valid on its own: some homonym's flag set carries none of the blocking flags.(package private) List<HunspellDictionary.WordBreak> Returns the word separators with their start and end anchors.private static voidwriteNormalizedByte(ByteArrayOutputStream target, byte source, boolean flagByte) Writes a raw byte, converting a high flag byte to a UTF-8 code point.private static voidwriteNormalizedFlagLine(ByteArrayOutputStream target, byte[] bytes, int lineStart, int lineEnd) Writes one affix line, converting high bytes only within raw flag fields.
-
Field Details
-
AFFIX_FILE_SUFFIX
The file suffix for a Hunspell affix file.- See Also:
-
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:
-
AFFIX_STREAM
- See Also:
-
DICTIONARY_STREAM
- See Also:
-
NO_AFFIXES
The shared empty bucket answered for characters no affix rule is keyed under. -
PREFIX_TAG
The line tag of a prefix block and of every rule line inside it.- See Also:
-
SUFFIX_TAG
The line tag of a suffix block and of every rule line inside it.- See Also:
-
FLAG_TAG
The directive that selects the file-wide flag representation.- See Also:
-
ALIAS_TAG
The directive that defines the file-wide flag alias table.- See Also:
-
INPUT_CONVERSION_TAG
- See Also:
-
OUTPUT_CONVERSION_TAG
- See Also:
-
IGNORE_TAG
- See Also:
-
KEEP_CASE_TAG
- See Also:
-
COMPLEX_PREFIXES_TAG
- See Also:
-
COMPOUND_RULE_TAG
- See Also:
-
COMPOUND_PATTERN_TAG
- See Also:
-
MORPHOLOGY_ALIAS_TAG
- See Also:
-
BREAK_TAG
- See Also:
-
LANGUAGE_TAG
- See Also:
-
WARNING_TAG
- See Also:
-
FORBID_WARNING_TAG
- See Also:
-
CHECK_SHARPS_TAG
- See Also:
-
COMPOUND_ROOT_TAG
- See Also:
-
FORCE_UPPER_CASE_TAG
- See Also:
-
COMPOUND_MORE_SUFFIXES_TAG
- See Also:
-
SIMPLIFIED_TRIPLE_TAG
- See Also:
-
SYLLABLE_NUMBER_TAG
- See Also:
-
LEMMA_PRESENT_TAG
- See Also:
-
COMPOUND_SYLLABLE_TAG
- See Also:
-
CHECK_COMPOUND_REP_TAG
- See Also:
-
REPLACEMENT_TAG
The suggestion table whose replacementsCHECKCOMPOUNDREPapplies to compounds.- See Also:
-
PHONETIC_FIELD
The word-list field that lists a misspelling of its entry.- See Also:
-
COMPOUND_PART_FIELD
Field prefix of a compound part in an analysis.- See Also:
-
SHARP_S
The sharp s, whichCHECKSHARPSrelates to a double s.- See Also:
-
DOUBLE_S
The lowercase double s that a sharp s expands to.- See Also:
-
DOUBLE_CAPITAL_S
The uppercase double s that an all-uppercase sharp s entry is written with.- See Also:
-
BREAK_START_ANCHOR
TheBREAKanchor that binds a separator to the start of the word.- See Also:
-
BREAK_END_ANCHOR
TheBREAKanchor that binds a separator to the end of the word.- See Also:
-
DOTTED_CAPITAL_I
The dotted capital I, the uppercase ofiin the Turkic languages.- See Also:
-
STEM_FIELD
- See Also:
-
SURFACE_PREFIX_FIELD
- See Also:
-
DERIVATIONAL_SUFFIX_FIELD
- See Also:
-
FLAG_FIELD
- See Also:
-
DEFAULT_WORD_BREAKS
The separators used when the affix file declares noBREAKtable: a hyphen inside the word, at its start, and at its end. -
COMMENT_PREFIX
Prefix used by comment lines.- See Also:
-
SET_TAG
The affix-file directive that declares the character encoding.- See Also:
-
SET_PREFIX
TheSETdirective followed by a space.- See Also:
-
SET_TAB_PREFIX
TheSETdirective followed by a tab.- See Also:
-
NO_MATERIAL
The affix format's marker for absent strip or affix material.- See Also:
-
MAX_NUMERIC_FLAG
private static final int MAX_NUMERIC_FLAGLargest flag value permitted byFLAG num: the full unsigned 16-bit range. The format manual names 65000, but published dictionaries use values above it and Hunspell loads them.- See Also:
-
HUNGARIAN_HYPHEN_FLAGS
private static final int[] HUNGARIAN_HYPHEN_FLAGSThe flags Hungarian dictionaries reserve for the hyphen rule: an entry carrying one of them may open a compound written before a hyphen. -
MAX_COMPOUND_MIN
private static final int MAX_COMPOUND_MINLargestCOMPOUNDMINvalue that can be doubled without overflow.- See Also:
-
entries
-
suffixesByLast
-
suffixesWithoutMaterial
-
prefixesByFirst
-
prefixesWithoutMaterial
-
compoundFlag
private final int compoundFlag -
compoundBegin
private final int compoundBegin -
compoundEnd
private final int compoundEnd -
compoundMin
private final int compoundMin -
needAffix
private final int needAffix -
onlyInCompound
private final int onlyInCompound -
forbiddenWord
private final int forbiddenWord -
circumfix
private final int circumfix -
compoundMiddle
private final int compoundMiddle -
compoundPermit
private final int compoundPermit -
compoundForbid
private final int compoundForbid -
compoundWordMax
private final int compoundWordMax -
checkCompoundDup
private final boolean checkCompoundDup -
checkCompoundCase
private final boolean checkCompoundCase -
checkCompoundTriple
private final boolean checkCompoundTriple -
fullStrip
private final boolean fullStrip -
ignoredCharacters
-
inputConversion
-
outputConversion
-
morphology
-
complexPrefixes
private final boolean complexPrefixes -
keepCase
private final int keepCase -
warningFlag
private final int warningFlag -
forbidWarn
private final boolean forbidWarn -
checkSharps
private final boolean checkSharps -
turkicCase
private final boolean turkicCase -
hungarian
private final boolean hungarian -
syllableNumber
private final boolean syllableNumber -
compoundRules
-
compoundPatterns
-
compoundRoot
private final int compoundRoot -
forceUpperCase
private final int forceUpperCase -
compoundMoreSuffixes
private final boolean compoundMoreSuffixes -
simplifiedTriple
private final boolean simplifiedTriple -
checkCompoundRep
private final boolean checkCompoundRep -
replacements
-
maxCompoundSyllables
private final int maxCompoundSyllables -
compoundVowels
-
wordBreaks
-
unsupportedDirectives
-
longestSpacedForm
private final int longestSpacedForm
-
-
Constructor Details
-
HunspellDictionary
private HunspellDictionary(Map<String, List<int[]>> entries, HunspellDictionary.AffixFile affix, List<HunspellDictionary.UnsupportedDirective> unsupportedDirectives) Initializes the dictionary from the two parsed files.- Parameters:
entries- The words mapped to the flag sets of their entries.affix- The parsed affix file.unsupportedDirectives- The skipped directives in encounter order.
-
-
Method Details
-
longestSpacedForm
private static int longestSpacedForm(Set<String> words, List<HunspellDictionary.Affix> prefixes, List<HunspellDictionary.Affix> suffixes) Bounds the length of a word containing a space that can have a reading. Such a reading needs an entry or affix material with a space, and it is found by undoing at most two prefixes and two suffixes, each adding at most the longest affix material; a case variant is at least half as long as its surface form, because the sharp s variant replaces two letters with one.- Parameters:
words- The listed spellings.prefixes- The prefix rules.suffixes- The suffix rules.- Returns:
- The longest possible UTF-16 length, or -1 when no spaced form has a reading.
-
mayReadSpacedForm
boolean mayReadSpacedForm(int length) Tests whether a word containing a space can have a reading, so that the compound word-pair check can skip texts no reading can match.- Parameters:
length- The UTF-16 length of the spaced word.- Returns:
falseif no word of this length containing a space has a reading.
-
bucketByBoundary
private static HunspellDictionary.BoundaryIndex bucketByBoundary(List<HunspellDictionary.Affix> rules, boolean suffix, List<HunspellDictionary.Affix> withoutMaterial) Buckets affix rules by the boundary code point of their affix material, the last code point for a suffix rule and the first for a prefix rule.- Parameters:
rules- The rules of one kind, in file order.suffix- Whether the rules are suffix rules.withoutMaterial- Collects the rules with empty affix material, which no boundary code point keys.- Returns:
- The rules indexed by their boundary code point. Never
null.
-
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.
-
loadStreams
private static HunspellDictionary loadStreams(InputStream affixStream, InputStream dictionaryStream, HunspellDictionary.LoadMode mode, String source) throws IOException Loads validated streams without closing them.- Parameters:
affixStream- The affix input.dictionaryStream- The word-list input.mode- The directive policy.source- The affix source used in unsupported-directive diagnostics.- Returns:
- The parsed dictionary.
- Throws:
IOException- Thrown if reading, validation, or parsing fails.
-
maskIgnoredAffixLines
private static List<HunspellDictionary.UnsupportedDirective> maskIgnoredAffixLines(byte[] bytes, HunspellDictionary.LoadMode mode, String source) throws IOException Replaces comments and unused directive lines with ASCII spaces before strict decoding. Published dictionaries sometimes retain legacy-encoded metadata despite aSET UTF-8declaration. Line endings and byte positions remain unchanged, while malformed bytes in parsed directives are still reported.- Parameters:
bytes- The buffered affix file, modified in place.mode- The directive policy applied before masking.source- The affix source description.- Returns:
- Unsupported directives skipped in partial mode, in encounter order.
- Throws:
IOException- Thrown if strict loading encounters an unsupported directive.
-
byteOrderMarkLength
private static int byteOrderMarkLength(byte[] bytes) Measures a leading UTF-8 byte order mark, which the byte-level scans skip so that the first line's directive is read without it.- Parameters:
bytes- The affix content.- Returns:
- 3 when the content starts with a UTF-8 byte order mark, otherwise 0.
-
hasAffixDirective
Finds a directive before metadata is removed or decoded.- Parameters:
bytes- The affix content.directive- The requested first field.- Returns:
- Whether the directive occurs outside a comment.
-
isIgnoredAffixDirective
Identifies metadata, suggestion and command-line settings unused by stemming. REP is parsed separately when CHECKCOMPOUNDREP makes it affect recognition.- Parameters:
directive- The affix directive name.- Returns:
- Whether the directive can be ignored by the affix stemmer.
-
isAsciiFieldSpace
private static boolean isAsciiFieldSpace(byte value) Tests an affix field separator.- Parameters:
value- The input byte.- Returns:
- Whether the byte separates fields.
-
maskInlineComment
Replaces a trailing comment with spaces. A number sign starts a comment only in a field the directive does not consume, because the format allows#as a flag, a separator, affix material, and conversion text. The fields after the ones a directive reads are not interpreted.- Parameters:
bytes- The mutable file content.from- The first byte of the directive.to- The exclusive end of the line.directive- The directive name.
-
firstCommentField
Finds the first field index a trailing comment may occupy.- Parameters:
bytes- The file content.fields- The field boundaries of the line.directive- The directive name.- Returns:
- The index after the fields the directive consumes.
-
isAffixHeader
Distinguishes an affix block header, which carries a cross-product marker and a rule count, from a rule line.- Parameters:
bytes- The file content.fields- The field boundaries of the line.- Returns:
- Whether the line is a block header.
-
isParsedAffixDirective
Tests whether a directive is supported by the parser.- Parameters:
directive- The directive name.- Returns:
- Whether the parser processes the directive's fields.
-
normalizeUtf8ByteFlags
Converts raw one-byte flags in a UTF-8 affix file to equivalent Unicode code points before decoding. Hunspell's default andlongflag modes operate on bytes, and published UTF-8 dictionaries can therefore contain non-UTF-8 bytes in flag fields. Text, conditions, and affix material remain subject to strict UTF-8 decoding.- Parameters:
bytes- The affix file after unused lines have been masked.charset- The encoding selected bySET.- Returns:
- The content with raw flag bytes represented as valid UTF-8.
-
usesUnicodeOrNumericFlags
private static boolean usesUnicodeOrNumericFlags(byte[] bytes) Tests for UTF-8 or numeric flag encoding.- Parameters:
bytes- The affix content.- Returns:
- Whether
FLAG UTF-8orFLAG numis configured.
-
writeNormalizedFlagLine
private static void writeNormalizedFlagLine(ByteArrayOutputStream target, byte[] bytes, int lineStart, int lineEnd) Writes one affix line, converting high bytes only within raw flag fields.- Parameters:
target- The converted content destination.bytes- The source file content.lineStart- The first byte of the line.lineEnd- The exclusive end of the line.
-
normalizeDictionaryByteFlags
private static byte[] normalizeDictionaryByteFlags(byte[] bytes) Converts raw flag bytes after the flag separator of each dictionary entry. Word text and morphology fields remain subject to strict UTF-8 decoding.- Parameters:
bytes- The buffered dictionary file.- Returns:
- The content with raw flag bytes represented as valid UTF-8.
-
writeNormalizedByte
private static void writeNormalizedByte(ByteArrayOutputStream target, byte source, boolean flagByte) Writes a raw byte, converting a high flag byte to a UTF-8 code point.- Parameters:
target- The converted content destination.source- The source byte.flagByte- Whether this byte represents a flag.
-
isSingleFlagDirective
Tests for a directive with one flag argument.- Parameters:
directive- The directive name.- Returns:
- Whether the value is one Hunspell flag.
-
findAsciiFields
private static int findAsciiFields(byte[] bytes, int from, int to, int[] starts, int[] fieldEnds) Finds the fields needed to classify one raw line.- Parameters:
bytes- The source content.from- The first byte of the line.to- The exclusive end of the line.starts- The destination for field start offsets.fieldEnds- The destination for exclusive field end offsets.- Returns:
- The number of fields found, limited to the destination array length.
-
asciiField
Extracts one ASCII field.- Parameters:
bytes- The source content.from- The first byte of the field.to- The exclusive end of the field.- Returns:
- The field text.
-
decode
Converts file content without replacing malformed or unmappable input.- Parameters:
bytes- The encoded file content.charset- The selected character encoding.label- The file label used in the exception message.- Returns:
- The decoded content.
- Throws:
IOException- Thrown ifbytesare invalid incharset.
-
readBounded
Reads an input stream into a byte array, failing when more thanmaxBytesarrive.- Parameters:
in- The stream to read. Not closed.maxBytes- The inclusive upper bound on buffered bytes.label- The stream name used in the error message.- Returns:
- The buffered bytes. Never
null. - Throws:
IOException- Thrown if reading fails or the stream exceedsmaxBytes.
-
lookup
Looks up a word's flag sets among the listed entries.- Parameters:
word- The word exactly as listed.- Returns:
- The flag sets of all matching entries, or
nullwhen absent.
-
lookup
Looks up a word's flag sets, optionally including the hidden capitalized forms that all-uppercase input outside compounds may match. The stored lists are immutable and are returned as they are; a list is built only when a word has both listed and hidden entries. Callers do not modify the flag arrays.- Parameters:
word- The word exactly as listed or in hidden capitalized form.includeHidden- Whether hidden capitalized forms count.- Returns:
- The flag sets of all matching entries, or
nullwhen absent.
-
immutableFlagSets
Replaces every flag-set list with an immutable copy so that lookups can return the stored lists directly.- Parameters:
flagSets- The words mapped to mutable flag-set lists.- Returns:
- The same words mapped to immutable lists.
-
caseType
Classifies a word's capitalization, judging the initial by the first character.- Parameters:
word- The word to classify.- Returns:
- The capitalization class.
-
homonyms
The flag sets of a root's entries, listed or hidden capitalized.- Parameters:
root- The entry spelling a reading selected.- Returns:
- The flag sets in list order. Never
null.
-
suffixesEndingWith
The suffix rules whose affix material ends in the given code point, which are the only material-bearing rules that can be undone from a word ending in it.- Parameters:
last- The word's last code point.- Returns:
- The bucket, possibly empty. Never
null.
-
suffixesWithoutMaterial
List<HunspellDictionary.Affix> suffixesWithoutMaterial()Returns the strip-only suffix rules, applicable to any word. Nevernull.- Returns:
- the strip-only suffix rules, applicable to any word
-
prefixesStartingWith
The prefix rules whose affix material starts with the given code point, which are the only material-bearing rules that can be undone from a word starting with it.- Parameters:
first- The word's first code point.- Returns:
- The bucket, possibly empty. Never
null.
-
prefixesWithoutMaterial
List<HunspellDictionary.Affix> prefixesWithoutMaterial()Returns the strip-only prefix rules, applicable to any word. Nevernull.- Returns:
- the strip-only prefix rules, applicable to any word
-
compoundsDeclared
boolean compoundsDeclared()Returns whether the affix file declares any compounding flag at all.- Returns:
- whether the affix file declares any compounding flag at all
-
compoundRules
List<HunspellCompoundRule> compoundRules()Returns the parsed independent compound flag patterns.- Returns:
- the parsed independent compound flag patterns
-
compoundPatterns
List<HunspellDictionary.CompoundPattern> compoundPatterns()Returns the compound-boundary patterns.- Returns:
- the compound-boundary patterns
-
simplifiedTriple
boolean simplifiedTriple()Returns whether simplified triple-letter junctions are enabled.- Returns:
- whether simplified triple-letter junctions are enabled
-
compoundMoreSuffixes
boolean compoundMoreSuffixes()Returns whether compounds permit an additional suffix level.- Returns:
- whether compounds permit an additional suffix level
-
wordBreaks
List<HunspellDictionary.WordBreak> wordBreaks()Returns the word separators with their start and end anchors.- Returns:
- the word separators with their start and end anchors
-
compoundUnits
Counts an entry toward COMPOUNDWORDMAX.- Parameters:
flags- The selected entry flags.affixes- The applied rules.- Returns:
- One unit, or an additional unit for COMPOUNDROOT.
-
compoundSizeAllowed
boolean compoundSizeAllowed(int syllables, int units) Checks word and syllable limits on a completed compound.- Parameters:
syllables- The syllable count after language adjustments.units- The compound-word count.- Returns:
- Whether the limits permit the compound.
-
compoundSyllables
int compoundSyllables(String part, int[] flags, List<HunspellDictionary.Affix> affixes, boolean last) Calculates a component's contribution to the compound syllable limit.- Parameters:
part- The component text.flags- The selected entry flags.affixes- The applied rules in order.last- Whether this is the closing component.- Returns:
- The adjusted vowel count.
-
countSyllables
Counts code points listed by COMPOUNDSYLLABLE.- Parameters:
text- The text to count.- Returns:
- The vowel count.
-
hyphenMovingRule
boolean hyphenMovingRule()Returns whether the Hungarian moving rule applies. The part of a Hungarian word before a hyphen is checked as a compound with relaxed rules: the opening part may qualify through the reserved flagsF,G, andH, a compound-forbidden opening entry is allowed, and the size limits do not apply.- Returns:
- whether the Hungarian moving rule applies
-
opensHyphenatedCompound
boolean opensHyphenatedCompound(int[] flags) Checks whether an entry may open a compound under the Hungarian moving rule.- Parameters:
flags- One entry's flag set.- Returns:
trueif the entry carries one of the hardwired opening flags and is not forbidden.
-
compoundCaseAllowed
Checks a closing entry's capitalization requirement.- Parameters:
flags- The closing entry flags.word- The input compound.- Returns:
- Whether FORCEUCASE permits the input.
-
rejectsCompoundReplacement
Tests CHECKCOMPOUNDREP with the configured replacement table.- Parameters:
word- The candidate compound.recognized- Tests a non-compound form.- Returns:
- Whether a replacement invalidates the compound reading.
-
positionalCompoundsDeclared
boolean positionalCompoundsDeclared()Returns whether positional or general compound flags are configured.- Returns:
- whether positional or general compound flags are configured
-
acceptsRulePart
Checks blocking flags on a compound-rule part.- Parameters:
flags- The selected entry flags.last- Whether this is the closing part.affixes- The applied suffixes.- Returns:
- Whether the selected entry and affixes can form a compound part.
-
compoundMin
int compoundMin()Returns the smallest length a compound part may have. At least1.- Returns:
- the smallest length a compound part may have
-
compoundWordMax
int compoundWordMax()Returns the largest number of parts a compound may have.0is unbounded.- Returns:
- the largest number of parts a compound may have
-
checkCompoundDup
boolean checkCompoundDup()Returns whetherCHECKCOMPOUNDDUPforbids a part repeating its neighbor.- Returns:
- whether
CHECKCOMPOUNDDUPforbids a part repeating its neighbor
-
checkCompoundCase
boolean checkCompoundCase()Returns whetherCHECKCOMPOUNDCASEforbids uppercase at part boundaries.- Returns:
- whether
CHECKCOMPOUNDCASEforbids uppercase at part boundaries
-
checkCompoundTriple
boolean checkCompoundTriple()Returns whetherCHECKCOMPOUNDTRIPLEforbids triple letters at boundaries.- Returns:
- whether
CHECKCOMPOUNDTRIPLEforbids triple letters at boundaries
-
fullStrip
boolean fullStrip()Returns whetherFULLSTRIPallows an affix rule to strip a whole stem.- Returns:
- whether
FULLSTRIPallows an affix rule to strip a whole stem
-
inputForm
Applies input conversion followed by ignored-character removal.- Parameters:
word- The supplied word.- Returns:
- The dictionary lookup form.
-
outputForm
Applies output conversion to a recognized stem.- Parameters:
stem- The dictionary stem.- Returns:
- The converted output.
-
complexPrefixes
boolean complexPrefixes()Returns whether prefix continuation allows an additional prefix level.- Returns:
- whether prefix continuation allows an additional prefix level
-
checkSharps
boolean checkSharps()Returns whether uppercase SS may represent a German sharp s.- Returns:
- whether uppercase SS may represent a German sharp s
-
lowerCase
Applies the dictionary's lowercase mapping.- Parameters:
text- The input text.- Returns:
- The lowercase text.
-
acceptsCase
boolean acceptsCase(int[] flags, String surface, String variant, HunspellDictionary.Affix... affixes) Checks case-sensitive and warning restrictions for a selected entry.- Parameters:
flags- The homonym's flags.surface- The input after conversion.variant- The case variant under analysis.affixes- The applied affixes.- Returns:
- Whether this reading is permitted.
-
morphologicalStems
Returns a stem after applying entry and affix morphology.- Parameters:
root- The dictionary entry spelling.flags- The selected homonym's flags.affixes- The affixes in application order.- Returns:
- The stems of matching homonyms.
-
morphologicalAnalyses
List<String> morphologicalAnalyses(String root, int[] flags, boolean compoundEnd, HunspellDictionary.Affix... affixes) Returns morphological fields for matching dictionary entries and applied rules: prefix fields, then entry fields, then suffix fields. A prefix without morphological fields contributes its affix text when no suffix follows and itsfl:flag field otherwise; after the entry fields, an entry without fields contributes that prefix'sfl:field. A bare closing compound part without entry fields contributes no stem field.- Parameters:
root- The dictionary entry text.flags- The selected homonym flags.compoundEnd- Whether the reading closes a compound.affixes- The applied rules in order.- Returns:
- The complete field strings, possibly empty strings.
-
morphologicalStem
private String morphologicalStem(String root, List<String> fields, HunspellDictionary.Affix... affixes) Applies morphological stem and affix fields to one dictionary entry.- Parameters:
root- The entry spelling.fields- The entry's morphological fields.affixes- The affixes in application order.- Returns:
- The morphological stem.
-
fieldValue
Finds a morphological field value.- Parameters:
fields- The expanded fields.tag- The tag including the colon.fallback- The value used when the tag is not present.- Returns:
- The first field value or fallback.
-
hasField
Checks for a morphological field.- Parameters:
fields- The expanded fields.tag- The tag including the colon.- Returns:
- Whether the tag is present.
-
removeIgnored
Removes characters listed in the affix file's IGNORE setting.- Parameters:
text- The word or affix material.ignored- The characters to remove.- Returns:
- Text without the ignored characters.
-
positionalFlag
The flag admitting a part at a compound position, next to the general compounding flag.- Parameters:
position- The part's place in the compound.- Returns:
- The dedicated positional flag, or
0when undeclared.
-
mayStand
Checks whether a listed word may stand at a compound position: some homonym's flag set contains the general compound flag or the position's dedicated flag and is not forbidden. AnONLYINCOMPOUNDentry is valid here, while aNEEDAFFIXentry still requires an affix.- Parameters:
flagSets- The word's flag sets fromlookup(String).position- The part's place in the compound.- Returns:
trueif the word may stand at the position.
-
mayStand
Checks whether one homonym may stand as a bare compound part at a position.- Parameters:
flags- One entry's flag set.position- The part's place in the compound.- Returns:
trueif the entry may stand at the position.
-
supportsPart
boolean supportsPart(List<int[]> flagSets, int affixFlag, HunspellDictionary.CompoundPosition position, boolean affixAdmits) Checks whether some homonym supports an affixed compound part. The flag set contains the removed affix flag, is not forbidden, and either the affix permits the position or the set contains the compound or positional flag.- Parameters:
flagSets- The part stem's flag sets fromlookup(String).affixFlag- The removed affix's flag.position- The part's place in the compound.affixAdmits- Whether the affix's continuation classes admit the position, fromaffixAdmits(Affix, CompoundPosition).- Returns:
trueif some homonym permits the affixed form at the position.
-
supportsPart
boolean supportsPart(int[] flags, int affixFlag, HunspellDictionary.CompoundPosition position, boolean affixAdmits) Checks whether one homonym supports an affixed compound part, under the conditions ofsupportsPart(List, int, CompoundPosition, boolean).- Parameters:
flags- One entry's flag set.affixFlag- The removed affix's flag.position- The part's place in the compound.affixAdmits- Whether the affix's continuation classes admit the position.- Returns:
trueif the entry permits the affixed form at the position.
-
affixAdmits
Checks whether an affix admits its derived form at a compound position: its continuation classes carry the general compounding flag or the position's dedicated flag. Published dictionaries position their linking forms this way, through zero or dash suffixes whose continuation classes hold the positional flags.- Parameters:
affix- The affix rule applied to the part.position- The part's place in the compound.- Returns:
trueif the affixed form may stand at the position.
-
permitsInside
Checks whether an affix may sit at a compound-internal boundary: it carries theCOMPOUNDPERMITFLAGamong its continuation classes. Without the flag a suffix fits only the last part and a prefix only the first.- Parameters:
affix- The affix rule applied to the part.- Returns:
trueif the affix may face another part.
-
forbidsInCompound
Checks whether an affix bars its derived form from compounds altogether: it carries theCOMPOUNDFORBIDFLAGamong its continuation classes.- Parameters:
affix- The affix rule applied to the part.- Returns:
trueif the affixed form may not join a compound.
-
forbiddenAtCompoundPosition
private boolean forbiddenAtCompoundPosition(int[] flags, HunspellDictionary.CompoundPosition position) Checks whether an entry marked withCOMPOUNDFORBIDFLAGis barred from this compound position. Such an entry may stand only as the last part.- Parameters:
flags- One entry's flag set.position- The part's place in the compound.- Returns:
trueif the entry may not stand at the position.
-
firstForbidden
Checks whether a spelling is forbidden as a whole. Only the first listed homonym decides, so a dictionary can list a valid word first and a forbidden compound-only homonym after it.- Parameters:
flagSets- The word's flag sets fromlookup(String), in list order.- Returns:
trueif the first homonym carries the forbidden-word flag.
-
forbidsAffixed
Checks whether an affix analysis reaches a forbidden entry, which forbids the affixed spelling and thereby its compound and break readings.- Parameters:
flagSets- The stem's flag sets fromlookup(String).flag- The removed affix's flag.- Returns:
trueif a homonym carries both the affix flag and the forbidden flag.
-
forbidsAffixed
boolean forbidsAffixed(int[] flags, int flag) Checks whether one homonym carries both an affix flag and the forbidden flag.- Parameters:
flags- One entry's flag set.flag- The removed affix's flag.- Returns:
trueif the entry forbids the affixed spelling.
-
forbidsCompoundStart
Checks whether a spelling may not open a compound part sequence: its first listed homonym carriesCOMPOUNDFORBIDFLAG, which applies to every part but the last and overrides affixed readings of the same spelling.- Parameters:
flagSets- The part's flag sets fromlookup(String), in list order.- Returns:
trueif the spelling is barred from non-final compound positions.
-
upperCaseInitial
Converts the initial code point to uppercase with the dictionary's case mapping.- Parameters:
word- The nonempty word.- Returns:
- The word with an uppercase initial.
-
lowerCaseInitial
Converts the initial code point to lowercase with the dictionary's case mapping.- Parameters:
word- The nonempty word.- Returns:
- The word with a lowercase initial.
-
hasFlag
Checks whether any of a word's flag sets carries a flag.- Parameters:
flagSets- The flag sets fromlookup(String).flag- The flag to look for.- Returns:
trueif some flag set contains the flag.
-
contains
static boolean contains(int[] flags, int flag) Checks one flag set for a flag. An undeclared flag, encoded as0, is carried by no entry.- Parameters:
flags- One entry's flag set.flag- The flag to look for.- Returns:
trueif the set contains the flag.
-
validStandalone
Checks whether a listed word is valid on its own: some homonym's flag set carries none of the blocking flags. An entry whose every flag set is markedNEEDAFFIXis a virtual stem that exists only to be affixed, one markedONLYINCOMPOUNDappears only inside compounds, and one markedFORBIDDENWORDis listed to be blocked; none of them is a word by itself.- Parameters:
flagSets- The word's flag sets fromlookup(String).- Returns:
trueif some homonym stands on its own.
-
validStandalone
boolean validStandalone(int[] flags) Checks whether one homonym stands on its own: its flag set carries none of the blocking flags named invalidStandalone(List).- Parameters:
flags- One entry's flag set.- Returns:
trueif the entry is a word by itself.
-
supports
Checks whether some homonym supports an affix analysis: its flag set carries the affix's flag and is neither compound-only nor forbidden. ANEEDAFFIXset does support the analysis, because the removed affix is exactly what the virtual stem needs.- Parameters:
flagSets- The stem's flag sets fromlookup(String).flag- The removed affix's flag.- Returns:
trueif some homonym carries the flag and may stand affixed.
-
supports
boolean supports(int[] flags, int flag) Checks whether one homonym supports an affix analysis, under the conditions ofsupports(List, int).- Parameters:
flags- One entry's flag set.flag- The removed affix's flag.- Returns:
trueif the entry carries the flag and may stand affixed.
-
supportsCrossProduct
boolean supportsCrossProduct(List<int[]> flagSets, HunspellDictionary.Affix prefix, HunspellDictionary.Affix suffix) Checks whether some homonym supports a cross-product analysis. The root can contain both affix flags, or one root flag can select an affix with continuation flags that select the other affix.- Parameters:
flagSets- The stem's flag sets fromlookup(String).prefix- The removed prefix.suffix- The removed suffix.- Returns:
trueif some homonym licenses both affixes.
-
supportsCrossProduct
boolean supportsCrossProduct(int[] flags, HunspellDictionary.Affix prefix, HunspellDictionary.Affix suffix) Checks whether one homonym supports a cross-product analysis, under the conditions ofsupportsCrossProduct(List, Affix, Affix).- Parameters:
flags- One entry's flag set.prefix- The removed prefix.suffix- The removed suffix.- Returns:
trueif the entry licenses both affixes and may stand affixed.
-
licensesCrossProduct
boolean licensesCrossProduct(int[] flags, HunspellDictionary.Affix prefix, HunspellDictionary.Affix suffix) Checks cross-product flags within a single entry.- Parameters:
flags- The selected entry flags.prefix- The prefix rule.suffix- The suffix rule.- Returns:
- Whether the entry and continuation classes permit both rules.
-
supportsCompoundCrossProduct
boolean supportsCompoundCrossProduct(int[] flags, HunspellDictionary.CompoundPosition position, HunspellDictionary.Affix prefix, HunspellDictionary.Affix suffix, HunspellDictionary.Affix... additional) Checks a compound cross-product reading.- Parameters:
flags- The selected entry flags.position- The component position.prefix- The prefix rule.suffix- The suffix rule.additional- Additional continuation-linked rules.- Returns:
- Whether the entry and rules permit this component.
-
needsFurtherAffix
Checks whether a form made with this affix alone is still a virtual stem: the affix carries theNEEDAFFIXflag among its continuation classes, so a further affix must join before the form is a word.- Parameters:
affix- The affix rule to inspect.- Returns:
trueif the affix alone does not finish a word.
-
compoundOnly
Checks whether an affix applies only inside compounds: it carries theONLYINCOMPOUNDflag among its continuation classes.- Parameters:
affix- The affix rule to inspect.- Returns:
trueif the affix never applies to a standalone word.
-
circumfixOnly
Checks whether an affix is one half of a circumfix: it carries theCIRCUMFIXflag among its continuation classes, so it is only valid on a word that also carries a circumfix-marked affix of the other kind, the Germange...tparticiple being the model.- Parameters:
affix- The affix rule to inspect.- Returns:
trueif the affix never applies without its other half.
-
declaredCharset
Finds theSETdeclaration by scanning the raw affix bytes as ASCII, which is safe because the declaration itself is ASCII in every supported encoding. Both files are then decoded with the declared charset.- Parameters:
affixBytes- The raw affix file content.- Returns:
- The declared charset, or UTF-8 when no declaration is present.
- Throws:
IOException- Thrown if the declared encoding name is not supported.
-
parseAffix
Parses the affix file: theFLAGdeclaration, theAFflag alias table, the compound and blocking flag declarations, and thePFXandSFXblocks. Other directives are skipped because this class implements affix stemming, not the complete Hunspell spell-checking engine.- Parameters:
content- The decoded affix file content.- Returns:
- The parsed rules and flag mode. Never
null. - Throws:
IOException- Thrown if a supported directive is malformed.
-
readFlagDeclaration
private static boolean readFlagDeclaration(String[] fields, int line, HunspellDictionary.AffixFile result) throws IOException Reads a directive that declares one flag, such asCOMPOUNDFLAGorNEEDAFFIX.- Parameters:
fields- The line's fields.line- The one-based source line.result- The affix file under construction.- Returns:
trueif the line was a flag declaration.- Throws:
IOException- Thrown if the declaration has no flag or the flag is malformed.
-
readCompoundSetting
private static boolean readCompoundSetting(String[] fields, int line, HunspellDictionary.AffixFile result) throws IOException Reads a compound setting: the size limits, the boundary checks, the syllable rules, and the compound switches.- Parameters:
fields- The line's fields.line- The one-based source line.result- The affix file under construction.- Returns:
trueif the line was a compound setting.- Throws:
IOException- Thrown if a value is missing, negative, or out of range.
-
readGeneralSetting
private static void readGeneralSetting(String[] fields, int line, HunspellDictionary.AffixFile result) throws IOException Reads a general setting outside compounding: the affix switches, the sharp-s and warning rules, and the language. Directives read before this pass and ignored directives are left alone.- Parameters:
fields- The line's fields.line- The one-based source line.result- The affix file under construction.- Throws:
IOException- Thrown if the language declaration is malformed.
-
readFlagMode
Finds the file-wide flag mode before parsing directives that contain flags.- Parameters:
fieldsByLine- The affix file fields, indexed by source line.- Returns:
- The selected flag mode, or character mode when no declaration is present.
- Throws:
IOException- Thrown if the declaration is missing a mode, unsupported, or repeated.
-
readFlagAliases
private static List<int[]> readFlagAliases(String[][] fieldsByLine, HunspellDictionary.FlagMode mode) throws IOException Parses the file-wide flag alias table before parsing affix continuation flags.- Parameters:
fieldsByLine- The affix file fields, indexed by source line.mode- The file's flag encoding.- Returns:
- The aliases in their one-based reference order.
- Throws:
IOException- Thrown if the table header, size, or an alias is malformed.
-
parseValue
Parses the integer value of a directive that carries exactly one.- Parameters:
fields- The already-split directive line.lineNumber- The source line, for error messages.- Returns:
- The parsed value.
- Throws:
IOException- Thrown if the value is missing or is not an integer.
-
parseAffixBlock
private static int parseAffixBlock(String[][] fieldsByLine, int index, String[] header, HunspellDictionary.AffixFile result) throws IOException Parses onePFXorSFXblock: the header line naming the flag, the cross-product marker, and the rule count, followed by exactly that many rule lines.- Parameters:
fieldsByLine- All affix file fields, indexed by source line.index- The line index of the block header.header- The already-split header fields.result- The parse target the rules are added to.- Returns:
- The index of the first line after the block.
- Throws:
IOException- Thrown if the header or a rule line is malformed.
-
parseWordList
private static Map<String,List<int[]>> parseWordList(String content, HunspellDictionary.AffixFile affix) throws IOException Parses the word list: an optional leading entry count, then one entry per line consisting of the word, an optional/flagsrun, and optional trailing morphological fields. The morphological fields are separated first, because the flag separator is only meaningful in what precedes them; a word may itself contain spaces. A slash escaped as\/belongs to the word itself and is unescaped in the stored key.- Parameters:
content- The decoded word-list content.affix- The affix settings and destination for entry morphology.- Returns:
- The words mapped to the flag sets of their entries. Never
null. - Throws:
IOException- Thrown if a flag run is malformed or an alias reference is out of range.
-
readMorphologyAliases
Parses the complete AM alias table before entries and affixes.- Parameters:
lines- The affix fields indexed by source line.- Returns:
- The aliases in reference order.
- Throws:
IOException- Thrown if a count or table entry is malformed.
-
readCompoundRules
private static List<HunspellCompoundRule> readCompoundRules(String[][] lines, HunspellDictionary.FlagMode mode) throws IOException Parses and validates the COMPOUNDRULE table.- Parameters:
lines- The affix fields indexed by line.mode- The flag encoding.- Returns:
- The parsed patterns.
- Throws:
IOException- Thrown if a count, pattern, or flag is malformed.
-
readCompoundPatterns
private static List<HunspellDictionary.CompoundPattern> readCompoundPatterns(String[][] lines, HunspellDictionary.FlagMode mode) throws IOException Parses CHECKCOMPOUNDPATTERN restrictions and replacements.- Parameters:
lines- The affix fields.mode- The flag encoding.- Returns:
- The boundary patterns.
- Throws:
IOException- Thrown if a declaration is malformed.
-
readWordBreaks
private static List<HunspellDictionary.WordBreak> readWordBreaks(String[][] lines) throws IOException Parses BREAK declarations, using hyphen rules when no table is configured.- Parameters:
lines- The affix fields.- Returns:
- The separators and anchors.
- Throws:
IOException- Thrown if the table or a separator is malformed.
-
parseMorphology
private static List<String> parseMorphology(String[] fields, List<List<String>> aliases, int line) throws IOException Expands an optional morphology alias.- Parameters:
fields- The morphological fields or alias reference.aliases- The AM table.line- The source line.- Returns:
- The expanded immutable fields.
- Throws:
IOException- Thrown if an alias reference is invalid.
-
isCount
Checks whether a line consists purely of decimal digits, which identifies the optional entry-count header of a word list.- Parameters:
line- The trimmed line to inspect.- Returns:
trueif the line is a non-empty digit run.
-
parseAliasedFlags
private static int[] parseAliasedFlags(String text, HunspellDictionary.FlagMode mode, List<int[]> aliases, int lineNumber) throws IOException Resolves a numericAFalias or parses a direct flag run when no alias applies.- Parameters:
text- The flag field without the leading slash.mode- The selected flag encoding.aliases- The affix file's alias table.lineNumber- The source line, for error messages.- Returns:
- The resolved or parsed flags.
- Throws:
IOException- Thrown if the alias is malformed or outside the table, or the direct flags do not fitmode.
-
unescapedSlash
Finds the first/that is not escaped as\/, which separates the word from its flag run in a word-list entry.- Parameters:
line- The word-list line to scan.- Returns:
- The index of the separator, or
-1when the entry has no flags.
-
morphologyIndex
Finds where the trailing morphological fields of a word-list entry begin, which terminates the word and its flag run. A morphological field is either introduced by a tabulator, the older separator, or written as a two-letter tag followed by:and preceded by a separator, such aspo:verb. A separator that is not followed by such a tag belongs to the word, because a word-list entry may name several words. The separators are the space and the tabulator, the two characters the word-list format splits on; they are format delimiters of the word-list grammar, not a whitespace judgment, so wider whitespace such as a no-break space stays part of the word by design.- Parameters:
line- The trimmed word-list line to scan.- Returns:
- The index at which the morphological fields begin, or
-1if the entry carries none.
-
isFieldSeparator
private static boolean isFieldSeparator(char c) Checks one character against the word-list format's field separators, space and tabulator.- Parameters:
c- The character to test.- Returns:
trueifcseparates fields in the word-list format.
-
trim
Removes leading and trailing whitespace, using the whitespace definition the rest of the parser scans with.- Parameters:
text- The text to trim.- Returns:
- The text without leading or trailing whitespace. Never
null.
-
parseFlags
private static int[] parseFlags(String text, HunspellDictionary.FlagMode mode, int lineNumber) throws IOException Parses a flag run according to the declared flag mode: single characters incharmode, character pairs packed into oneintinlongmode, and comma-separated decimal numbers innummode.- Parameters:
text- The flag run without its leading/. An empty run carries no flags in every mode.mode- The declared flag encoding.lineNumber- The source line, for error messages.- Returns:
- The parsed flags. Never
null. - Throws:
IOException- Thrown if the run does not fit the declared encoding.
-
parseFlag
private static int parseFlag(String text, HunspellDictionary.FlagMode mode, int lineNumber) throws IOException Parses a field that must contain exactly one flag, such as the flag name in an affix block header.- Parameters:
text- The flag field.mode- The declared flag encoding.lineNumber- The source line, for error messages.- Returns:
- The single parsed flag.
- Throws:
IOException- Thrown if the field holds no flag or more than one.
-
splitLines
Splits text into lines with a single character scan. A line ends at a line feed, a carriage return, or a carriage return followed by a line feed, as in the directive masking, so line numbers agree.- Parameters:
content- The text to split.- Returns:
- The lines without their terminators. Never
null.
-