Class Hunspell
java.lang.Object
org.languagetool.rules.spelling.hunspell.Hunspell
The simple hunspell library frontend which takes care of creating
and singleton'ing the library instance (no need to load it more than once
per process).
The Hunspell java bindings are licensed under the same terms as Hunspell itself (GPL/LGPL/MPL tri-license),
see the file COPYING.txt in the root of the distribution for the exact terms.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Class representing a single dictionary. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate HunspellLibrary
The native library instance, created by JNA.private static Hunspell
The Singleton instance of Hunspellprivate String
The library file that was loaded.private HashMap
<String, Hunspell.Dictionary> This is the cache where we keep the already loaded dictionaries around -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroyDictionary
(String baseFileName) Removes a dictionary from the internal cacheprivate static CharBuffer
ensureCapacity
(CharBuffer buffer, int capacity) getDictionary
(String baseFileName) Gets an instance of the dictionary.static Hunspell
The instance of the HunspellManager, looks for the native lib in the default directoriesstatic Hunspell
getInstance
(String libDir) The instance of the HunspellManager, looks for the native lib in the directory specified.static String
libName()
Calculate the filename of the native hunspell lib.static String
protected void
-
Field Details
-
hunspell
The Singleton instance of Hunspell -
hsl
The native library instance, created by JNA. -
libFile
The library file that was loaded. -
map
This is the cache where we keep the already loaded dictionaries around
-
-
Constructor Details
-
Hunspell
Constructor for the library, loads the native lib. Loading is done in the first of the following three ways that works: 1) Unmodified load in the provided directory. 2) libFile stripped back to the base name (^lib(.*)\.so on unix) 3) The library is searched for in the classpath, extracted to disk and loaded.- Parameters:
libDir
- Optional absolute directory where the native lib can be found.- Throws:
UnsupportedOperationException
- if the OS or architecture is simply not supported.UnsatisfiedLinkError
-
-
Method Details
-
getInstance
The instance of the HunspellManager, looks for the native lib in the default directories -
getInstance
public static Hunspell getInstance(String libDir) throws UnsatisfiedLinkError, UnsupportedOperationException The instance of the HunspellManager, looks for the native lib in the directory specified.- Parameters:
libDir
- Optional absolute directory where the native lib can be found.- Throws:
UnsatisfiedLinkError
UnsupportedOperationException
-
tryLoad
- Throws:
UnsupportedOperationException
-
getLibFile
-
libName
Calculate the filename of the native hunspell lib. The files have completely different names to allow them to live in the same directory and avoid confusion.- Throws:
UnsupportedOperationException
-
libNameBare
- Throws:
UnsupportedOperationException
-
ensureCapacity
-
getDictionary
Gets an instance of the dictionary.- Parameters:
baseFileName
- the base name of the dictionary, passing /dict/da_DK means that the files /dict/da_DK.dic and /dict/da_DK.aff get loaded- Throws:
IOException
-
destroyDictionary
Removes a dictionary from the internal cache- Parameters:
baseFileName
- the base name of the dictionary, as passed to getDictionary()
-