Package net.didion.jwnl.dictionary
Class FileBackedDictionary
- java.lang.Object
-
- net.didion.jwnl.dictionary.Dictionary
-
- net.didion.jwnl.dictionary.AbstractCachingDictionary
-
- net.didion.jwnl.dictionary.FileBackedDictionary
-
- All Implemented Interfaces:
Installable
public class FileBackedDictionary extends AbstractCachingDictionary
ADictionarythat retrieves objects from the text files in the WordNet distribution directory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classFileBackedDictionary.FileLookaheadIteratorA lookahead iterator over a dictionary file.private classFileBackedDictionary.IndexFileLookaheadIteratorprivate classFileBackedDictionary.SubstringIndexFileLookaheadIterator
-
Field Summary
Fields Modifier and Type Field Description private FileManager_dbprivate FileDictionaryElementFactory_factoryprivate static MessageLog_logstatic java.lang.StringCACHE_SIZEThe default cache size.static java.lang.StringDICTIONARY_ELEMENT_FACTORYThe class of FileDictionaryElementFactory to use.static java.lang.StringENABLE_CACHINGThe value should be "true" or "false".static java.lang.StringEXCEPTION_WORD_CACHE_SIZESize of the exception cache.static java.lang.StringFILE_MANAGERFile manager install parameter.static java.lang.StringINDEX_WORD_CACHE_SIZESize of the index word cache.static java.lang.StringMORPHMorphological processor class install parameter.private java.util.MapsenseMapA sense map, key is offsetlemma, word is populated with lemma, usage, and sense key.static java.lang.StringSYNSET_WORD_CACHE_SIZESize of the synset cache.
-
Constructor Summary
Constructors Modifier Constructor Description FileBackedDictionary()privateFileBackedDictionary(FileManager manager, MorphologicalProcessor morph, FileDictionaryElementFactory factory, boolean enableCaching)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Shut down the dictionaryFileDictionaryElementFactorygetDictionaryElementFactory()ExcgetException(POS pos, java.lang.String derivation)Lookupderivationin the exceptions file of part-of-speechposand return an Exc object containing the results.java.util.IteratorgetExceptionIterator(POS pos)Return an Iterator over all the Exceptions in the database.protected FileManagergetFileManager()Get the file manager that backs this database.IndexWordgetIndexWord(POS pos, java.lang.String lemma)Look up a word in the database.java.util.IteratorgetIndexWordIterator(POS pos)Return an Iterator over all the IndexWords of part-of-speech pos in the database.java.util.IteratorgetIndexWordIterator(POS pos, java.lang.String substring)Return an Iterator over all the IndexWords of part-of-speech pos whose lemmas contain substring as a substring.IndexWordgetRandomIndexWord(POS pos)private SynsetgetSynset(POS pos, long offset, java.lang.String line)SynsetgetSynsetAt(POS pos, long offset)Return theSynsetat offsetoffsetfrom the database.java.util.IteratorgetSynsetIterator(POS pos)Return an Iterator over all the Synsets of part-of-speech pos in the database.voidinstall(java.util.Map params)Install a FileBackedDictionary from a map of parameters.static voidinstall(FileManager fileManager, FileDictionaryElementFactory factory)Construct a Dictionary that retrieves file data fromfileManager.static voidinstall(FileManager fileManager, FileDictionaryElementFactory factory, boolean enableCaching)static voidinstall(FileManager fileManager, MorphologicalProcessor morph, FileDictionaryElementFactory factory)Construct a Dictionary that retrieves file data fromfileManager.static voidinstall(FileManager fileManager, MorphologicalProcessor morph, FileDictionaryElementFactory factory, boolean enableCaching)private ExcparseAndCacheExceptionLine(POS pos, long offset, java.lang.String line)private IndexWordparseAndCacheIndexWordLine(POS pos, long offset, java.lang.String line)-
Methods inherited from class net.didion.jwnl.dictionary.AbstractCachingDictionary
cacheException, cacheIndexWord, cacheSynset, clearCache, clearCache, getCacheCapacity, getCachedException, getCachedIndexWord, getCachedSynset, getCacheSizes, isCachingEnabled, setCacheCapacity, setCacheCapacity, setCachingEnabled
-
Methods inherited from class net.didion.jwnl.dictionary.Dictionary
getInstance, getMorphologicalProcessor, lookupAllIndexWords, lookupIndexWord, prepareQueryString, setDictionary, uninstall
-
-
-
-
Field Detail
-
_log
private static final MessageLog _log
-
MORPH
public static final java.lang.String MORPH
Morphological processor class install parameter. The value should be the class of MorphologicalProcessor to use.- See Also:
- Constant Field Values
-
FILE_MANAGER
public static final java.lang.String FILE_MANAGER
File manager install parameter. The value should be the class of FileManager to use.- See Also:
- Constant Field Values
-
DICTIONARY_ELEMENT_FACTORY
public static final java.lang.String DICTIONARY_ELEMENT_FACTORY
The class of FileDictionaryElementFactory to use.- See Also:
- Constant Field Values
-
ENABLE_CACHING
public static final java.lang.String ENABLE_CACHING
The value should be "true" or "false". The default is "true".- See Also:
- Constant Field Values
-
CACHE_SIZE
public static final java.lang.String CACHE_SIZE
The default cache size.- See Also:
- Constant Field Values
-
INDEX_WORD_CACHE_SIZE
public static final java.lang.String INDEX_WORD_CACHE_SIZE
Size of the index word cache. Overrides the default cache size- See Also:
- Constant Field Values
-
SYNSET_WORD_CACHE_SIZE
public static final java.lang.String SYNSET_WORD_CACHE_SIZE
Size of the synset cache. Overrides the default cache size- See Also:
- Constant Field Values
-
EXCEPTION_WORD_CACHE_SIZE
public static final java.lang.String EXCEPTION_WORD_CACHE_SIZE
Size of the exception cache. Overrides the default cache size- See Also:
- Constant Field Values
-
senseMap
private java.util.Map senseMap
A sense map, key is offsetlemma, word is populated with lemma, usage, and sense key.
-
_db
private FileManager _db
-
_factory
private FileDictionaryElementFactory _factory
-
-
Constructor Detail
-
FileBackedDictionary
public FileBackedDictionary()
-
FileBackedDictionary
private FileBackedDictionary(FileManager manager, MorphologicalProcessor morph, FileDictionaryElementFactory factory, boolean enableCaching)
-
-
Method Detail
-
install
public static void install(FileManager fileManager, FileDictionaryElementFactory factory)
Construct a Dictionary that retrieves file data fromfileManager. A client can use this to create a Dictionary backed by a RemoteFileManager.- See Also:
RemoteFileManager
-
install
public static void install(FileManager fileManager, MorphologicalProcessor morph, FileDictionaryElementFactory factory)
Construct a Dictionary that retrieves file data fromfileManager. If enableCaching is true, lookup operations will check the relavant cache before doing a lookup and will cache their results after doing a lookup.
-
install
public static void install(FileManager fileManager, FileDictionaryElementFactory factory, boolean enableCaching)
-
install
public static void install(FileManager fileManager, MorphologicalProcessor morph, FileDictionaryElementFactory factory, boolean enableCaching)
-
install
public void install(java.util.Map params) throws JWNLExceptionInstall a FileBackedDictionary from a map of parameters. The keys are chose from the static variables above.- Throws:
JWNLException
-
close
public void close()
Description copied from class:DictionaryShut down the dictionary- Specified by:
closein classDictionary
-
getFileManager
protected FileManager getFileManager()
Get the file manager that backs this database.
-
getDictionaryElementFactory
public FileDictionaryElementFactory getDictionaryElementFactory()
-
getIndexWordIterator
public java.util.Iterator getIndexWordIterator(POS pos) throws JWNLException
Description copied from class:DictionaryReturn an Iterator over all the IndexWords of part-of-speech pos in the database.- Specified by:
getIndexWordIteratorin classDictionary- Parameters:
pos- The part-of-speech- Returns:
- An iterator over
IndexWords - Throws:
JWNLException
-
getIndexWordIterator
public java.util.Iterator getIndexWordIterator(POS pos, java.lang.String substring) throws JWNLException
Description copied from class:DictionaryReturn an Iterator over all the IndexWords of part-of-speech pos whose lemmas contain substring as a substring.- Specified by:
getIndexWordIteratorin classDictionary- Parameters:
pos- The part-of-speech.- Returns:
- An iterator over
IndexWords. - Throws:
JWNLException
-
getIndexWord
public IndexWord getIndexWord(POS pos, java.lang.String lemma) throws JWNLException
Description copied from class:DictionaryLook up a word in the database. The search is case-independent, and phrases are separated by spaces ("look up", not "look_up"). Note: this method does not subject lemma to any morphological processing. If you want this, useDictionary.lookupIndexWord(POS, String).- Specified by:
getIndexWordin classDictionary- Parameters:
pos- The part-of-speech.lemma- The orthographic representation of the word.- Returns:
- An IndexWord representing the word, or
nullif no such entry exists. - Throws:
JWNLException
-
getRandomIndexWord
public IndexWord getRandomIndexWord(POS pos) throws JWNLException
- Specified by:
getRandomIndexWordin classDictionary- Throws:
JWNLException
-
parseAndCacheIndexWordLine
private IndexWord parseAndCacheIndexWordLine(POS pos, long offset, java.lang.String line)
-
getSynsetIterator
public java.util.Iterator getSynsetIterator(POS pos)
Description copied from class:DictionaryReturn an Iterator over all the Synsets of part-of-speech pos in the database.- Specified by:
getSynsetIteratorin classDictionary- Parameters:
pos- The part-of-speech.- Returns:
- An iterator over
Synsets.
-
getSynsetAt
public Synset getSynsetAt(POS pos, long offset) throws JWNLException
Description copied from class:DictionaryReturn theSynsetat offsetoffsetfrom the database.- Specified by:
getSynsetAtin classDictionary- Parameters:
pos- The part-of-speech file to look inoffset- The offset of the synset in the file- Returns:
- A synset containing the parsed line from the database
- Throws:
JWNLException
-
getSynset
private Synset getSynset(POS pos, long offset, java.lang.String line) throws JWNLException
- Throws:
JWNLException
-
getExceptionIterator
public java.util.Iterator getExceptionIterator(POS pos)
Description copied from class:DictionaryReturn an Iterator over all the Exceptions in the database.- Specified by:
getExceptionIteratorin classDictionary- Parameters:
pos- the part-of-speech- Returns:
- Iterator An iterator over
Strings
-
getException
public Exc getException(POS pos, java.lang.String derivation) throws JWNLException
Description copied from class:DictionaryLookupderivationin the exceptions file of part-of-speechposand return an Exc object containing the results.- Specified by:
getExceptionin classDictionary- Parameters:
pos- the exception file to look inderivation- the word to look up- Returns:
- Exc the Exc object
- Throws:
JWNLException
-
-