|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.illinois.cs.cogcomp.lbj.coref.features.WordNetTools
public class WordNetTools
A collection of methods for dealing with WordNet, with functionality to look up words in WordNet and determine the synonyms, hypernyms, and antonyms. Since WordNet can be slow, also caches lookups. Provides facility for loading and saving from a file, enabling cache persistence.
Field Summary | |
---|---|
private java.util.Map<java.lang.String,java.lang.Boolean> |
areAntCache
|
private java.util.Map<java.lang.String,java.lang.Boolean> |
areHypCache
|
private java.util.Map<java.lang.String,java.lang.Boolean> |
areSynCache
|
private static java.lang.String |
m_className
|
private DictionaryDatabase |
m_dict
|
private static java.lang.String |
m_dsrBase
|
private static java.lang.String |
m_dsrName
|
private static java.lang.String |
m_packageName
|
private static WordNetTools |
m_wn
|
private static long |
serialVersionUID
|
private java.util.Map<java.lang.String,java.lang.Boolean> |
shareHypCache
|
private java.util.Map<java.lang.String,java.lang.Boolean> |
shareHypPOSCache
|
private java.util.Map<java.lang.String,java.lang.Boolean> |
shareSynCache
|
private java.util.Map<java.lang.String,IndexWord> |
wordCache
|
Constructor Summary | |
---|---|
WordNetTools()
Constructs a new WordNetTools object with empty caches. |
Method Summary | ||
---|---|---|
boolean |
areAntonyms(java.lang.String w1,
java.lang.String w2)
Determines whether two phrases are antonyms using WordNet. |
|
boolean |
areHypernyms(java.lang.String w1,
java.lang.String w2)
Determines whether one phrase is the hypernym of another using WordNet. |
|
boolean |
areSynonyms(java.lang.String w1,
java.lang.String w2)
Determines whether two phrases are synonyms using WordNet. |
|
java.util.Set<Word> |
getAllHypernyms(IndexWord word)
Gets all hypernyms of all senses of a word. |
|
java.util.Set<Word> |
getAllHypernyms(PointerTarget word)
Gets all hypernyms of a word. |
|
java.util.Set<Word> |
getAntonyms(IndexWord word)
Gets all antonyms for all senses of a word. |
|
protected static java.lang.String |
getFQDSRName()
Determines the location where the serialization file should be loaded or saved. |
|
java.util.Set<Word> |
getHypernyms(IndexWord word)
Gets hypernyms of all senses of a word. |
|
java.lang.String[] |
getHypernymStrings(java.lang.String word)
Looks up word and gets all hypernyms for all senses of a word. |
|
private IndexWord |
getIndexNoun(java.lang.String word)
Looks up the IndexWord of a string in WordNet. |
|
private IndexWord |
getIndexWord(java.lang.String word)
Looks up the IndexWord of a string in WordNet. |
|
private IndexWord |
getIndexWord(java.lang.String word,
java.lang.String pos)
Looks up the IndexWord of a string in WordNet. |
|
java.util.List<Word> |
getSenseWords(IndexWord word)
Gets the Word for each sense of word . |
|
java.util.Set<Word> |
getSynonyms(IndexWord word)
Gets all synonyms for all senses of a word. |
|
java.lang.String[] |
getSynonymStrings(java.lang.String word)
Looks up word and gets all synonyms for all senses of a word. |
|
static WordNetTools |
getWN()
Gets the singleton WordNetTools, with its associated caches. |
|
private Word |
getWord(PointerTarget p)
Translates a pointer target to a Word . |
|
private boolean |
hasLetters(java.lang.String phrase)
Determines whether a phrase has any letters. |
|
private java.lang.String |
join(java.lang.String a,
java.lang.String b)
|
|
private static WordNetTools |
loadWN()
Load the WN from a precomputed location. |
|
protected IndexWord |
lookupIndexNounSafe(java.lang.String word)
Looks up the IndexWord of a string in WordNet. |
|
protected IndexWord |
lookupIndexWordSafe(java.lang.String word,
java.lang.String pos)
Looks up the IndexWord of a string in WordNet. |
|
private
|
overlap(java.util.Set<T> a,
java.util.Collection<T> b)
|
|
void |
printSynsets(IndexWord word)
Writes the synsets of word to System.out . |
|
void |
printSynsets(java.lang.String word)
Writes the synsets of word to System.out . |
|
void |
readExternal(java.io.ObjectInput in)
|
|
private void |
readObject(java.io.ObjectInputStream in)
|
|
static void |
saveWN()
Saves the WordNetTools with its associated caches. |
|
boolean |
shareHypernyms(java.lang.String w1,
java.lang.String w2)
Determines whether two phrases share hypernyms using WordNet. |
|
boolean |
shareHypernymsPOS(java.lang.String w1,
java.lang.String w2)
Determines whether two phrases share hypernyms using WordNet. |
|
boolean |
shareSynonymns(java.lang.String w1,
java.lang.String w2)
Determines whether any sense of one phrase has the same synonym as any sense of another phrase. |
|
private void |
startup()
Load the underlying WordNet FileBackedDictionary. |
|
void |
writeExternal(java.io.ObjectOutput out)
Writes the object using the externalization protocol. |
|
private void |
writeObject(java.io.ObjectOutputStream out)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.lang.String m_packageName
private static java.lang.String m_className
private static final java.lang.String m_dsrBase
private static java.lang.String m_dsrName
private static WordNetTools m_wn
private transient DictionaryDatabase m_dict
private transient java.util.Map<java.lang.String,IndexWord> wordCache
private java.util.Map<java.lang.String,java.lang.Boolean> shareSynCache
private java.util.Map<java.lang.String,java.lang.Boolean> shareHypPOSCache
private java.util.Map<java.lang.String,java.lang.Boolean> shareHypCache
private java.util.Map<java.lang.String,java.lang.Boolean> areSynCache
private java.util.Map<java.lang.String,java.lang.Boolean> areHypCache
private java.util.Map<java.lang.String,java.lang.Boolean> areAntCache
private static final long serialVersionUID
Constructor Detail |
---|
public WordNetTools()
getWN()
Method Detail |
---|
private void startup()
java.lang.RuntimeException
- if the database cannot be loaded.public boolean areSynonyms(java.lang.String w1, java.lang.String w2)
w1
is synonymous with any sense of w2
,
or vice versa, returns true.
w1
- A string.w2
- Another string.
public boolean areAntonyms(java.lang.String w1, java.lang.String w2)
w1
is an antonym of any sense of w2
,
or vice versa, returns true.
w1
- A string.w2
- Another string.
public boolean areHypernyms(java.lang.String w1, java.lang.String w2)
w1
is a hypernym of any sense of w2
,
or vice versa, returns true.
Not restricted to direct hypernyms (other ancestors or descendants may
appear along the hypernym path between the two phrases).
w1
- A string.w2
- Another string.
public boolean shareHypernyms(java.lang.String w1, java.lang.String w2)
w1
is the hypernym of w2
,
or vice versa, returns true.
w1
- A string.w2
- Another string.
public boolean shareHypernymsPOS(java.lang.String w1, java.lang.String w2)
w1
is the hypernym of w2
,
or vice versa, returns true.
w1
- A string.w2
- Another string.
public boolean shareSynonymns(java.lang.String w1, java.lang.String w2)
w1
- A string.w2
- Another string.
public java.util.Set<Word> getSynonyms(IndexWord word)
word
- An entry in WordNet.
word
.public java.lang.String[] getSynonymStrings(java.lang.String word)
word
- Any string, assumed to be a noun.
word
.public java.util.Set<Word> getAntonyms(IndexWord word)
word
- An entry in WordNet.
word
.public java.util.Set<Word> getAllHypernyms(IndexWord word)
word
- An entry in WordNet.
word
.public java.util.Set<Word> getAllHypernyms(PointerTarget word)
word
- A pointer target entry in WordNet,
which may be a Word
or Synset
(in which case the first element will be used).
word
.public java.lang.String[] getHypernymStrings(java.lang.String word)
word
- Any string, assumed to be a noun.
word
.public java.util.Set<Word> getHypernyms(IndexWord word)
word
- An entry in WordNet.
word
.getAllHypernyms(IndexWord)
private Word getWord(PointerTarget p)
Word
.
If p
is a Synset, the first entry is returned.
p
- A pointer target representing a word or synset.
private IndexWord getIndexWord(java.lang.String word)
IndexWord
of a string in WordNet.
The string is assumed to be a noun (or noun phrase),
but if no such entry is found, it is assumed to be an adjective.
word
- The word or phrase to be looked up.
private IndexWord getIndexNoun(java.lang.String word)
IndexWord
of a string in WordNet.
The string is assumed to be a noun (or noun phrase).
word
- The word or phrase to be looked up.
private IndexWord getIndexWord(java.lang.String word, java.lang.String pos)
IndexWord
of a string in WordNet.
If the desired word is not found, the word will be backed-off
by attempting to add "s" or "es", and finally by using the
lookupBaseForm method (which result will only be accepted if at
least the length of word
minus 2).
This method is cached based on the word (ignoring the POS),
so a given word
string will always return the same
IndexWord, even if pos
differs.
word
- The word or phrase to be looked up.pos
- The part of speech of the desired entry, "NOUN" or "ADJ".
protected IndexWord lookupIndexNounSafe(java.lang.String word)
IndexWord
of a string in WordNet.
The string is assumed to be a noun (or noun phrase).
If the entry is not found, a shorter entry will NOT
be returned.
word
- The word or phrase to be looked up.
protected IndexWord lookupIndexWordSafe(java.lang.String word, java.lang.String pos)
IndexWord
of a string in WordNet.
This method is not cached.
so a given word
string will always return the same
IndexWord, even if pos
differs.
word
- The word or phrase to be looked up.
If punctuation or number, it will be ignored.pos
- The part of speech of the desired entry,
either "NOUN" or "ADJ".
private boolean hasLetters(java.lang.String phrase)
phrase
- any text.
public java.util.List<Word> getSenseWords(IndexWord word)
Word
for each sense of word
.
word
- The desired entry.
word
as Word
s.private <T> boolean overlap(java.util.Set<T> a, java.util.Collection<T> b)
private java.lang.String join(java.lang.String a, java.lang.String b)
public void printSynsets(java.lang.String word)
word
to System.out
.
word
- The noun or noun phrase.public void printSynsets(IndexWord word)
word
to System.out
.
word
- The word or phrase.private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public void readExternal(java.io.ObjectInput in)
readExternal
in interface java.io.Externalizable
public void writeExternal(java.io.ObjectOutput out)
writeExternal
in interface java.io.Externalizable
private static WordNetTools loadWN()
public static void saveWN()
protected static java.lang.String getFQDSRName()
loadWN()
,
saveWN()
public static WordNetTools getWN()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |