Class HunspellDictionary

java.lang.Object
opennlp.tools.stemmer.hunspell.HunspellDictionary

@ThreadSafe public final class HunspellDictionary extends Object
An immutable, in-memory Hunspell-format dictionary loaded from user-supplied .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:
  • Field Details

    • AFFIX_FILE_SUFFIX

      public static final String AFFIX_FILE_SUFFIX
      The file suffix for a Hunspell affix file.
      See Also:
    • DICTIONARY_FILE_SUFFIX

      public static final String DICTIONARY_FILE_SUFFIX
      The file suffix for a Hunspell word-list file.
      See Also:
    • MAX_STREAM_BYTES

      public static final int MAX_STREAM_BYTES
      Inclusive upper bound on bytes buffered from one affix or dictionary stream during load(InputStream, InputStream). The limit is 64 MiB. Larger streams fail with IOException.
      See Also:
    • AFFIX_STREAM

      private static final String AFFIX_STREAM
      See Also:
    • DICTIONARY_STREAM

      private static final String DICTIONARY_STREAM
      See Also:
    • NO_AFFIXES

      private static final List<HunspellDictionary.Affix> NO_AFFIXES
      The shared empty bucket answered for characters no affix rule is keyed under.
    • PREFIX_TAG

      private static final String PREFIX_TAG
      The line tag of a prefix block and of every rule line inside it.
      See Also:
    • SUFFIX_TAG

      private static final String SUFFIX_TAG
      The line tag of a suffix block and of every rule line inside it.
      See Also:
    • FLAG_TAG

      private static final String FLAG_TAG
      The directive that selects the file-wide flag representation.
      See Also:
    • ALIAS_TAG

      private static final String ALIAS_TAG
      The directive that defines the file-wide flag alias table.
      See Also:
    • INPUT_CONVERSION_TAG

      private static final String INPUT_CONVERSION_TAG
      See Also:
    • OUTPUT_CONVERSION_TAG

      private static final String OUTPUT_CONVERSION_TAG
      See Also:
    • IGNORE_TAG

      private static final String IGNORE_TAG
      See Also:
    • KEEP_CASE_TAG

      private static final String KEEP_CASE_TAG
      See Also:
    • COMPLEX_PREFIXES_TAG

      private static final String COMPLEX_PREFIXES_TAG
      See Also:
    • COMPOUND_RULE_TAG

      private static final String COMPOUND_RULE_TAG
      See Also:
    • COMPOUND_PATTERN_TAG

      private static final String COMPOUND_PATTERN_TAG
      See Also:
    • MORPHOLOGY_ALIAS_TAG

      private static final String MORPHOLOGY_ALIAS_TAG
      See Also:
    • BREAK_TAG

      private static final String BREAK_TAG
      See Also:
    • LANGUAGE_TAG

      private static final String LANGUAGE_TAG
      See Also:
    • WARNING_TAG

      private static final String WARNING_TAG
      See Also:
    • FORBID_WARNING_TAG

      private static final String FORBID_WARNING_TAG
      See Also:
    • CHECK_SHARPS_TAG

      private static final String CHECK_SHARPS_TAG
      See Also:
    • COMPOUND_ROOT_TAG

      private static final String COMPOUND_ROOT_TAG
      See Also:
    • FORCE_UPPER_CASE_TAG

      private static final String FORCE_UPPER_CASE_TAG
      See Also:
    • COMPOUND_MORE_SUFFIXES_TAG

      private static final String COMPOUND_MORE_SUFFIXES_TAG
      See Also:
    • SIMPLIFIED_TRIPLE_TAG

      private static final String SIMPLIFIED_TRIPLE_TAG
      See Also:
    • SYLLABLE_NUMBER_TAG

      private static final String SYLLABLE_NUMBER_TAG
      See Also:
    • LEMMA_PRESENT_TAG

      private static final String LEMMA_PRESENT_TAG
      See Also:
    • COMPOUND_SYLLABLE_TAG

      private static final String COMPOUND_SYLLABLE_TAG
      See Also:
    • CHECK_COMPOUND_REP_TAG

      private static final String CHECK_COMPOUND_REP_TAG
      See Also:
    • REPLACEMENT_TAG

      static final String REPLACEMENT_TAG
      The suggestion table whose replacements CHECKCOMPOUNDREP applies to compounds.
      See Also:
    • PHONETIC_FIELD

      static final String PHONETIC_FIELD
      The word-list field that lists a misspelling of its entry.
      See Also:
    • COMPOUND_PART_FIELD

      static final String COMPOUND_PART_FIELD
      Field prefix of a compound part in an analysis.
      See Also:
    • SHARP_S

      static final String SHARP_S
      The sharp s, which CHECKSHARPS relates to a double s.
      See Also:
    • DOUBLE_S

      static final String DOUBLE_S
      The lowercase double s that a sharp s expands to.
      See Also:
    • DOUBLE_CAPITAL_S

      static final String DOUBLE_CAPITAL_S
      The uppercase double s that an all-uppercase sharp s entry is written with.
      See Also:
    • BREAK_START_ANCHOR

      static final String BREAK_START_ANCHOR
      The BREAK anchor that binds a separator to the start of the word.
      See Also:
    • BREAK_END_ANCHOR

      static final String BREAK_END_ANCHOR
      The BREAK anchor that binds a separator to the end of the word.
      See Also:
    • DOTTED_CAPITAL_I

      static final String DOTTED_CAPITAL_I
      The dotted capital I, the uppercase of i in the Turkic languages.
      See Also:
    • STEM_FIELD

      private static final String STEM_FIELD
      See Also:
    • SURFACE_PREFIX_FIELD

      private static final String SURFACE_PREFIX_FIELD
      See Also:
    • DERIVATIONAL_SUFFIX_FIELD

      private static final String DERIVATIONAL_SUFFIX_FIELD
      See Also:
    • FLAG_FIELD

      private static final String FLAG_FIELD
      See Also:
    • DEFAULT_WORD_BREAKS

      private static final List<HunspellDictionary.WordBreak> DEFAULT_WORD_BREAKS
      The separators used when the affix file declares no BREAK table: a hyphen inside the word, at its start, and at its end.
    • COMMENT_PREFIX

      private static final String COMMENT_PREFIX
      Prefix used by comment lines.
      See Also:
    • SET_TAG

      private static final String SET_TAG
      The affix-file directive that declares the character encoding.
      See Also:
    • SET_PREFIX

      private static final String SET_PREFIX
      The SET directive followed by a space.
      See Also:
    • SET_TAB_PREFIX

      private static final String SET_TAB_PREFIX
      The SET directive followed by a tab.
      See Also:
    • NO_MATERIAL

      static final String NO_MATERIAL
      The affix format's marker for absent strip or affix material.
      See Also:
    • MAX_NUMERIC_FLAG

      private static final int MAX_NUMERIC_FLAG
      Largest flag value permitted by FLAG 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_FLAGS
      The 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_MIN
      Largest COMPOUNDMIN value that can be doubled without overflow.
      See Also:
    • entries

      private final Map<String,List<int[]>> entries
    • hiddenEntries

      private final Map<String,List<int[]>> hiddenEntries
      The capitalized forms of mixed-case and flagged all-uppercase entries, kept as hidden homonyms so that all-uppercase input matches them. Keyed like entries, sharing the entry flag arrays.
    • suffixesByLast

      private final HunspellDictionary.BoundaryIndex suffixesByLast
    • suffixesWithoutMaterial

      private final List<HunspellDictionary.Affix> suffixesWithoutMaterial
    • prefixesByFirst

      private final HunspellDictionary.BoundaryIndex prefixesByFirst
    • prefixesWithoutMaterial

      private final List<HunspellDictionary.Affix> 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

      private final String ignoredCharacters
    • inputConversion

      private final HunspellConversion inputConversion
    • outputConversion

      private final HunspellConversion outputConversion
    • morphology

      private final Map<int[],List<String>> 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

      private final List<HunspellCompoundRule> compoundRules
    • compoundPatterns

      private final List<HunspellDictionary.CompoundPattern> 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

      private final HunspellConversion replacements
    • maxCompoundSyllables

      private final int maxCompoundSyllables
    • compoundVowels

      private final String compoundVowels
    • wordBreaks

      private final List<HunspellDictionary.WordBreak> wordBreaks
    • unsupportedDirectives

      private final List<HunspellDictionary.UnsupportedDirective> unsupportedDirectives
    • longestSpacedForm

      private final int longestSpacedForm
  • Constructor Details

  • 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:
      false if 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

      public static HunspellDictionary load(Path affixFile, Path dictionaryFile) throws IOException
      Loads affix and dictionary files using HunspellDictionary.LoadMode.STRICT.
      Parameters:
      affixFile - The .aff affix file. Must not be null.
      dictionaryFile - The .dic word list. Must not be null.
      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 is null.
    • 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 .aff affix file. Must not be null.
      dictionaryFile - The .dic word list. Must not be null.
      mode - The loading policy. Must not be null.
      Returns:
      The loaded dictionary. Never null.
      Throws:
      IOException - Thrown if reading fails, a file exceeds MAX_STREAM_BYTES, a file is malformed, or HunspellDictionary.LoadMode.STRICT encounters an unsupported affix directive.
      IllegalArgumentException - Thrown if a parameter is null.
    • load

      public static HunspellDictionary load(InputStream affixStream, InputStream dictionaryStream) throws IOException
      Loads affix and dictionary streams using HunspellDictionary.LoadMode.STRICT. Each stream is buffered up to MAX_STREAM_BYTES bytes; a larger stream fails with IOException.
      Parameters:
      affixStream - The .aff affix content. Must not be null. Not closed.
      dictionaryStream - The .dic word list content. Must not be null. Not closed.
      Returns:
      The loaded dictionary. Never null.
      Throws:
      IOException - Thrown if reading fails, a stream exceeds MAX_STREAM_BYTES, the content is malformed, or an affix directive is unsupported.
      IllegalArgumentException - Thrown if a parameter is null.
    • 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 to MAX_STREAM_BYTES bytes.
      Parameters:
      affixStream - The .aff affix content. Must not be null. Not closed.
      dictionaryStream - The .dic word list content. Must not be null. Not closed.
      mode - The loading policy. Must not be null.
      Returns:
      The loaded dictionary. Never null. Under HunspellDictionary.LoadMode.ALLOW_PARTIAL it reports skipped directives through getUnsupportedDirectives().
      Throws:
      IOException - Thrown if reading fails, a stream exceeds MAX_STREAM_BYTES, the content is malformed, or HunspellDictionary.LoadMode.STRICT encounters an unsupported affix directive.
      IllegalArgumentException - Thrown if a parameter is null.
    • getUnsupportedDirectives

      public List<HunspellDictionary.UnsupportedDirective> 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 a SET UTF-8 declaration. 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

      private static boolean hasAffixDirective(byte[] bytes, String directive)
      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

      private static boolean isIgnoredAffixDirective(String directive)
      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

      private static void maskInlineComment(byte[] bytes, int from, int to, String directive)
      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

      private static int firstCommentField(byte[] bytes, List<int[]> fields, String directive)
      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

      private static boolean isAffixHeader(byte[] bytes, List<int[]> fields)
      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

      private static boolean isParsedAffixDirective(String directive)
      Tests whether a directive is supported by the parser.
      Parameters:
      directive - The directive name.
      Returns:
      Whether the parser processes the directive's fields.
    • normalizeUtf8ByteFlags

      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. Hunspell's default and long flag 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 by SET.
      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-8 or FLAG num is 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

      private static boolean isSingleFlagDirective(String directive)
      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

      private static String asciiField(byte[] bytes, int from, int to)
      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

      private static String decode(byte[] bytes, Charset charset, String label) throws IOException
      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 if bytes are invalid in charset.
    • readBounded

      static byte[] readBounded(InputStream in, int maxBytes, String label) throws IOException
      Reads an input stream into a byte array, failing when more than maxBytes arrive.
      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 exceeds maxBytes.
    • lookup

      List<int[]> lookup(String word)
      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 null when absent.
    • lookup

      List<int[]> lookup(String word, boolean includeHidden)
      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 null when absent.
    • immutableFlagSets

      private static Map<String,List<int[]>> immutableFlagSets(Map<String,List<int[]>> flagSets)
      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

      static HunspellDictionary.CaseType caseType(String word)
      Classifies a word's capitalization, judging the initial by the first character.
      Parameters:
      word - The word to classify.
      Returns:
      The capitalization class.
    • hiddenCapitalizedEntries

      private Map<String,List<int[]>> 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 as EBOOKS for eBook or ACME'S for ACME matches them. A form that is itself listed is not added, and forbidden entries contribute none.
      Parameters:
      listed - The words mapped to the flag sets of their entries.
      Returns:
      The capitalized forms mapped to the flag sets they share with their entries.
    • homonyms

      private List<int[]> homonyms(String root)
      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

      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.
      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. Never null.
      Returns:
      the strip-only suffix rules, applicable to any word
    • prefixesStartingWith

      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.
      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. Never null.
      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

      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

      Returns the word separators with their start and end anchors.
      Returns:
      the word separators with their start and end anchors
    • compoundUnits

      int compoundUnits(int[] flags, List<HunspellDictionary.Affix> affixes)
      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

      private int countSyllables(String text)
      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 flags F, G, and H, 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:
      true if the entry carries one of the hardwired opening flags and is not forbidden.
    • compoundCaseAllowed

      boolean compoundCaseAllowed(int[] flags, String word)
      Checks a closing entry's capitalization requirement.
      Parameters:
      flags - The closing entry flags.
      word - The input compound.
      Returns:
      Whether FORCEUCASE permits the input.
    • rejectsCompoundReplacement

      boolean rejectsCompoundReplacement(String word, Predicate<String> recognized)
      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

      boolean acceptsRulePart(int[] flags, boolean last, HunspellDictionary.Affix... affixes)
      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 least 1.
      Returns:
      the smallest length a compound part may have
    • compoundWordMax

      int compoundWordMax()
      Returns the largest number of parts a compound may have. 0 is unbounded.
      Returns:
      the largest number of parts a compound may have
    • checkCompoundDup

      boolean checkCompoundDup()
      Returns whether CHECKCOMPOUNDDUP forbids a part repeating its neighbor.
      Returns:
      whether CHECKCOMPOUNDDUP forbids a part repeating its neighbor
    • checkCompoundCase

      boolean checkCompoundCase()
      Returns whether CHECKCOMPOUNDCASE forbids uppercase at part boundaries.
      Returns:
      whether CHECKCOMPOUNDCASE forbids uppercase at part boundaries
    • checkCompoundTriple

      boolean checkCompoundTriple()
      Returns whether CHECKCOMPOUNDTRIPLE forbids triple letters at boundaries.
      Returns:
      whether CHECKCOMPOUNDTRIPLE forbids triple letters at boundaries
    • fullStrip

      boolean fullStrip()
      Returns whether FULLSTRIP allows an affix rule to strip a whole stem.
      Returns:
      whether FULLSTRIP allows an affix rule to strip a whole stem
    • inputForm

      String inputForm(String word)
      Applies input conversion followed by ignored-character removal.
      Parameters:
      word - The supplied word.
      Returns:
      The dictionary lookup form.
    • outputForm

      String outputForm(String stem)
      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

      String lowerCase(String text)
      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

      List<String> morphologicalStems(String root, int[] flags, HunspellDictionary.Affix... affixes)
      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 its fl: flag field otherwise; after the entry fields, an entry without fields contributes that prefix's fl: 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

      private String fieldValue(List<String> fields, String tag, String fallback)
      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

      private boolean hasField(List<String> fields, String tag)
      Checks for a morphological field.
      Parameters:
      fields - The expanded fields.
      tag - The tag including the colon.
      Returns:
      Whether the tag is present.
    • removeIgnored

      private static String removeIgnored(String text, String ignored)
      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

      private int positionalFlag(HunspellDictionary.CompoundPosition position)
      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 0 when undeclared.
    • mayStand

      boolean mayStand(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. An ONLYINCOMPOUND entry is valid here, while a NEEDAFFIX entry still requires an affix.
      Parameters:
      flagSets - The word's flag sets from lookup(String).
      position - The part's place in the compound.
      Returns:
      true if the word may stand at the position.
    • mayStand

      boolean mayStand(int[] flags, HunspellDictionary.CompoundPosition position)
      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:
      true if 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 from lookup(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, from affixAdmits(Affix, CompoundPosition).
      Returns:
      true if 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 of supportsPart(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:
      true if the entry permits the affixed form at the position.
    • affixAdmits

      boolean affixAdmits(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. 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:
      true if the affixed form may stand at the position.
    • permitsInside

      boolean permitsInside(HunspellDictionary.Affix affix)
      Checks whether an affix may sit at a compound-internal boundary: it carries the COMPOUNDPERMITFLAG among 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:
      true if the affix may face another part.
    • forbidsInCompound

      boolean forbidsInCompound(HunspellDictionary.Affix affix)
      Checks whether an affix bars its derived form from compounds altogether: it carries the COMPOUNDFORBIDFLAG among its continuation classes.
      Parameters:
      affix - The affix rule applied to the part.
      Returns:
      true if the affixed form may not join a compound.
    • forbiddenAtCompoundPosition

      private boolean forbiddenAtCompoundPosition(int[] flags, HunspellDictionary.CompoundPosition position)
      Checks whether an entry marked with COMPOUNDFORBIDFLAG is 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:
      true if the entry may not stand at the position.
    • firstForbidden

      boolean firstForbidden(List<int[]> flagSets)
      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 from lookup(String), in list order.
      Returns:
      true if the first homonym carries the forbidden-word flag.
    • forbidsAffixed

      boolean forbidsAffixed(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.
      Parameters:
      flagSets - The stem's flag sets from lookup(String).
      flag - The removed affix's flag.
      Returns:
      true if 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:
      true if the entry forbids the affixed spelling.
    • forbidsCompoundStart

      boolean forbidsCompoundStart(List<int[]> flagSets)
      Checks whether a spelling may not open a compound part sequence: its first listed homonym carries COMPOUNDFORBIDFLAG, which applies to every part but the last and overrides affixed readings of the same spelling.
      Parameters:
      flagSets - The part's flag sets from lookup(String), in list order.
      Returns:
      true if the spelling is barred from non-final compound positions.
    • upperCaseInitial

      String upperCaseInitial(String word)
      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

      String lowerCaseInitial(String word)
      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

      static boolean hasFlag(List<int[]> flagSets, int flag)
      Checks whether any of a word's flag sets carries a flag.
      Parameters:
      flagSets - The flag sets from lookup(String).
      flag - The flag to look for.
      Returns:
      true if 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 as 0, is carried by no entry.
      Parameters:
      flags - One entry's flag set.
      flag - The flag to look for.
      Returns:
      true if the set contains the flag.
    • validStandalone

      boolean validStandalone(List<int[]> flagSets)
      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 marked NEEDAFFIX is a virtual stem that exists only to be affixed, one marked ONLYINCOMPOUND appears only inside compounds, and one marked FORBIDDENWORD is listed to be blocked; none of them is a word by itself.
      Parameters:
      flagSets - The word's flag sets from lookup(String).
      Returns:
      true if 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 in validStandalone(List).
      Parameters:
      flags - One entry's flag set.
      Returns:
      true if the entry is a word by itself.
    • supports

      boolean supports(List<int[]> flagSets, int flag)
      Checks whether some homonym supports an affix analysis: its flag set carries the affix's flag and is neither compound-only nor forbidden. A NEEDAFFIX set does support the analysis, because the removed affix is exactly what the virtual stem needs.
      Parameters:
      flagSets - The stem's flag sets from lookup(String).
      flag - The removed affix's flag.
      Returns:
      true if 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 of supports(List, int).
      Parameters:
      flags - One entry's flag set.
      flag - The removed affix's flag.
      Returns:
      true if 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 from lookup(String).
      prefix - The removed prefix.
      suffix - The removed suffix.
      Returns:
      true if 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 of supportsCrossProduct(List, Affix, Affix).
      Parameters:
      flags - One entry's flag set.
      prefix - The removed prefix.
      suffix - The removed suffix.
      Returns:
      true if 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

      boolean needsFurtherAffix(HunspellDictionary.Affix affix)
      Checks whether a form made with this affix alone is still a virtual stem: the affix carries the NEEDAFFIX flag among its continuation classes, so a further affix must join before the form is a word.
      Parameters:
      affix - The affix rule to inspect.
      Returns:
      true if the affix alone does not finish a word.
    • compoundOnly

      boolean compoundOnly(HunspellDictionary.Affix affix)
      Checks whether an affix applies only inside compounds: it carries the ONLYINCOMPOUND flag among its continuation classes.
      Parameters:
      affix - The affix rule to inspect.
      Returns:
      true if the affix never applies to a standalone word.
    • circumfixOnly

      boolean circumfixOnly(HunspellDictionary.Affix affix)
      Checks whether an affix is one half of a circumfix: it carries the CIRCUMFIX flag among its continuation classes, so it is only valid on a word that also carries a circumfix-marked affix of the other kind, the German ge...t participle being the model.
      Parameters:
      affix - The affix rule to inspect.
      Returns:
      true if the affix never applies without its other half.
    • declaredCharset

      private static Charset declaredCharset(byte[] affixBytes) throws IOException
      Finds the SET declaration 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

      private static HunspellDictionary.AffixFile parseAffix(String content) throws IOException
      Parses the affix file: the FLAG declaration, the AF flag alias table, the compound and blocking flag declarations, and the PFX and SFX blocks. 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 as COMPOUNDFLAG or NEEDAFFIX.
      Parameters:
      fields - The line's fields.
      line - The one-based source line.
      result - The affix file under construction.
      Returns:
      true if 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:
      true if 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

      private static HunspellDictionary.FlagMode readFlagMode(String[][] fieldsByLine) throws IOException
      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

      private static int parseValue(String[] fields, int lineNumber) throws IOException
      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 one PFX or SFX block: 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 /flags run, 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

      private static List<List<String>> readMorphologyAliases(String[][] lines) throws IOException
      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

      private static boolean isCount(String line)
      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:
      true if 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 numeric AF alias 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 fit mode.
    • unescapedSlash

      private static int unescapedSlash(String line)
      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 -1 when the entry has no flags.
    • morphologyIndex

      private static int morphologyIndex(String line)
      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 as po: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 -1 if 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:
      true if c separates fields in the word-list format.
    • trim

      private static String trim(String text)
      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 in char mode, character pairs packed into one int in long mode, and comma-separated decimal numbers in num mode.
      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

      private static String[] splitLines(String content)
      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.