Class Hunspell
- java.lang.Object
-
- org.languagetool.rules.spelling.hunspell.Hunspell
-
public class Hunspell extends java.lang.ObjectThe 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 Classes Modifier and Type Class Description classHunspell.DictionaryClass representing a single dictionary.
-
Field Summary
Fields Modifier and Type Field Description private HunspellLibraryhslThe native library instance, created by JNA.private static HunspellhunspellThe Singleton instance of Hunspellprivate java.lang.StringlibFileThe library file that was loaded.private java.util.HashMap<java.lang.String,Hunspell.Dictionary>mapThis is the cache where we keep the already loaded dictionaries around
-
Constructor Summary
Constructors Modifier Constructor Description protectedHunspell(java.lang.String libDir)Constructor for the library, loads the native lib.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroyDictionary(java.lang.String baseFileName)Removes a dictionary from the internal cacheprivate static java.nio.CharBufferensureCapacity(java.nio.CharBuffer buffer, int capacity)Hunspell.DictionarygetDictionary(java.lang.String baseFileName)Gets an instance of the dictionary.static HunspellgetInstance()The instance of the HunspellManager, looks for the native lib in the default directoriesstatic HunspellgetInstance(java.lang.String libDir)The instance of the HunspellManager, looks for the native lib in the directory specified.java.lang.StringgetLibFile()static java.lang.StringlibName()Calculate the filename of the native hunspell lib.static java.lang.StringlibNameBare()protected voidtryLoad(java.lang.String libFile)
-
-
-
Field Detail
-
hunspell
private static Hunspell hunspell
The Singleton instance of Hunspell
-
hsl
private HunspellLibrary hsl
The native library instance, created by JNA.
-
libFile
private java.lang.String libFile
The library file that was loaded.
-
map
private java.util.HashMap<java.lang.String,Hunspell.Dictionary> map
This is the cache where we keep the already loaded dictionaries around
-
-
Constructor Detail
-
Hunspell
protected Hunspell(java.lang.String libDir) throws java.lang.UnsatisfiedLinkError, java.lang.UnsupportedOperationExceptionConstructor 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:
java.lang.UnsupportedOperationException- if the OS or architecture is simply not supported.java.lang.UnsatisfiedLinkError
-
-
Method Detail
-
getInstance
public static Hunspell getInstance() throws java.lang.UnsatisfiedLinkError, java.lang.UnsupportedOperationException
The instance of the HunspellManager, looks for the native lib in the default directories- Throws:
java.lang.UnsatisfiedLinkErrorjava.lang.UnsupportedOperationException
-
getInstance
public static Hunspell getInstance(java.lang.String libDir) throws java.lang.UnsatisfiedLinkError, java.lang.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:
java.lang.UnsatisfiedLinkErrorjava.lang.UnsupportedOperationException
-
tryLoad
protected void tryLoad(java.lang.String libFile) throws java.lang.UnsupportedOperationException- Throws:
java.lang.UnsupportedOperationException
-
getLibFile
public java.lang.String getLibFile()
-
libName
public static java.lang.String libName() throws java.lang.UnsupportedOperationExceptionCalculate 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:
java.lang.UnsupportedOperationException
-
libNameBare
public static java.lang.String libNameBare() throws java.lang.UnsupportedOperationException- Throws:
java.lang.UnsupportedOperationException
-
ensureCapacity
private static java.nio.CharBuffer ensureCapacity(java.nio.CharBuffer buffer, int capacity)
-
getDictionary
public Hunspell.Dictionary getDictionary(java.lang.String baseFileName) throws java.io.IOException
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:
java.io.IOException
-
destroyDictionary
public void destroyDictionary(java.lang.String baseFileName)
Removes a dictionary from the internal cache- Parameters:
baseFileName- the base name of the dictionary, as passed to getDictionary()
-
-