net.sf.extjwnl.dictionary
Class Dictionary

java.lang.Object
  extended by net.sf.extjwnl.dictionary.Dictionary
Direct Known Subclasses:
AbstractCachingDictionary, MapBackedDictionary

public abstract class Dictionary
extends Object

Abstract representation of a WordNet dictionary. See the architecture documentation for information on subclassing Dictionary.

Author:
John Didion , Aliaksandr Autayeu

Nested Class Summary
static class Dictionary.Version
          Represents a version of WordNet.
 
Field Summary
static String CHECK_LEX_IDS_KEY
          Whether to check and fix lexicographer ids, default true.
protected  HashMap<POS,Long> maxOffset
           
protected  Map<String,Param> params
           
 
Constructor Summary
protected Dictionary()
          Create a Dictionary that does not do morphological processing.
protected Dictionary(Document doc)
           
protected Dictionary(MorphologicalProcessor morph)
          Create a Dictionary using the specified MorphologicalProcessor.
 
Method Summary
 void addElement(DictionaryElement element)
          Adds dictionary element to the dictionary.
 void addException(Exc exc)
          Adds exception to the dictionary.
 void addIndexWord(IndexWord indexWord)
          Adds index word to the dictionary.
 void addSynset(Synset synset)
          Adds synset to the dictionary.
abstract  void close()
          Shut down the dictionary
 Exc createException(POS pos, String lemma, List<String> exceptions)
          Creates an exception in the dictionary.
 IndexWord createIndexWord(POS pos, String lemma, Synset synset)
          Creates index word.
 Synset createSynset(POS pos)
          Creates synset of the specified part of speech.
 void delete()
           
 void edit()
          Puts the dictionary into edit mode.
static Dictionary getDatabaseBackedInstance(String dbURL)
          Returns DatabaseBackedDictionary instance with default configuration.
abstract  Exc getException(POS pos, String derivation)
          Lookup derivation in the exceptions file of part-of-speech pos and return an Exc object containing the results.
abstract  Iterator<Exc> getExceptionIterator(POS pos)
          Return an Iterator over all the Exceptions in the database.
static Dictionary getFileBackedInstance(String dictionaryPath)
          Returns FileBackedDictionary instance with default configuration.
abstract  IndexWord getIndexWord(POS pos, String lemma)
          Look up a word in the database.
abstract  Iterator<IndexWord> getIndexWordIterator(POS pos)
          Return an Iterator over all the IndexWords of part-of-speech pos in the database.
abstract  Iterator<IndexWord> getIndexWordIterator(POS pos, String substring)
          Return an Iterator over all the IndexWords of part-of-speech pos whose lemmas contain substring as a substring.
static Dictionary getInstance()
           
static Dictionary getInstance(InputSource properties)
          Parses properties and creates a dictionary.
static Dictionary getInstance(InputStream properties)
          Parses a properties file and creates a dictionary.
static Dictionary getMapBackedInstance(String dictionaryPath)
          Returns MapBackedDictionary instance with default configuration.
 MorphologicalProcessor getMorphologicalProcessor()
           
abstract  IndexWord getRandomIndexWord(POS pos)
           
static Dictionary getRestoreDictionary()
           
abstract  Synset getSynsetAt(POS pos, long offset)
          Return the Synset at offset offset from the database.
abstract  Iterator<Synset> getSynsetIterator(POS pos)
          Return an Iterator over all the Synsets of part-of-speech pos in the database.
 Dictionary.Version getVersion()
          Returns the current WordNet version.
 boolean isEditable()
          Returns whether the dictionary is editable.
 IndexWordSet lookupAllIndexWords(String lemma)
          Return a set of IndexWords, with each element in the set corresponding to a part-of-speech of word.
 IndexWord lookupIndexWord(POS pos, String lemma)
          Main word lookup procedure.
protected static String prepareQueryString(String lemma)
          Prepares the lemma for being used in a lookup operation.
 void removeElement(DictionaryElement element)
          Removes the dictionary element from the dictionary.
 void removeException(Exc exc)
          Removes the exc from the dictionary.
 void removeIndexWord(IndexWord indexWord)
          Removes indexWord from the dictionary.
 void removeSynset(Synset synset)
          Removes synset from the dictionary.
 void save()
          Saves the dictionary.
static Dictionary setInstance(Dictionary dictionary)
           
 void setMorphologicalProcessor(MorphologicalProcessor morph)
           
static void setRestoreDictionary(Dictionary dictionary)
           
static void uninstall()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHECK_LEX_IDS_KEY

public static final String CHECK_LEX_IDS_KEY
Whether to check and fix lexicographer ids, default true.

See Also:
Constant Field Values

params

protected Map<String,Param> params

maxOffset

protected HashMap<POS,Long> maxOffset
Constructor Detail

Dictionary

protected Dictionary()
Create a Dictionary that does not do morphological processing.


Dictionary

protected Dictionary(MorphologicalProcessor morph)
Create a Dictionary using the specified MorphologicalProcessor.

Parameters:
morph - MorphologicalProcessor to use

Dictionary

protected Dictionary(Document doc)
              throws JWNLException
Throws:
JWNLException
Method Detail

getInstance

public static Dictionary getInstance()

getInstance

public static Dictionary getInstance(InputStream properties)
                              throws JWNLException
Parses a properties file and creates a dictionary.

Parameters:
properties - the properties file stream
Returns:
dictionary
Throws:
JWNLException - various JWNL exceptions, depending on where this fails

getInstance

public static Dictionary getInstance(InputSource properties)
                              throws JWNLException
Parses properties and creates a dictionary.

Parameters:
properties - input source with properties
Returns:
dictionary
Throws:
JWNLException - various JWNL exceptions, depending on where this fails

getFileBackedInstance

public static Dictionary getFileBackedInstance(String dictionaryPath)
                                        throws JWNLException
Returns FileBackedDictionary instance with default configuration.

Parameters:
dictionaryPath - dictionary path
Returns:
FileBackedDictionary instance with default configuration
Throws:
JWNLException - JWNLException

getMapBackedInstance

public static Dictionary getMapBackedInstance(String dictionaryPath)
                                       throws JWNLException
Returns MapBackedDictionary instance with default configuration.

Parameters:
dictionaryPath - dictionary path
Returns:
MapBackedDictionary instance with default configuration
Throws:
JWNLException - JWNLException

getDatabaseBackedInstance

public static Dictionary getDatabaseBackedInstance(String dbURL)
                                            throws JWNLException
Returns DatabaseBackedDictionary instance with default configuration.

Parameters:
dbURL - database url
Returns:
DatabaseBackedDictionary instance with default configuration
Throws:
JWNLException - JWNLException

setInstance

public static Dictionary setInstance(Dictionary dictionary)

uninstall

public static void uninstall()

setRestoreDictionary

public static void setRestoreDictionary(Dictionary dictionary)

getRestoreDictionary

public static Dictionary getRestoreDictionary()

getIndexWordIterator

public abstract Iterator<IndexWord> getIndexWordIterator(POS pos)
                                                  throws JWNLException
Return an Iterator over all the IndexWords of part-of-speech pos in the database.

Parameters:
pos - The part-of-speech
Returns:
An iterator over IndexWords
Throws:
JWNLException - JWNLException

getIndexWordIterator

public abstract Iterator<IndexWord> getIndexWordIterator(POS pos,
                                                         String substring)
                                                  throws JWNLException
Return an Iterator over all the IndexWords of part-of-speech pos whose lemmas contain substring as a substring.

Parameters:
pos - The part-of-speech.
substring - substring
Returns:
An iterator over IndexWords.
Throws:
JWNLException - JWNLException

getIndexWord

public abstract IndexWord getIndexWord(POS pos,
                                       String lemma)
                                throws JWNLException
Look 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, use lookupIndexWord(POS, String).

Parameters:
pos - The part-of-speech.
lemma - The orthographic representation of the word.
Returns:
An IndexWord representing the word, or null if no such entry exists.
Throws:
JWNLException - JWNLException

getRandomIndexWord

public abstract IndexWord getRandomIndexWord(POS pos)
                                      throws JWNLException
Throws:
JWNLException

getSynsetIterator

public abstract Iterator<Synset> getSynsetIterator(POS pos)
                                            throws JWNLException
Return an Iterator over all the Synsets of part-of-speech pos in the database.

Parameters:
pos - The part-of-speech.
Returns:
An iterator over Synsets.
Throws:
JWNLException - JWNLException

getSynsetAt

public abstract Synset getSynsetAt(POS pos,
                                   long offset)
                            throws JWNLException
Return the Synset at offset offset from the database.

Parameters:
pos - The part-of-speech file to look in
offset - The offset of the synset in the file
Returns:
A synset containing the parsed line from the database
Throws:
JWNLException - JWNLException

getExceptionIterator

public abstract Iterator<Exc> getExceptionIterator(POS pos)
                                            throws JWNLException
Return an Iterator over all the Exceptions in the database.

Parameters:
pos - the part-of-speech
Returns:
Iterator An iterator over Excs
Throws:
JWNLException - JWNLException

getException

public abstract Exc getException(POS pos,
                                 String derivation)
                          throws JWNLException
Lookup derivation in the exceptions file of part-of-speech pos and return an Exc object containing the results.

Parameters:
pos - the exception file to look in
derivation - the word to look up
Returns:
Exc the Exc object
Throws:
JWNLException - JWNLException

close

public abstract void close()
Shut down the dictionary


getMorphologicalProcessor

public MorphologicalProcessor getMorphologicalProcessor()

setMorphologicalProcessor

public void setMorphologicalProcessor(MorphologicalProcessor morph)

lookupIndexWord

public IndexWord lookupIndexWord(POS pos,
                                 String lemma)
                          throws JWNLException
Main word lookup procedure. First try a normal lookup. If that doesn't work, try looking up the stemmed form of the lemma.

Parameters:
pos - the part-of-speech of the word to look up
lemma - the lemma to look up
Returns:
IndexWord the IndexWord found by the lookup procedure, or null if an IndexWord is not found
Throws:
JWNLException - JWNLException

lookupAllIndexWords

public IndexWordSet lookupAllIndexWords(String lemma)
                                 throws JWNLException
Return a set of IndexWords, with each element in the set corresponding to a part-of-speech of word.

Parameters:
lemma - the word for which to lookup senses
Returns:
An array of IndexWords, each of which is a sense of word
Throws:
JWNLException - JWNLException

getVersion

public Dictionary.Version getVersion()
Returns the current WordNet version.

Returns:
current WordNet version

isEditable

public boolean isEditable()
Returns whether the dictionary is editable.

Returns:
whether the dictionary is editable

edit

public void edit()
          throws JWNLException
Puts the dictionary into edit mode.

Throws:
JWNLException - JWNLException

save

public void save()
          throws JWNLException
Saves the dictionary.

Throws:
JWNLException - JWNLException

delete

public void delete()
            throws JWNLException
Throws:
JWNLException

addElement

public void addElement(DictionaryElement element)
                throws JWNLException
Adds dictionary element to the dictionary.

Parameters:
element - element to add
Throws:
JWNLException - JWNLException

removeElement

public void removeElement(DictionaryElement element)
                   throws JWNLException
Removes the dictionary element from the dictionary.

Parameters:
element - element to be removed
Throws:
JWNLException - JWNLException

createException

public Exc createException(POS pos,
                           String lemma,
                           List<String> exceptions)
                    throws JWNLException
Creates an exception in the dictionary.

Parameters:
pos - exception part of speech
lemma - exception lemma
exceptions - list of base forms
Returns:
exception object
Throws:
JWNLException - JWNLException

addException

public void addException(Exc exc)
                  throws JWNLException
Adds exception to the dictionary.

Parameters:
exc - exception to add
Throws:
JWNLException - JWNLException

removeException

public void removeException(Exc exc)
                     throws JWNLException
Removes the exc from the dictionary.

Parameters:
exc - exc to be removed
Throws:
JWNLException - JWNLException

createSynset

public Synset createSynset(POS pos)
                    throws JWNLException
Creates synset of the specified part of speech.

Parameters:
pos - part of speech
Returns:
synset object
Throws:
JWNLException - JWNLException

addSynset

public void addSynset(Synset synset)
               throws JWNLException
Adds synset to the dictionary.

Parameters:
synset - synset to add
Throws:
JWNLException - JWNLException

removeSynset

public void removeSynset(Synset synset)
                  throws JWNLException
Removes synset from the dictionary.

Parameters:
synset - synset to remove
Throws:
JWNLException - JWNLException

createIndexWord

public IndexWord createIndexWord(POS pos,
                                 String lemma,
                                 Synset synset)
                          throws JWNLException
Creates index word.

Parameters:
pos - part of speech
lemma - lemma
synset - synset
Returns:
index word object
Throws:
JWNLException - JWNLException

addIndexWord

public void addIndexWord(IndexWord indexWord)
                  throws JWNLException
Adds index word to the dictionary.

Parameters:
indexWord - index word to add
Throws:
JWNLException - JWNLException

removeIndexWord

public void removeIndexWord(IndexWord indexWord)
                     throws JWNLException
Removes indexWord from the dictionary.

Parameters:
indexWord - index word to remove
Throws:
JWNLException - JWNLException

prepareQueryString

protected static String prepareQueryString(String lemma)
Prepares the lemma for being used in a lookup operation. Specifically, this method trims whitespace and converts the lemma to lower case.

Parameters:
lemma - the lemma to be prepared
Returns:
String the prepared lemma


Copyright © 2011. All Rights Reserved.