|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.mit.jwi.RAMDictionary
public class RAMDictionary
Default implementation of the IRAMDictionary interface. This
implementation is designed to wrap an arbitrary dictionary object; however,
convenience constructors are provided for the most common use cases:
Note: If you receive an OutOfMemoryError while using this
object (this can occur on 32 bit JVMs), try increasing your heap size, for
example, by using the -Xmx switch.
| Nested Class Summary | |
|---|---|
static class |
RAMDictionary.DataLoader
A Callable that creates a dictionary data from a specified
dictionary. |
static class |
RAMDictionary.DictionaryData
Object that holds all the dictionary data loaded from the Wordnet files. |
protected class |
RAMDictionary.HotSwappableExceptionEntryIterator
A hot swappable iterator that iterates over exceptions entries for a particular part of speech. |
protected class |
RAMDictionary.HotSwappableIndexWordIterator
A hot swappable iterator for index words. |
protected class |
RAMDictionary.HotSwappableIterator<E>
An iterator that allows the dictionary to be loaded into memory while it is iterating. |
protected class |
RAMDictionary.HotSwappableSenseEntryIterator
A hot swappable iterator that iterates over sense entries. |
protected class |
RAMDictionary.HotSwappableSynsetIterator
A hot swappable iterator for synsets. |
protected class |
RAMDictionary.JWIBackgroundDataLoader
This runnable loads the dictionary data into memory and sets the appropriate variable in the parent dictionary. |
| Nested classes/interfaces inherited from interface edu.mit.jwi.IRAMDictionary |
|---|
IRAMDictionary.FileInputStreamFactory, IRAMDictionary.IInputStreamFactory, IRAMDictionary.URLInputStreamFactory |
| Nested classes/interfaces inherited from interface edu.mit.jwi.data.IHasLifecycle |
|---|
IHasLifecycle.LifecycleState, IHasLifecycle.ObjectClosedException, IHasLifecycle.ObjectOpenException |
| Field Summary | |
|---|---|
protected IDictionary |
backing
|
protected RAMDictionary.DictionaryData |
data
|
static int |
defaultLoadPolicy
The default load policy of a RAMDictionary is to load data in the
background when opened. |
protected IRAMDictionary.IInputStreamFactory |
factory
|
protected java.util.concurrent.locks.Lock |
lifecycleLock
|
protected java.lang.Thread |
loader
|
protected java.util.concurrent.locks.Lock |
loadLock
|
protected int |
loadPolicy
|
protected IHasLifecycle.LifecycleState |
state
|
| Fields inherited from interface edu.mit.jwi.data.ILoadPolicy |
|---|
BACKGROUND_LOAD, IMMEDIATE_LOAD, NO_LOAD |
| Constructor Summary | |
|---|---|
|
RAMDictionary(java.io.File file)
Constructs a new wrapper RAM dictionary that will load the contents the specified local Wordnet data, with the specified load policy. |
|
RAMDictionary(java.io.File file,
int loadPolicy)
Loads data from the specified File using the specified load policy. |
|
RAMDictionary(IDictionary dict,
int loadPolicy)
Constructs a new RAMDictionary that will load the contents of the wrapped dictionary into memory, with the specified load policy. |
protected |
RAMDictionary(IDictionary backing,
IRAMDictionary.IInputStreamFactory factory,
int loadPolicy)
This is a internal constructor that unifies the constructor decision matrix. |
|
RAMDictionary(IRAMDictionary.IInputStreamFactory factory)
Constructs a new RAMDictionary that will load an in-memory image from the specified stream factory. |
|
RAMDictionary(java.net.URL url)
Constructs a new RAMDictionary that will load the contents the specified Wordnet data using the default load policy. |
|
RAMDictionary(java.net.URL url,
int loadPolicy)
Loads data from the specified URL using the specified load policy. |
| Method Summary | |
|---|---|
protected IHasLifecycle.LifecycleState |
assertLifecycleState()
This is an internal utility method that determines whether this dictionary should be considered open or closed. |
void |
close()
This closes the object by disposing of data backing objects or connections. |
static IDictionary |
createBackingDictionary(java.io.File file)
Creates a DataSourceDictionary out of the specified file, as long
as the file points to an existing local directory. |
static IDictionary |
createBackingDictionary(java.net.URL url)
Creates a DataSourceDictionary out of the specified url, as long
as the url points to an existing local directory. |
static IRAMDictionary.IInputStreamFactory |
createInputStreamFactory(java.io.File file)
Creates an input stream factory out of the specified File. |
static IRAMDictionary.IInputStreamFactory |
createInputStreamFactory(java.net.URL url)
Creates an input stream factory out of the specified URL. |
static boolean |
export(java.io.File in,
java.io.OutputStream out)
This is a convenience method that transforms a Wordnet dictionary at the specified file location into a in-memory image written to the specified output stream. |
static boolean |
export(IRAMDictionary.IInputStreamFactory in,
java.io.OutputStream out)
This is a convenience method that transforms a Wordnet dictionary drawn from the specified input stream factory into a in-memory image written to the specified output stream. |
protected static boolean |
export(IRAMDictionary dict,
java.io.OutputStream out)
Exports a specified RAM Dictionary object to the specified output stream. |
void |
export(java.io.OutputStream out)
Exports the in-memory contents of the to the specified output stream. |
static boolean |
export(java.net.URL in,
java.io.OutputStream out)
This is a convenience method that transforms a Wordnet dictionary at the specified url location into a in-memory image written to the specified output stream. |
IDictionary |
getBackingDictionary()
Returns the dictionary that backs this instance. |
java.nio.charset.Charset |
getCharset()
Returns the character set associated with this object. |
IExceptionEntry |
getExceptionEntry(IExceptionEntryID id)
Retrieves the exception entry for the specified id from the database. |
IExceptionEntry |
getExceptionEntry(java.lang.String surfaceForm,
POS pos)
Retrieves the exception entry for the specified surface form and part of speech from the database. |
java.util.Iterator<IExceptionEntry> |
getExceptionEntryIterator(POS pos)
Returns an iterator that will iterate over all exception entries of the specified part of speech. |
IIndexWord |
getIndexWord(IIndexWordID id)
Retrieves the specified index word object from the database. |
IIndexWord |
getIndexWord(java.lang.String lemma,
POS pos)
This method is identical to getIndexWord(IIndexWordID) and
is provided as a convenience. |
java.util.Iterator<IIndexWord> |
getIndexWordIterator(POS pos)
Returns an iterator that will iterate over all index words of the specified part of speech. |
int |
getLoadPolicy()
Returns the load policy for this object, expressed as an integer. |
ISenseEntry |
getSenseEntry(ISenseKey key)
Retrieves the sense entry for the specified sense key from the database. |
java.util.Iterator<ISenseEntry> |
getSenseEntryIterator()
Returns an iterator that will iterate over all sense entries in the dictionary. |
IRAMDictionary.IInputStreamFactory |
getStreamFactory()
Returns the stream factory that backs this instance; may be null. |
ISynset |
getSynset(ISynsetID id)
Retrieves the synset with the specified id from the database. |
java.util.Iterator<ISynset> |
getSynsetIterator(POS pos)
Returns an iterator that will iterate over all synsets of the specified part of speech. |
IVersion |
getVersion()
Returns the associated version for this object. |
IWord |
getWord(ISenseKey key)
Retrieves the word with the specified sense key from the database. |
IWord |
getWord(IWordID id)
Retrieves the word with the specified id from the database. |
boolean |
isLoaded()
Returns whether this object is loaded or not. |
boolean |
isOpen()
Returns true if the dictionary is open, that is, ready to
accept queries; returns false otherwise |
void |
load()
Starts a simple, non-blocking load. |
void |
load(boolean block)
Initiates the loading process. |
boolean |
open()
This opens the object by performing any required initialization steps. |
void |
setCharset(java.nio.charset.Charset charset)
Sets the character set associated with this dictionary. |
void |
setLoadPolicy(int policy)
Sets the load policy for this object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static int defaultLoadPolicy
RAMDictionary is to load data in the
background when opened.
protected final IDictionary backing
protected final IRAMDictionary.IInputStreamFactory factory
protected final java.util.concurrent.locks.Lock lifecycleLock
protected final java.util.concurrent.locks.Lock loadLock
protected volatile IHasLifecycle.LifecycleState state
protected transient java.lang.Thread loader
protected int loadPolicy
protected RAMDictionary.DictionaryData data
| Constructor Detail |
|---|
public RAMDictionary(java.io.File file)
file - a file pointing to a local copy of wordnet; may not be
null
java.lang.NullPointerException - if the specified file is nullpublic RAMDictionary(java.net.URL url)
url - a url pointing to a local copy of wordnet; may not be
null
java.lang.NullPointerException - if the specified url is null
public RAMDictionary(java.io.File file,
int loadPolicy)
file - a file pointing to a local copy of wordnet; may not be
nullloadPolicy - the load policy of the dictionary; see constants in
ILoadPolicy. Note that if the file points to to a
resource that is the exported image of an in-memory
dictionary, the specified load policy is ignored: the
dictionary is loaded into memory immediately.
java.lang.NullPointerException - if the specified file is nullILoadPolicy
public RAMDictionary(java.net.URL url,
int loadPolicy)
url - a url pointing to a local copy of wordnet; may not be
nullloadPolicy - the load policy of the dictionary; see constants in
ILoadPolicy. Note that if the url points to to a
resource that is the exported image of an in-memory
dictionary, the specified load policy is ignored: the
dictionary is loaded into memory immediately.
java.lang.NullPointerException - if the specified url is nullILoadPolicy
public RAMDictionary(IDictionary dict,
int loadPolicy)
dict - the dictionary to be wrapped, may not be nullloadPolicy - the load policy of the dictionary; see constants in
ILoadPolicy.ILoadPolicypublic RAMDictionary(IRAMDictionary.IInputStreamFactory factory)
factory - the stream factory that provides the stream; may not be null
java.lang.NullPointerException - if the factory is null
protected RAMDictionary(IDictionary backing,
IRAMDictionary.IInputStreamFactory factory,
int loadPolicy)
null, otherwise an exception is thrown. If the
factory is non-null, the dictionary will ignore the
specified load policy and set the load policy to "immediate load".
backing - the backing dictionary; may be nullfactory - the input stream factory; may be nullloadPolicy - the load policy| Method Detail |
|---|
public IDictionary getBackingDictionary()
null.public IRAMDictionary.IInputStreamFactory getStreamFactory()
null.
nullpublic void setCharset(java.nio.charset.Charset charset)
IDictionarynull.
setCharset in interface IDictionarycharset - the possibly null character set to use when
decoding files.public java.nio.charset.Charset getCharset()
IHasCharsetnull.
getCharset in interface IHasCharsetnullpublic int getLoadPolicy()
ILoadPolicy
getLoadPolicy in interface ILoadPolicypublic void setLoadPolicy(int policy)
ILoadPolicy
setLoadPolicy in interface ILoadPolicypolicy - the policy to implement; may be one of NO_LOAD,
BACKGROUND_LOAD, IMMEDIATE_LOAD or
an implementation-dependent value.public boolean isLoaded()
ILoadabletrue only if the loading process has completed and the
object is actually loaded; if the object is still in the process of
loading, or failed to load, the method should return false.
isLoaded in interface ILoadabletrue if the method has completed loading;
false otherwisepublic void load()
ILoadable
load in interface ILoadable
public void load(boolean block)
throws java.lang.InterruptedException
ILoadableblock is false), or return
only when the loading process is complete. If the object is already
loaded, the method returns immediately and has no effect. If the object
is in the process of loading, and the method is called in blocking mode,
the method blocks until loading is complete, even if that call of the
method did not initiate the loading process. Some implementors of this
interface may not support the immediate-return functionality.
load in interface ILoadableblock - if true, the method returns only when the loading
process is complete; if false, the method returns
immediately.
java.lang.InterruptedException - if the method is blocking, and is interrupted while waiting
for loading to complete
public boolean open()
throws java.io.IOException
IHasLifecyclefalse, then subsequent calls to
IHasLifecycle.isOpen() will return false.
open in interface IHasLifecycletrue if there were no errors in initialization;
false otherwise.
java.io.IOException - if there was IO error while performing initializataionpublic boolean isOpen()
IHasLifecycletrue if the dictionary is open, that is, ready to
accept queries; returns false otherwise
isOpen in interface IHasLifecycletrue if the object is open; false
otherwisepublic void close()
IClosable
close in interface IClosableprotected final IHasLifecycle.LifecycleState assertLifecycleState()
public void export(java.io.OutputStream out)
throws java.io.IOException
IRAMDictionary
export in interface IRAMDictionaryout - the output stream to which the in-memory data will be written;
may not be null
java.io.IOException - if there is a problem writing the in-memory data to the
output stream.public IVersion getVersion()
IHasVersionnull.
getVersion in interface IHasVersionnull if none.
public IIndexWord getIndexWord(java.lang.String lemma,
POS pos)
IDictionarygetIndexWord(IIndexWordID) and
is provided as a convenience.
getIndexWord in interface IDictionarylemma - the lemma for the index word requested; may not be
null, empty, or all whitespacepos - the part of speech; may not be null
null if none is foundpublic IIndexWord getIndexWord(IIndexWordID id)
IDictionarynull.
Note: This call does no stemming on the specified lemma, it is
taken as specified. That is, if you submit the word "dogs", it will
search for "dogs", not "dog"; in the standard Wordnet distribution, there
is no entry for "dogs" and therefore the call will return
null. This is in contrast to the Wordnet API provided by
Princeton. If you want your searches to capture morphological variation,
use the descendants of the IStemmer class.
getIndexWord in interface IDictionaryid - the id of the index word to search for; may not be
null
null otherwisepublic java.util.Iterator<IIndexWord> getIndexWordIterator(POS pos)
IDictionary
getIndexWordIterator in interface IDictionarypos - the part of speech over which to iterate; may not be
null
public IWord getWord(IWordID id)
IDictionarynull
getWord in interface IDictionaryid - the id of the word to search for; may not be null
null otherwisepublic IWord getWord(ISenseKey key)
IDictionarynull
getWord in interface IDictionarykey - the sense key of the word to search for; may not be
null
null otherwisepublic ISynset getSynset(ISynsetID id)
IDictionarynull
getSynset in interface IDictionaryid - the id of the synset to search for; may not be
null
null otherwisepublic java.util.Iterator<ISynset> getSynsetIterator(POS pos)
IDictionary
getSynsetIterator in interface IDictionarypos - the part of speech over which to iterate; may not be
null
public ISenseEntry getSenseEntry(ISenseKey key)
IDictionarynull
getSenseEntry in interface IDictionarykey - the sense key of the entry to search for; may not be
null
null otherwisepublic java.util.Iterator<ISenseEntry> getSenseEntryIterator()
IDictionary
getSenseEntryIterator in interface IDictionary
public IExceptionEntry getExceptionEntry(java.lang.String surfaceForm,
POS pos)
IDictionarynull
getExceptionEntry in interface IDictionarysurfaceForm - the surface form to be looked up; may not be null
, empty, or all whitespacepos - the part of speech; may not be null
null otherwisepublic IExceptionEntry getExceptionEntry(IExceptionEntryID id)
IDictionarynull
getExceptionEntry in interface IDictionaryid - the exception entry id of the entry to search for; may not be
null
public java.util.Iterator<IExceptionEntry> getExceptionEntryIterator(POS pos)
IDictionary
getExceptionEntryIterator in interface IDictionarypos - the part of speech over which to iterate; may not be
null
public static IRAMDictionary.IInputStreamFactory createInputStreamFactory(java.io.File file)
null.
file - the file out of which to make an input stream factory; may not
be null
null if the url
points to a local directory.
java.lang.NullPointerException - if the specified file is nullpublic static IRAMDictionary.IInputStreamFactory createInputStreamFactory(java.net.URL url)
null.
url - the url out of which to make an input stream factory; may not
be null
null if the url
points to a local directory.
java.lang.NullPointerException - if the specified url is nullpublic static IDictionary createBackingDictionary(java.io.File file)
DataSourceDictionary out of the specified file, as long
as the file points to an existing local directory.
file - the local directory for which to create a data source
dictionary; may not be null
null
java.lang.NullPointerException - if the specified file is nullpublic static IDictionary createBackingDictionary(java.net.URL url)
DataSourceDictionary out of the specified url, as long
as the url points to an existing local directory.
url - the local directory for which to create a data source
dictionary; may not be null
null
java.lang.NullPointerException - if the specified url is null
public static boolean export(java.io.File in,
java.io.OutputStream out)
throws java.io.IOException
in - the file from which the Wordnet data should be loaded; may not
be nullout - the output stream to which the Wordnet data should be written;
may not be null
true if the export was successful
java.lang.NullPointerException - if either argument is null
java.io.IOException - if there is an IO problem when opening or exporting the
dictionary.
public static boolean export(java.net.URL in,
java.io.OutputStream out)
throws java.io.IOException
in - the url from which the Wordnet data should be loaded; may not
be nullout - the output stream to which the Wordnet data should be written;
may not be null
true if the export was successful
java.lang.NullPointerException - if either argument is null
java.io.IOException - if there is an IO problem when opening or exporting the
dictionary.
public static boolean export(IRAMDictionary.IInputStreamFactory in,
java.io.OutputStream out)
throws java.io.IOException
in - the file from which the Wordnet data should be loaded; may not
be nullout - the output stream to which the Wordnet data should be written;
may not be null
true if the export was successful
java.lang.NullPointerException - if either argument is null
java.io.IOException - if there is an IO problem when opening or exporting the
dictionary.
protected static boolean export(IRAMDictionary dict,
java.io.OutputStream out)
throws java.io.IOException
dict - the dictionary to be exported; the dictionary will be closed
at the end of the method.out - the output stream to which the data will be written.
true if the export was successful
java.io.IOException - if there was a IO problem during export
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||