Class HunspellDictionary
A Hunspell dictionary -- an .aff affix file and a .dic word list -- read for spelling
checks and suggestions. Hunspell dictionaries exist for most languages under open licenses
(LibreOffice ships them); none is bundled with Codename One, so an application supplies the
pair, typically from its resources.
Supported: SET (UTF-8, ISO8859-1, ISO8859-2), FLAG (character, long, num), AF
aliases, PFX/SFX rules with strip, add, condition and cross products, continuation
classes (two suffixes in a row), FORBIDDENWORD, NEEDAFFIX, ONLYINCOMPOUND, compounding
by COMPOUNDFLAG/COMPOUNDBEGIN/COMPOUNDMIDDLE/COMPOUNDEND with COMPOUNDMIN and
COMPOUNDWORDMAX, ICONV/OCONV, TRY, MAP and REP. Words that need
COMPOUNDRULE or the CHECKCOMPOUND* restrictions are reported as misspelled.
// the .aff and .dic files of a Hunspell dictionary, here as two tiny strings
byte[] aff = "SET UTF-8\nSFX S Y 1\nSFX S 0 s .\n".getBytes();
byte[] dic = "2\ncat/S\ndog/S\n".getBytes();
HunspellDictionary d = HunspellDictionary.fromBytes(aff, dic);
SpellChecker spell = SpellChecker.create(d);
Log.p("cats: " + spell.isCorrect("cats") + ", cots: " + spell.isCorrect("cots"));
-
Constructor Summary
ConstructorsConstructorDescriptionHunspellDictionary(String aff, String dic) Reads a dictionary from the text of its two files. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIs the word correct? A capitalized or all capitals word is also accepted in lower case (sentence starts, headings), but not the reverse: a name listed capitalized is wrong in lower case.static HunspellDictionaryfromBytes(byte[] aff, byte[] dic) Reads a dictionary from the raw bytes of its two files, decoded by theSETline.booleanIs this exact form, with its case as given, in the dictionary or derived by its rules?voidsetSplitWords(Set<String> leading, Set<String> trailing) Short words that often run into the next word (leading) or the one before (trailing): a missing space next to one ranks before other splits insuggest.intsize()The number of words in the word list, before affixes.Suggestions for a misspelled word, best first: a case change,MAPslips (a missing diacritic first),REPconfusions, a missing space, one typo with theTRYletters, and when those find too few, the dictionary words that start like it within two typos.
-
Constructor Details
-
HunspellDictionary
-
-
Method Details
-
fromBytes
Reads a dictionary from the raw bytes of its two files, decoded by the
SETline.Parameters
-
aff: the affix file -
dic: the word list
Returns
the dictionary
-
-
lookup
Is this exact form, with its case as given, in the dictionary or derived by its rules?
Parameters
w: the word
Returns
true when it is
-
setSplitWords
Short words that often run into the next word (leading) or the one before (trailing): a missing space next to one ranks before other splits in
suggest.Parameters
-
leading: words that run into the next word, or null -
trailing: words that run into the previous one, or null
-
-
check
Is the word correct? A capitalized or all capitals word is also accepted in lower case (sentence starts, headings), but not the reverse: a name listed capitalized is wrong in lower case.
Parameters
word: the word
Returns
true when it is spelled correctly
-
suggest
Suggestions for a misspelled word, best first: a case change,
MAPslips (a missing diacritic first),REPconfusions, a missing space, one typo with theTRYletters, and when those find too few, the dictionary words that start like it within two typos.Parameters
-
word: the misspelled word -
max: the most suggestions to return
Returns
the suggestions, in the case the word was written in
-
-
size
public int size()The number of words in the word list, before affixes.
Returns
the root count
-