java-gnome version 4.0.15

org.freedesktop.enchant
Class Enchant

Object
  extended by org.gnome.glib.Glib
      extended by org.freedesktop.enchant.Enchant

public final class Enchant
extends Glib

Get a handle to an Enchant dictionary for spell checking.

Enchant is not itself a spell checking library; it is, rather a facade to various common spelling mechanisms. It provides a simple and sufficient API for doing spelling operations. Which actual back-end provider will be employed depends on the system and user "ordering" files.

Usage

Enchant is straight-forward to use. For possibly misspelled word, you can do

 Enchant.init();
 
 dict = Enchant.requestDictionary("en_CA");
 
 if (dict.check(word)) {
     return "Spelled correctly!";
 } else {
     possibles = dict.suggest(word);
     
     str.append("The word ");
     str.append(word);
     str.append(" was misspelled. You could correct it with one of:\n"
     
     for (i = 0; i < possibles.length; i++) {
         str.append(possibles[i]);
         str.append('\n');
     }
     
     return str.toString();
 }
 

Since:
4.0.14
Author:
Andrew Cowie
See Also:
Enchant home page

Method Summary
static void init()
           
static Dictionary requestDictionary(String lang)
          Get a Dictionary for the specified language.
static Dictionary requestPersonalWordList(String filename)
          Get a Dictionary for the specified personal word list.
 
Methods inherited from class org.gnome.glib.Glib
getRealName, getSystemConfigDirs, getSystemDataDirs, getUserCacheDir, getUserConfigDir, getUserDataDir, getUserName, getUserSpecialDir, reloadUserSpecialDirsCache, setProgramName
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

public static void init()
Since:
4.0.14

requestDictionary

public static Dictionary requestDictionary(String lang)
Get a Dictionary for the specified language.

Languages are indicated in a locale-like form; while you can use just the language code en, specifying a specific language variant such as en_UK or fr_CA is preferred.

Returns null if no suitable dictionary was found.

Since:
4.0.14

requestPersonalWordList

public static Dictionary requestPersonalWordList(String filename)
                                          throws FileNotFoundException
Get a Dictionary for the specified personal word list.

Word lists are simple files with one word per line. By creating a Dictionary of a personal word list you can add words to a file that is independent of a normal spelling engine back-end.

Throws:
FileNotFoundException
Since:
4.0.14


java-gnome