edu.mit.jwi
Class RAMDictionary

java.lang.Object
  extended by edu.mit.jwi.RAMDictionary
All Implemented Interfaces:
IClosable, IHasLifecycle, ILoadable, ILoadPolicy, IDictionary, IRAMDictionary, IHasVersion

public class RAMDictionary
extends Object
implements IRAMDictionary

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 (i.e., Wordnet located on the local filesystem, pointed to by a URL or File).

Note: If you receive an OutOfMemoryError while using this object, try increasing the heap size of your JVM, for example, by using the -Xmx switch.

Since:
JWI 2.2.0
Version:
2.2.2
Author:
Mark A. Finlayson

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.data.IHasLifecycle
IHasLifecycle.ObjectClosedException
 
Field Summary
protected  IDictionary backing
           
protected  RAMDictionary.DictionaryData data
           
protected  Lock lifecycleLock
           
protected  Thread loader
           
protected  Lock loadLock
           
protected  int loadPolicy
           
protected  IVersion version
           
 
Fields inherited from interface edu.mit.jwi.data.ILoadPolicy
BACKGROUND_LOAD, IMMEDIATE_LOAD, NO_LOAD
 
Constructor Summary
RAMDictionary(File file, int loadPolicy)
          Constructs a new wrapper RAM dictionary that will load the contents the specified local Wordnet data, with the specified load policy
RAMDictionary(IDictionary dict, int loadPolicy)
          Constructs a new wrapper RAM dictionary that will load the contents of the wrapped dictionary into memory, with the specified load policy
RAMDictionary(URL url, int loadPolicy)
          Constructs a new wrapper RAM dictionary that will load the contents the specified local Wordnet data, with the specified load policy
 
Method Summary
 void close()
          This closes the object by disposing of data backing objects or connections.
 IDictionary getBackingDictionary()
          Returns the dictionary that backs this instance.
 IExceptionEntry getExceptionEntry(IExceptionEntryID id)
          Retrieves the exception entry for the specified id from the database.
 IExceptionEntry getExceptionEntry(String surfaceForm, POS pos)
          Retrieves the exception entry for the specified surface form and part of speech from the database.
 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(String lemma, POS pos)
          This method is identical to getIndexWord(IIndexWordID) and is provided as a convenience.
 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.
 Iterator<ISenseEntry> getSenseEntryIterator()
          Returns an iterator that will iterate over all sense entries in the dictionary.
 ISynset getSynset(ISynsetID id)
          Retrieves the synset with the specified id from the database.
 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 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

backing

protected final IDictionary backing

lifecycleLock

protected final Lock lifecycleLock

loadLock

protected final Lock loadLock

loader

protected transient Thread loader

loadPolicy

protected int loadPolicy

version

protected IVersion version

data

protected RAMDictionary.DictionaryData data
Constructor Detail

RAMDictionary

public RAMDictionary(IDictionary dict,
                     int loadPolicy)
Constructs a new wrapper RAM dictionary that will load the contents of the wrapped dictionary into memory, with the specified load policy

Parameters:
dict - the dictionary to be wrapped
loadPolicy - the load policy of the dictionary; see constants in ILoadPolicy.
Since:
JWI 2.2.0
See Also:
ILoadPolicy

RAMDictionary

public RAMDictionary(URL url,
                     int loadPolicy)
Constructs a new wrapper RAM dictionary that will load the contents the specified local Wordnet data, with the specified load policy

Parameters:
url - a url pointing to a local copy of wordnet; may not be null
loadPolicy - the load policy of the dictionary; see constants in ILoadPolicy.
Throws:
NullPointerException - if the specified url is null
Since:
JWI 2.2.0
See Also:
ILoadPolicy

RAMDictionary

public RAMDictionary(File file,
                     int loadPolicy)
Constructs a new wrapper RAM dictionary that will load the contents the specified local Wordnet data, with the specified load policy

Parameters:
file - a file pointing to a local copy of wordnet; may not be null
loadPolicy - the load policy of the dictionary; see constants in ILoadPolicy.
Throws:
NullPointerException - if the specified file is null
Since:
JWI 2.2.0
See Also:
ILoadPolicy
Method Detail

getBackingDictionary

public IDictionary getBackingDictionary()
Returns the dictionary that backs this instance.

Returns:
the dictionary that backs this instance.
Since:
JWI 2.2.0

getLoadPolicy

public int getLoadPolicy()
Description copied from interface: ILoadPolicy
Returns the load policy for this object, expressed as an integer.

Specified by:
getLoadPolicy in interface ILoadPolicy
Returns:
the load policy for this object

setLoadPolicy

public void setLoadPolicy(int policy)
Description copied from interface: ILoadPolicy
Sets the load policy for this object. If the object is currently loaded, or in the process of loading, the load policy will not take effect until the next time objet is instantiated, initialized, or opened.

Specified by:
setLoadPolicy in interface ILoadPolicy
Parameters:
policy - the policy to implement; may be one of NO_LOAD, BACKGROUND_LOAD, IMMEDIATE_LOAD or an implementation-dependent value.

isLoaded

public boolean isLoaded()
Description copied from interface: ILoadable
Returns whether this object is loaded or not. This method should return true 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.

Specified by:
isLoaded in interface ILoadable
Returns:
true if the method has completed loading; false otherwise

load

public void load()
Description copied from interface: ILoadable
Starts a simple, non-blocking load. If the object is already loaded, the method returns immediately and has no effect. If the object is in the process of loading, the method also returns immediately.

Specified by:
load in interface ILoadable

load

public void load(boolean block)
          throws InterruptedException
Description copied from interface: ILoadable
Initiates the loading process. Depending on the flag, the method may return immediately (block 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.

Specified by:
load in interface ILoadable
Parameters:
block - if true, the method returns only when the loading process is complete; if false, the method returns immediately.
Throws:
InterruptedException - if the method is blocking, and is interrupted while waiting for loading to complete

open

public boolean open()
             throws IOException
Description copied from interface: IHasLifecycle
This opens the object by performing any required initialization steps. If this method returns false, then subsequent calls to IHasLifecycle.isOpen() will return false.

Specified by:
open in interface IHasLifecycle
Returns:
true if there were no errors in initialization; false otherwise.
Throws:
IOException - if there was IO error while performing initializataion

isOpen

public boolean isOpen()
Description copied from interface: IHasLifecycle
Returns true if the dictionary is open, that is, ready to accept queries; returns false otherwise

Specified by:
isOpen in interface IHasLifecycle
Returns:
true if the object is open; false otherwise

close

public void close()
Description copied from interface: IClosable
This closes the object by disposing of data backing objects or connections. If the object is already closed, or in the process of closing, this method does nothing (although, if the object is in the process of closing, it may block until closing is complete).

Specified by:
close in interface IClosable

getVersion

public IVersion getVersion()
Description copied from interface: IHasVersion
Returns the associated version for this object. If this object is not associated with any particular version, this method may return null.

Specified by:
getVersion in interface IHasVersion
Returns:
The associated version, or null if none.

getIndexWord

public IIndexWord getIndexWord(String lemma,
                               POS pos)
Description copied from interface: IDictionary
This method is identical to getIndexWord(IIndexWordID) and is provided as a convenience.

Specified by:
getIndexWord in interface IDictionary
Parameters:
lemma - the lemma for the index word requested; may not be null, empty, or all whitespace
pos - the part of speech; may not be null
Returns:
the index word corresponding to the specified lemma and part of speech, or null if none is found

getIndexWord

public IIndexWord getIndexWord(IIndexWordID id)
Description copied from interface: IDictionary
Retrieves the specified index word object from the database. If the specified lemma/part of speech combination is not found, returns null.

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.

Specified by:
getIndexWord in interface IDictionary
Parameters:
id - the id of the index word to search for; may not be null
Returns:
the index word, if found; null otherwise

getIndexWordIterator

public Iterator<IIndexWord> getIndexWordIterator(POS pos)
Description copied from interface: IDictionary
Returns an iterator that will iterate over all index words of the specified part of speech.

Specified by:
getIndexWordIterator in interface IDictionary
Parameters:
pos - the part of speech over which to iterate; may not be null
Returns:
an iterator that will iterate over all index words of the specified part of speech

getWord

public IWord getWord(IWordID id)
Description copied from interface: IDictionary
Retrieves the word with the specified id from the database. If the specified word is not found, returns null

Specified by:
getWord in interface IDictionary
Parameters:
id - the id of the word to search for; may not be null
Returns:
the word, if found; null otherwise

getWord

public IWord getWord(ISenseKey key)
Description copied from interface: IDictionary
Retrieves the word with the specified sense key from the database. If the specified word is not found, returns null

Specified by:
getWord in interface IDictionary
Parameters:
key - the sense key of the word to search for; may not be null
Returns:
the word, if found; null otherwise

getSynset

public ISynset getSynset(ISynsetID id)
Description copied from interface: IDictionary
Retrieves the synset with the specified id from the database. If the specified synset is not found, returns null

Specified by:
getSynset in interface IDictionary
Parameters:
id - the id of the synset to search for; may not be null
Returns:
the synset, if found; null otherwise

getSynsetIterator

public Iterator<ISynset> getSynsetIterator(POS pos)
Description copied from interface: IDictionary
Returns an iterator that will iterate over all synsets of the specified part of speech.

Specified by:
getSynsetIterator in interface IDictionary
Parameters:
pos - the part of speech over which to iterate; may not be null
Returns:
an iterator that will iterate over all synsets of the specified part of speech

getSenseEntry

public ISenseEntry getSenseEntry(ISenseKey key)
Description copied from interface: IDictionary
Retrieves the sense entry for the specified sense key from the database. If the specified sense key has no associated sense entry, returns null

Specified by:
getSenseEntry in interface IDictionary
Parameters:
key - the sense key of the entry to search for; may not be null
Returns:
the entry, if found; null otherwise

getSenseEntryIterator

public Iterator<ISenseEntry> getSenseEntryIterator()
Description copied from interface: IDictionary
Returns an iterator that will iterate over all sense entries in the dictionary.

Specified by:
getSenseEntryIterator in interface IDictionary
Returns:
an iterator that will iterate over all sense entries

getExceptionEntry

public IExceptionEntry getExceptionEntry(String surfaceForm,
                                         POS pos)
Description copied from interface: IDictionary
Retrieves the exception entry for the specified surface form and part of speech from the database. If the specified surface form/ part of speech pair has no associated exception entry, returns null

Specified by:
getExceptionEntry in interface IDictionary
Parameters:
surfaceForm - the surface form to be looked up; may not be null , empty, or all whitespace
pos - the part of speech; may not be null
Returns:
the entry, if found; null otherwise

getExceptionEntry

public IExceptionEntry getExceptionEntry(IExceptionEntryID id)
Description copied from interface: IDictionary
Retrieves the exception entry for the specified id from the database. If the specified id is not found, returns null

Specified by:
getExceptionEntry in interface IDictionary
Parameters:
id - the exception entry id of the entry to search for; may not be null
Returns:
the exception entry for the specified id

getExceptionEntryIterator

public Iterator<IExceptionEntry> getExceptionEntryIterator(POS pos)
Description copied from interface: IDictionary
Returns an iterator that will iterate over all exception entries of the specified part of speech.

Specified by:
getExceptionEntryIterator in interface IDictionary
Parameters:
pos - the part of speech over which to iterate; may not be null
Returns:
an iterator that will iterate over all exception entries of the specified part of speech


Copyright © 2011. All Rights Reserved.