table of contents
- NAME
- DESCRIPTION
- Dictionary file
- Personal dictionary file
- Short example
- AFFIX FILE GENERAL OPTIONS
- AFFIX FILE OPTIONS FOR SUGGESTION
- OPTIONS FOR COMPOUNDING
- AFFIX FILE OPTIONS FOR AFFIX CREATION
- AFFIX FILE OTHER OPTIONS
- Morphological analysis
- Optional data fields
- Twofold suffix stripping
- Extended affix classes
- Homonyms
- Prefix--suffix dependencies
- Circumfix
- Compounds
- Unicode character encoding
- Conversion of aspell dictionaries
- SEE ALSO
| hunspell(5) | File Formats Manual | hunspell(5) |
NAME¶
hunspell - format of Hunspell dictionaries and affix files
DESCRIPTION¶
Hunspell(1) requires two files to define the way a language is being spell-checked: a dictionary file containing words and applicable flags, and an affix file that specifies how these flags control spell checking. The personal dictionary file is an optional third file.
Dictionary file¶
A dictionary file (*.dic) contains a list of words, one per line. The first line of a dictionary (except personal dictionaries) contains the approximate word count (for optimal hash memory size). Each word may optionally be followed by a slash ("/") and one or more flags, which represent the word's attributes (for example, affixes).
Note: Dictionary words can also contain slashes if escaped as "\/".
It is worth adding not only individual words but also word pairs to the dictionary, to get correct suggestions for common misspellings that are missing a space, as in the following example for the bad "alot" and "inspite" (see also "REP" and the "ph:" field for correct suggestions for common misspellings):
3 word a lot in spite
Personal dictionary file¶
Personal dictionaries are simple word lists. An asterisk in the first character position marks the entry as forbidden. A second word separated by a slash sets the affixation.
foo Foo/Simpson *bar
In this example, "foo" and "Foo" are personal words, plus Foo will be recognized with affixes of Simpson (Foo's etc.) and bar is a forbidden word.
Short example¶
Dictionary file:
3 hello try/B work/AB
The flags B and A specify attributes of these words.
Affix file:
SET UTF-8 TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ' REP 2 REP f ph REP ph f PFX A Y 1 PFX A 0 re . SFX B Y 2 SFX B 0 ed [^y] SFX B y ied y
In the affix file, prefix A and suffix B have been defined. Flag A defines a `re-' prefix. Class B defines two `-ed' suffixes. First B suffix can be added to a word if the last character of the word isn't `y'. Second suffix can be added to the words terminated with an `y'.
All accepted words with this dictionary and affix combination are: "hello", "try", "tried", "work", "worked", "rework", "reworked".
AFFIX FILE GENERAL OPTIONS¶
Hunspell source distribution contains more than 80 examples for option usage.
- SET encoding
- Set character encoding of words and morphemes in affix and dictionary files. Possible values: UTF-8, ISO8859-1 - ISO8859-10, ISO8859-13 - ISO8859-15, KOI8-R, KOI8-U, cp1251, ISCII-DEVANAGARI.
SET UTF-8
- FLAG value
- Set flag type. Default type is the extended ASCII (8-bit) character. `UTF-8' parameter sets UTF-8 encoded Unicode character flags. The `long' value sets the double extended ASCII character flag type; the `num' value sets the decimal number flag type. Decimal flags are numbered from 1 to 65000 and are separated by commas in flag fields.
FLAG long
- COMPLEXPREFIXES
- Set twofold prefix stripping (but single suffix stripping), e.g. for morphologically complex languages with a right-to-left writing system.
- LANG langcode
- Set language code for language-specific functions of Hunspell. Use it to activate special casing of Azeri (LANG az), Turkish (LANG tr) and Crimean Tatar (LANG crh), and the non-generalized syllable-counting compounding rules of Hungarian (LANG hu).
- IGNORE characters
- Set characters to ignore in dictionary words, affixes and input words. Useful for optional characters such as Arabic (harakat) or Hebrew (niqqud) diacritical marks (see the tests/ignore.* test dictionary in the Hunspell distribution).
- AF number_of_flag_vector_aliases
- AF flag_vector
- Hunspell can substitute affix flag sets with ordinal numbers in affix rules (alias compression, see makealias tool). First example with alias compression:
3 hello try/1 work/2
AF definitions in the affix file:
AF 2 AF A AF AB
It is equivalent to the following dic file:
3 hello try/A work/AB
See also tests/alias* examples of the source distribution.
Note I: If the affix file contains the FLAG parameter, define it before the AF definitions.
Note II: Use the makealias utility in the Hunspell distribution to compress aff and dic files.
- AM number_of_morphological_aliases
- AM morphological_fields
- Hunspell can also substitute morphological data with ordinal numbers in affix rules (alias compression). See tests/alias* examples.
AFFIX FILE OPTIONS FOR SUGGESTION¶
Suggestion parameters can optimize Hunspell's default n-gram (similarity search through the dictionary words based on common 1-, 2-, 3-, and 4-character sequences), character-swap and deletion suggestions. REP is recommended for fixing typical and especially bad language-specific spelling errors, because REP suggestions have the highest priority in the suggestion list. PHONE is for languages whose orthography is not pronunciation-based.
For short common misspellings, it's important to use the ph: field (see later) to give the best suggestions.
- KEY characters_separated_by_vertical_line_optionally
- Hunspell searches for and suggests words in which a single character has been replaced by a neighbouring KEY character. Non-neighbouring characters in the KEY string are separated by vertical line characters. Suggested KEY parameters for QWERTY and Dvorak keyboard layouts:
KEY qwertyuiop|asdfghjkl|zxcvbnm KEY pyfgcrl|aeouidhtns|qjkxbmwvz
Using the first QWERTY layout, Hunspell suggests "nude" and "node" for "*nide". A character may have more neighbors, too:
KEY qwertzuop|yxcvbnm|qaw|say|wse|dsx|sy|edr|fdc|dx|rft|gfv|fc|tgz|hgb|gv|zhu|jhn|hb|uji|kjm|jn|iko|lkm
- TRY characters
- Hunspell can suggest correct word forms when they differ from the bad input word by one TRY character. The parameter of TRY is case-sensitive.
- NOSUGGEST flag
- Words flagged with NOSUGGEST are not suggested (but are still accepted when typed correctly). Proposed for vulgar and obscene words (see also SUBSTANDARD).
- MAXCPDSUGS num
- Set the maximum number of suggested compound words generated by compound rules. The number of suggested compound words from the same 1-character-distance type may exceed this.
- MAXNGRAMSUGS num
- Set the maximum number of n-gram suggestions. A value of 0 switches off n-gram suggestions (see also MAXDIFF).
- MAXDIFF [0-10]
- Set the similarity factor for the n-gram based suggestions (5 = default value; 0 = fewer n-gram suggestions, but min. 1; 10 = MAXNGRAMSUGS n-gram suggestions).
- ONLYMAXDIFF
- Remove all bad n-gram suggestions (default mode keeps one, see MAXDIFF).
- NOSPLITSUGS
- Disable word suggestions with spaces.
- SUGSWITHDOTS
- Add dot(s) to suggestions, if input word terminates in dot(s). (Not for LibreOffice dictionaries, because LibreOffice has an automatic dot expansion mechanism.)
- REP number_of_replacement_definitions
- REP what replacement
- This table specifies modifications to try first. The first REP line is the header of the table, followed by one or more REP data lines. With this table, Hunspell can suggest correct forms for typical spelling mistakes where the incorrect form differs by more than one letter from the correct form (see also "ph:"). The search string supports the regex boundary anchors (^ and $). For example, a possible English replacement table definition to handle misspelled consonants:
REP 5 REP f ph REP ph f REP tion$ shun REP ^cooccurr co-occurr REP ^alot$ a_lot
Note I: It's very useful to define replacements for the most typical one-character mistakes, too: with REP you can add higher priority to a subset of the TRY suggestions (suggestion list begins with the REP suggestions).
Note II: To suggest separated words, specify spaces as underscores:
REP 1 REP onetwothree one_two_three
Note III: The replacement table can be used for stricter compound word checking with the CHECKCOMPOUNDREP option.
- MAP number_of_map_definitions
- MAP string_of_related_chars_or_parenthesized_character_sequences
- We can define language-dependent information on characters and character
sequences that should be considered related (i.e. nearer than other chars
not in the set) in the affix file (.aff) by a map table. With this table,
Hunspell can suggest the right forms for words, which incorrectly choose
the wrong letter or letter groups from a related set more than once in a
word (see REP).
For example, a possible mapping could be for the German umlauted ü versus the regular u; the word Frühstück really should be written with umlauted u's and not regular ones.
MAP 1 MAP uü
Use parenthesized groups for character sequences (eg. for composed Unicode characters):
MAP 3
MAP ß(ss) (character sequence)
MAP fi(fi) ("fi" compatibility characters for Unicode fi ligature)
MAP (ọ́)o (composed Unicode character: ó with bottom dot)
- PHONE number_of_phone_definitions
- PHONE what replacement
- PHONE uses a table-driven phonetic transcription algorithm borrowed from Aspell. It is useful for languages whose orthography is not pronunciation-based. You can add a full alphabet conversion and other rules for converting special letter sequences. For detailed documentation see http://aspell.net/man-html/Phonetic-Code.html. Note: Multibyte UTF-8 characters do not yet work with bracket expressions. Dash range expressions still operate on single bytes, not UTF-8 characters.
- WARN flag
- This flag is for rare words, which are also often spelling mistakes, see option -r of command line Hunspell and FORBIDWARN.
- FORBIDWARN
- Words with flag WARN aren't accepted by the spell checker using this parameter.
OPTIONS FOR COMPOUNDING¶
- BREAK number_of_break_definitions
- BREAK character_or_character_sequence
- Define new break points for splitting words and checking word parts separately. Use ^ and $ to delete characters at the start and end of the word. Rationale: useful for compounding with joining characters or strings (for example, the hyphen in English and German or the hyphen and n-dash in Hungarian). Dashes are often bad break points for tokenization, because compounds with dashes may also contain invalid parts. With BREAK, Hunspell can check both sides of these compounds, breaking the words at dashes and n-dashes:
BREAK 2 BREAK - BREAK -- # n-dash
Breaks are recursive, so foo-bar, bar-foo and foo-foo--bar-bar would all be valid compounds. Note: The default word break of Hunspell is equivalent to the following BREAK definition:
BREAK 3 BREAK - BREAK ^- BREAK -$
With this BREAK definition, Hunspell doesn't accept the "-word" and "word-" forms:
BREAK 1 BREAK -
Switching off the default values:
BREAK 0
Note II: COMPOUNDRULE is better for handling dashes and other compound joining characters or character strings. Use BREAK if you want to check words with dashes or other joining characters and there is no time or ability to describe precise compound rules with COMPOUNDRULE (COMPOUNDRULE only handles the suffixation of the last word part of a compound word).
Note III: For command-line spell checking of words with extra characters, set the WORDCHARS parameter: WORDCHARS --- (see the tests/break.* example).
- COMPOUNDRULE number_of_compound_definitions
- COMPOUNDRULE compound_pattern
- Define custom compound patterns with a regex-like syntax. The first
COMPOUNDRULE line is a header containing the number of following
COMPOUNDRULE definitions. Compound patterns consist of compound flags,
parentheses, and `*' or `?' meta-characters. A flag followed by `*'
matches a word sequence of 0 or more words flagged with this compound
flag. A flag followed by `?' matches 0 or 1 words flagged with this
compound flag. See the tests/compound*.* examples.
Note: the en_US dictionary of OpenOffice.org uses COMPOUNDRULE for ordinal number recognition (1st, 2nd, 11th, 12th, 22nd, 112th, 1000122nd, etc.).
Note II: With long and numerical flag types, use only parenthesized flags: (1500)*(2000)?
Note III: COMPOUNDRULE flags work completely independently of the compounding mechanisms using COMPOUNDFLAG, COMPOUNDBEGIN, etc. (Use these flags on different word entries.)
- COMPOUNDMIN num
- Minimum length of words used for compounding. Default value is 3 letters.
- MAXCPDSUGS num
- Max Compound Suggestions. Use 0 to disable suggesting from compounds. Default value is unlimited.
- COMPOUNDFLAG flag
- Words flagged with COMPOUNDFLAG may appear in compound words (except when the word is shorter than COMPOUNDMIN). Affixes with COMPOUNDFLAG also permit compounding of affixed words.
- COMPOUNDBEGIN flag
- Words flagged with COMPOUNDBEGIN (or with a flagged affix) may be first elements in compound words.
- COMPOUNDLAST flag
- Words flagged with COMPOUNDLAST (or with a flagged affix) may be last elements in compound words.
- COMPOUNDMIDDLE flag
- Words flagged with COMPOUNDMIDDLE (or with a flagged affix) may be middle elements in compound words.
- ONLYINCOMPOUND flag
- Suffixes flagged with ONLYINCOMPOUND may only appear inside compounds (Fuge-elements in German, fogemorphemes in Swedish). The ONLYINCOMPOUND flag also works on words (see tests/onlyincompound.*). Note: also useful to flag compounding parts which are not correct as a word on their own.
- COMPOUNDPERMITFLAG flag
- Prefixes are allowed at the beginning of compounds, suffixes are allowed at the end of compounds by default. Affixes with COMPOUNDPERMITFLAG may be inside of compounds.
- COMPOUNDFORBIDFLAG flag
- Suffixes with this flag forbid compounding of the affixed word. Dictionary words with this flag are removed from the beginning and middle of compound words, overriding the effect of COMPOUNDPERMITFLAG.
- COMPOUNDMORESUFFIXES
- Allow twofold suffixes within compounds.
- COMPOUNDROOT flag
- The COMPOUNDROOT flag marks compounds in the dictionary (currently only used in the Hungarian language-specific code).
- COMPOUNDWORDMAX number
- Set maximum word count in a compound word. (Default is unlimited.)
- CHECKCOMPOUNDDUP
- Forbid word duplication in compounds (e.g. foofoo).
- CHECKCOMPOUNDREP
- Forbid compounding, if the (usually bad) compound word may be a non-compound word with a REP fault. Useful for languages with `compound friendly' orthography.
- CHECKCOMPOUNDCASE
- Forbid upper case characters at word boundaries in compounds.
- CHECKCOMPOUNDTRIPLE
- Forbid compounding, if compound word contains triple repeating letters (e.g. foo|ox or xo|oof). Bug: missing multi-byte character support in UTF-8 encoding (works only for 7-bit ASCII characters).
- SIMPLIFIEDTRIPLE
- Allow simplified 2-letter forms of the compounds forbidden by CHECKCOMPOUNDTRIPLE. It's useful for Swedish and Norwegian (and for the old German orthography: Schiff|fahrt -> Schiffahrt).
- CHECKCOMPOUNDPATTERN number_of_checkcompoundpattern_definitions
- CHECKCOMPOUNDPATTERN endchars[/flag] beginchars[/flag] [replacement]
- Forbid compounding, if the first word in the compound ends with endchars,
and next word begins with beginchars and (optionally) they have the
requested flags. The optional replacement parameter allows simplified
compound form.
The special "endchars" pattern 0 (zero) limits the rule to the unmodified stems (stems and stems with zero affixes):
CHECKCOMPOUNDPATTERN 0/x /y
Note: COMPOUNDMIN doesn't work correctly with the compound word alternation, so it may need to set COMPOUNDMIN to lower value.
- FORCEUCASE flag
- If the last word part of a compound has the FORCEUCASE flag, it forces capitalization of the whole compound word. E.g. the Dutch word "straat" (street) with the FORCEUCASE flag will be allowed only in capitalized compound forms, according to the Dutch spelling rules for proper names.
- COMPOUNDSYLLABLE max_syllable vowels
- Needed for special compounding rules in Hungarian. The first parameter is the maximum syllable count permitted in a compound when the number of words in the compound exceeds COMPOUNDWORDMAX. The second parameter is the list of vowels (used for counting syllables).
- SYLLABLENUM flags
- Needed for special compounding rules in Hungarian.
AFFIX FILE OPTIONS FOR AFFIX CREATION¶
- PFX flag cross_product number
- PFX flag stripping prefix [condition [morphological_fields...]]
- SFX flag cross_product number
- SFX flag stripping suffix [condition [morphological_fields...]]
- An affix is either a prefix or a suffix attached to root words to form
other words. Affix classes can be defined with an arbitrary number of
affix rules. Affix classes are identified by affix flags. The first line
of an affix class definition is the header. The fields of an affix class
header:
(0) Option name (PFX or SFX)
(1) Flag (name of the affix class)
(2) Cross product (permission to combine prefixes and suffixes). Possible values: Y (yes) or N (no)
(3) Line count of the following rules.
Fields of an affix rules:
(0) Option name
(1) Flag
(2) stripping characters from beginning (at prefix rules) or end (at suffix rules) of the word
(3) affix (optionally with flags of continuation classes, separated by a slash)
(4) condition.
Zero stripping or affix is indicated by zero. A zero condition is indicated by a dot. The condition is a simplified, regular-expression-like pattern that must be met before the affix can be applied. (A dot matches an arbitrary character. Characters in brackets match any character from the bracketed subset. A dash has no special meaning, but a circumflex (^) immediately after the opening bracket inverts the character set.)
(5) Optional morphological fields separated by spaces or tabs.
AFFIX FILE OTHER OPTIONS¶
- CIRCUMFIX flag
- An affix flagged with CIRCUMFIX may be applied to a word only when the word also has a prefix with CIRCUMFIX, and vice versa (see the circumfix.* test files in the source distribution).
- FORBIDDENWORD flag
- This flag marks a forbidden word form. Because affixed forms are also forbidden, we can subtract a subset from the set of accepted affixed and compound words. Note: useful for forbidding erroneous words generated by the compounding mechanism.
- FULLSTRIP
- With FULLSTRIP, affix rules can strip the full word, not only all but one character, before adding the affixes (see the fullstrip.* test files in the source distribution). Note: even without FULLSTRIP, conditions may match the full word length.
- KEEPCASE flag
- Forbid uppercased and capitalized forms of words flagged with KEEPCASE.
Useful for special orthographies (measurements and currency often keep
their case even in uppercased texts) and writing systems (e.g. keeping the
lower case of IPA characters). Also useful for words that would otherwise
be erroneously written in the wrong case.
Note: With CHECKSHARPS declaration, words with sharp s and KEEPCASE flag may be capitalized and uppercased, but uppercased forms of these words may not contain sharp s, only SS. See germancompounding example in the tests directory of the Hunspell distribution.
- ICONV number_of_ICONV_definitions
- ICONV pattern pattern2
- Define input conversion table. Use underscore '_' to represent the last
character of the string. For e.g. if you need to change <200D> to
<FFF0> only if it appears at the end of the word, then ...
ICONV <200D>_ <FFF0>
Note: useful to convert one type of quote to another one, or change ligature.
- OCONV number_of_OCONV_definitions
- OCONV pattern pattern2
- Define output conversion table.
- LEMMA_PRESENT flag
- Deprecated. Use "st:" field instead of LEMMA_PRESENT.
- NEEDAFFIX flag
- This flag marks virtual stems in the dictionary: words only valid when affixed (except when the dictionary word has a homonym or a zero affix). NEEDAFFIX also works with prefixes and prefix + suffix combinations (see tests/needaffix5.*).
- PSEUDOROOT flag
- Deprecated. (Former name of the NEEDAFFIX option.)
- SUBSTANDARD flag
- The SUBSTANDARD flag marks affix rules and dictionary words (allomorphs) that are not used in morphological generation, and root words to be removed from suggestions. See also NOSUGGEST.
- WORDCHARS characters
- WORDCHARS extends the tokenizer of the Hunspell command-line interface with additional word characters. For example, the dot, dash, n-dash, digits, and percent sign are word characters in Hungarian.
- CHECKSHARPS
- SS letter pair in uppercased (German) words may be upper case sharp s (ß). Hunspell can handle this special casing with the CHECKSHARPS declaration (see also KEEPCASE flag and tests/germancompounding example) in both spelling and suggestion.
Morphological analysis¶
Hunspell's dictionary items and affix rules may have optional space or tabulator separated morphological description fields, started with 3-character (two letters and a colon) field IDs:
word/flags po:noun is:nom
Example: We define a simple resource with morphological informations, a derivative suffix (ds:) and a part of speech category (po:):
Affix file:
SFX X Y 1
SFX X 0 able . ds:able
Dictionary file:
drink/X po:verb
Test file:
drink
drinkable
Test:
$ analyze test.aff test.dic test.txt
> drink
analyze(drink) = po:verb
stem(drink) = po:verb
> drinkable
analyze(drinkable) = po:verb ds:able
stem(drinkable) = drinkable
You can see in the example, that the analyzer concatenates the morphological fields in item and arrangement style.
Optional data fields¶
Default morphological and other IDs (used in suggestion, stemming and morphological generation):
- ph:
- Alternative transliteration for better suggestions, i.e. for misspellings
related to the special orthography and pronunciation of the word. This is
the best way to handle common misspellings, so it is worth adding a ph:
field to the most affected few thousand dictionary words (or word pairs
etc.) to get correct suggestions for their misspellings.
For example:
Wednesday ph:wendsay ph:wensday Marseille ph:maarsayl
Hunspell adds all ph: transliterations to the inner REP table, so it will always suggest the correct word for the specified misspellings with the highest priority.
The previous example is equivalent to the following REP definition:
REP 6 REP wendsay Wednesday REP Wendsay Wednesday REP wensday Wednesday REP Wensday Wednesday REP maarsayl Marseille REP Maarsayl Marseille
The asterisk at the end of the ph: pattern means stripping the terminating character both from the pattern and the word in the associated REP rule:
pretty ph:prity*
will result
REP 1 REP prit prett
REP rule, resulting in the following correct suggestions:
*prity -> pretty *pritier -> prettier *pritiest -> prettiest
Moreover, ph: fields can handle suggestions with more than two words, also different suggestions for the same misspelling:
do not know ph:dunno don't know ph:dunno
results
*dunno -> do not know, don't know
Note: if available, ph: is used in n-gram similarity, too.
The ASCII arrow "->" in a ph: pattern means a REP rule (see REP), creating an arbitrary replacement rule associated with the dictionary item:
happy/B ph:hepy ph:hepi->happi
results
*hepy -> happy *hepiest -> happiest
- st:
- Stem. Optional: the default stem is the dictionary item in morphological analysis. The stem field is useful for virtual stems (dictionary words with the NEEDAFFIX flag) and for morphological exceptions, in place of new single-use morphological rules.
feet st:foot is:plural mice st:mouse is:plural teeth st:tooth is:plural
Word forms with multiple stems need multiple dictionary items:
lay po:verb st:lie is:past_2 lay po:verb is:present lay po:noun
- al:
- Allomorph(s). A dictionary item is the stem of its allomorphs. Morphological generation needs stem, allomorph and affix fields.
sing al:sang al:sung sang st:sing sung st:sing
- po:
- Part of speech category.
- ds:
- Derivational suffix(es). Stemming doesn't remove derivational suffixes.
Morphological generation depends on the order of the suffix fields.
In affix rules:
SFX Y Y 1 SFX Y 0 ly . ds:ly_adj
In the dictionary:
ably st:able ds:ly_adj able al:ably
- is:
- Inflectional suffix(es). All inflectional suffixes are removed by stemming. Morphological generation depends on the order of the suffix fields.
feet st:foot is:plural
- ts:
- Terminal suffix(es). Terminal suffix fields are inflectional suffix fields
"removed" by additional (not terminal) suffixes.
Useful for zero morphemes and affixes removed by splitting rules.
work/D ts:present
SFX D Y 2 SFX D 0 ed . is:past_1 SFX D 0 ed . is:past_2
Typical example of the terminal suffix is the zero morpheme of the nominative case.
- sp:
- Surface prefix. Temporary solution for adding prefixes to the stems and generated word forms. See tests/morph.* example.
- pa:
- Parts of the compound words. Output fields of morphological analysis for stemming.
- dp:
- Planned: derivational prefix.
- ip:
- Planned: inflectional prefix.
- tp:
- Planned: terminal prefix.
Twofold suffix stripping¶
Ispell's original algorithm strips only one suffix. Hunspell can strip an additional one (or an extra prefix in COMPLEXPREFIXES mode).
Twofold suffix stripping is a significant improvement in handling the immense number of suffixes that characterize agglutinative languages.
A second `s' suffix (affix class Y) will be the continuation class of the suffix `able' in the following example:
SFX Y Y 1
SFX Y 0 s .
SFX X Y 1
SFX X 0 able/Y .
Dictionary file:
drink/X
Test file:
drink
drinkable
drinkables
Test:
$ hunspell -m -d test <test.txt
drink st:drink
drinkable st:drink fl:X
drinkables st:drink fl:X fl:Y
In theory, twofold suffix stripping requires only the square root of the number of suffix rules compared with a one-level Hunspell implementation. In practice, this is what made it possible to elaborate the Hungarian inflectional morphology with twofold suffix stripping.
Extended affix classes¶
Hunspell can handle more than 65000 affix classes. There are three new syntaxes for specifying flags in affix and dictionary files.
FLAG long command sets 2-character flags:
FLAG long
SFX Y1 Y 1
SFX Y1 0 s 1
Dictionary record with the Y1, Z3, F? flags:
foo/Y1Z3F?
FLAG num command sets numerical flags separated by comma:
FLAG num
SFX 65000 Y 1
SFX 65000 0 s 1
Dictionary example:
foo/65000,12,2756
The third one is the Unicode character flags.
Homonyms¶
Hunspell's dictionary can contain repeating elements that are homonyms:
work/A po:verb
work/B po:noun
An affix file:
SFX A Y 1
SFX A 0 s . sf:sg3
SFX B Y 1
SFX B 0 s . is:plur
Test file:
works
Test:
$ hunspell -d test -m <testwords
work st:work po:verb is:sg3
work st:work po:noun is:plur
This feature also gives a way to forbid illegal prefix/suffix combinations.
Prefix--suffix dependencies¶
An interesting side-effect of multi-step stripping is that the appropriate treatment of circumfixes now comes for free. For instance, in Hungarian, superlatives are formed by simultaneous prefixation of leg- and suffixation of -bb to the adjective base. A problem with the one-level architecture is that there is no way to render lexical licensing of particular prefixes and suffixes interdependent, and therefore incorrect forms are recognized as valid, i.e. *legvén = leg + vén `old'. Until the introduction of clusters, a special treatment of the superlative had to be hardwired in the earlier HunSpell code. This may have been legitimate for a single case, but in fact prefix--suffix dependences are ubiquitous in category-changing derivational patterns (cf. English payable, non-payable but *non-pay or drinkable, undrinkable but *undrink). In simple words, here, the prefix un- is legitimate only if the base drink is suffixed with -able. If both these patters are handled by on-line affix rules and affix rules are checked against the base only, there is no way to express this dependency and the system will necessarily over- or undergenerate.
In the next example, suffix class R has a prefix `continuation' class (class P).
PFX P Y 1 PFX P 0 un . [prefix_un]+ SFX S Y 1 SFX S 0 s . +PL SFX Q Y 1 SFX Q 0 s . +3SGV SFX R Y 1 SFX R 0 able/PS . +DER_V_ADJ_ABLE
Dictionary:
2 drink/RQ [verb] drink/S [noun]
Morphological analysis:
> drink drink[verb] drink[noun] > drinks drink[verb]+3SGV drink[noun]+PL > drinkable drink[verb]+DER_V_ADJ_ABLE > drinkables drink[verb]+DER_V_ADJ_ABLE+PL > undrinkable [prefix_un]+drink[verb]+DER_V_ADJ_ABLE > undrinkables [prefix_un]+drink[verb]+DER_V_ADJ_ABLE+PL > undrink Unknown word. > undrinks Unknown word.
Circumfix¶
Conditional affixes implemented by a continuation class are not enough for circumfixes, because a circumfix is one affix in morphology. We also need CIRCUMFIX option for correct morphological analysis.
# circumfixes: ~ obligate prefix/suffix combinations # superlative in Hungarian: leg- (prefix) AND -bb (suffix) # nagy, nagyobb, legnagyobb, legeslegnagyobb # (great, greater, greatest, most greatest) CIRCUMFIX X PFX A Y 1 PFX A 0 leg/X . PFX B Y 1 PFX B 0 legesleg/X . SFX C Y 3 SFX C 0 obb . +COMPARATIVE SFX C 0 obb/AX . +SUPERLATIVE SFX C 0 obb/BX . +SUPERSUPERLATIVE
Dictionary:
1 nagy/C [MN]
Analysis:
> nagy nagy[MN] > nagyobb nagy[MN]+COMPARATIVE > legnagyobb nagy[MN]+SUPERLATIVE > legeslegnagyobb nagy[MN]+SUPERSUPERLATIVE
Compounds¶
Allowing free compounding yields a decrease in the precision of recognition, not to mention stemming and morphological analysis. Although Ispell introduces lexical switches to license the compounding of bases, this proves not to be restrictive enough. For example:
# affix file COMPOUNDFLAG X
2 foo/X bar/X
With this resource, foobar and barfoo also are accepted words.
This has been improved upon with the introduction of direction-sensitive compounding, i.e., lexical features can specify separately whether a base can occur as leftmost or rightmost constituent in compounds. This, however, is still insufficient to handle the intricate patterns of compounding, not to mention idiosyncratic (and language specific) norms of hyphenation.
The Hunspell algorithm currently allows any affixed form of words that are lexically marked as potential members of compounds. Hunspell improved on this, and its recursive compound-checking rules make it possible to implement the intricate spelling conventions of Hungarian compounds. For example, the COMPOUNDWORDMAX, COMPOUNDSYLLABLE, COMPOUNDROOT, and SYLLABLENUM options can be used to encode the noteworthy Hungarian `6-3' rule. As a further example, in Hungarian derivative suffixes often modify compounding properties. Hunspell allows compounding flags on affixes, and provides two special flags (COMPOUNDPERMITFLAG and COMPOUNDFORBIDFLAG) to permit or prohibit compounding of the derived forms.
Several Hunspell features are needed to handle German compounding:
# German compounding # set language to handle special casing of German sharp s LANG de_DE # compound flags COMPOUNDBEGIN U COMPOUNDMIDDLE V COMPOUNDEND W # Prefixes are allowed at the beginning of compounds, # suffixes are allowed at the end of compounds by default: # (prefix)?(root)+(affix)? # Affixes with COMPOUNDPERMITFLAG may be inside of compounds. COMPOUNDPERMITFLAG P # for German fogemorphemes (Fuge-element) # Hint: ONLYINCOMPOUND is not required everywhere, but the # checking will be a little faster with it. ONLYINCOMPOUND X # forbid uppercase characters at compound word bounds CHECKCOMPOUNDCASE # for handling Fuge-elements with dashes (Arbeits-) # dash will be a special word COMPOUNDMIN 1 WORDCHARS - # compound settings and fogemorpheme for `Arbeit' SFX A Y 3 SFX A 0 s/UPX . SFX A 0 s/VPDX . SFX A 0 0/WXD . SFX B Y 2 SFX B 0 0/UPX . SFX B 0 0/VWXDP . # a suffix for `Computer' SFX C Y 1 SFX C 0 n/WD . # for forbid exceptions (*Arbeitsnehmer) FORBIDDENWORD Z # dash prefix for compounds with dash (Arbeits-Computer) PFX - Y 1 PFX - 0 -/P . # decapitalizing prefix # circumfix for positioning in compounds PFX D Y 29 PFX D A a/PX A PFX D Ä ä/PX Ä
.
. PFX D Y y/PX Y PFX D Z z/PX Z
Example dictionary:
4 Arbeit/A- Computer/BC- -/W Arbeitsnehmer/Z
Accepted compound words with the previous resource:
Computer Computern Arbeit Arbeits- Computerarbeit Computerarbeits- Arbeitscomputer Arbeitscomputern Computerarbeitscomputer Computerarbeitscomputern Arbeitscomputerarbeit Computerarbeits-Computer Computerarbeits-Computern
Not accepted compounds:
computer arbeit Arbeits arbeits ComputerArbeit ComputerArbeits Arbeitcomputer ArbeitsComputer Computerarbeitcomputer ComputerArbeitcomputer ComputerArbeitscomputer Arbeitscomputerarbeits Computerarbeits-computer Arbeitsnehmer
This solution is still not ideal, however, and will be replaced by a pattern-based compound-checking algorithm which is closely integrated with input buffer tokenization. Patterns describing compounds come as a separate input resource that can refer to high-level properties of constituent parts (e.g. the number of syllables, affix flags, and containment of hyphens). The patterns are matched against potential segmentations of compounds to assess wellformedness.
Unicode character encoding¶
Both Ispell and Myspell use 8-bit character encodings, which is a major deficiency when it comes to scalability. Although a language like Hungarian has a standard 8-bit character set (ISO 8859-2), that set does not allow a full implementation of Hungarian orthographic conventions. For instance, the '--' symbol (n-dash) is missing from this character set, despite being not only the official symbol for delimiting parenthetic clauses in the language but also occurring in compound words as a special `big' hyphen.
MySpell has some 8-bit encoding tables, but there are also languages without a standard 8-bit encoding. For example, a lot of African languages have non-Latin or extended-Latin characters.
Similarly, using the original spelling of certain foreign names like Ångström or Molière is encouraged by the Hungarian spelling norm, and, since characters 'Å' and 'è' are not part of ISO 8859-2, when they combine with inflections containing characters only in ISO 8859-2 (like elative -ből, allative -től or delative -ről with double acute), these result in words (like Ångströmről or Molière-től.) that can not be encoded using any single ASCII encoding scheme.
The problems raised by 8-bit encodings have long been recognized by proponents of Unicode. It is clear that trading efficiency for encoding-independence has its advantages when it comes to a truly multilingual application. Hunspell implements memory- and time-efficient Unicode handling. With non-UTF-8 character encodings, Hunspell works with the original 8-bit strings. With UTF-8, affixes and words are stored in UTF-8 and handled mostly in UTF-8 during analysis; for condition checking and suggestion they are converted to UTF-16. Unicode text analysis and spell checking have a minimal (0-20%) time overhead, and a minimal or reasonable memory overhead that depends on the language (its UTF-8 encoding and affixation).
Conversion of aspell dictionaries¶
Aspell dictionaries can be easily converted to Hunspell format. Conversion steps:
dictionary (xx.cwl -> xx.wl):
preunzip xx.cwl wc -l < xx.wl > xx.dic cat xx.wl >> xx.dic
affix file
If the affix file exists, copy it:
cp xx_affix.dat xx.affIf not, create it with the suitable character encoding (see xx.dat)
echo "SET ISO8859-x" > xx.affor
echo "SET UTF-8" > xx.aff
It is useful to add a TRY option listing the characters of the dictionary in order of frequency, to drive edit-distance suggestions:
echo "TRY qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM" >>xx.aff
SEE ALSO¶
hunspell (1), ispell (1), ispell (4)
| 2026-04-30 |