Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class HunspellDictionary
- Object
- 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"));Constructors
public HunspellDictionary(String aff, String dic) | Reads a dictionary from the text of its two files. |
Methods
public static HunspellDictionary fromBytes(byte[] aff, byte[] dic) | Reads a dictionary from the raw bytes of its two files, decoded by the SET line. |
public boolean lookup(String w) | Is this exact form, with its case as given, in the dictionary or derived by its rules? |
public void setSplitWords(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 in suggest. |
public boolean check(String word) | 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. |
public List<String> suggest(String word, int max) | Suggestions for a misspelled word, best first: a case change, MAP slips (a missing diacritic first), REP confusions, a missing space, one typo with the TRY letters, and when those find too few, the dictionary words that start like it within two typos. |
public int size() | The number of words in the word list, before affixes. |
Inherited methods
Constructor details
HunspellDictionary
public HunspellDictionary(String aff, String dic)Parameters
affString- the affix file
dicString- the word list
Method details
fromBytes
public static HunspellDictionary fromBytes(byte[] aff, byte[] dic)SET line.Parameters
affbyte[]- the affix file
dicbyte[]- the word list
Returns
lookup
public boolean lookup(String w)Parameters
wString- the word
Returns
setSplitWords
public void setSplitWords(Set<String> leading, Set<String> trailing)suggest.Parameters
leadingSet<String>- words that run into the next word, or null
trailingSet<String>- words that run into the previous one, or null
check
public boolean check(String word)Parameters
wordString- the word
Returns
suggest
public List<String> suggest(String word, int max)MAP slips (a missing
diacritic first), REP confusions, a missing space, one typo with the TRY letters,
and when those find too few, the dictionary words that start like it within two typos.Parameters
wordString- the misspelled word
maxint- the most suggestions to return
Returns
size
public int size()