public class WordNet
extends java.lang.Object
implements java.io.Serializable
// WordNet synset definitions
File synsetDef=new File("wn_s.pl");
// Choose hyponomy
File relationDef=new File("wn_hyp.pl");
// Choose to store only nouns and verbs
EnumSet types
=EnumSet.of(WordNet.WordType.NOUN,WordNet.WordType.VERB);
// Choose to store only two senses per word
int sensesPerWord=2;
WordNet w=new WordNet(synsetDef,relationDef,types,sensesPerWord);
for(Synset s : w.synsetsFor("mouse")) {
D.p(s); // Print synset
D.p(" "+s.getUps()); // Print direct supersynsets
}
-->
Synset #102244530 (NOUN): [mouse, ]
[Synset #102243671 (NOUN): [rodent, gnawer, gnawing_animal, ]]
Synset #103651364 (NOUN): [mouse, computer_mouse, ]
[Synset #103158939 (NOUN): [electronic_device, ]]
Synset #201175362 (VERB): [mouse, ]
[Synset #201174946 (VERB): [manipulate, ]]
Synset #201856050 (VERB): [sneak, mouse, creep, pussyfoot, ]
[Synset #201849285 (VERB): [walk, ]]
Note that if you load only n senses per word, there may be synsets in the WordNet instance
that do not have words!| Modifier and Type | Class and Description |
|---|---|
static class |
WordNet.Synset
Represents a WordNet synset
|
static class |
WordNet.WordType
Types of words in Wordnet
|
| Modifier and Type | Field and Description |
|---|---|
static int |
CLASSGROUP |
static int |
DOWNGROUP |
protected java.util.Map<java.lang.Integer,WordNet.Synset> |
id2synset
Maps ids to synsets (compiled on demand)
|
static int |
IDGROUP |
static java.util.regex.Pattern |
RELATIONPATTERN
Pattern for relation definitions
|
static int |
SENSENUMGROUP |
protected WordNet.Synset |
source
Holds the current source synset for NCA calculi
|
static java.util.regex.Pattern |
SYNSETPATTERN
Pattern for synset definitions
|
static int |
UPGROUP |
java.util.Map<java.lang.String,java.util.List<WordNet.Synset>> |
word2synsets
Maps words to synsets
|
static int |
WORDGROUP |
| Constructor and Description |
|---|
WordNet(java.io.File wn_s,
java.util.EnumSet<WordNet.WordType> lextypes,
int sensesPerWord)
Constructor with no relation (only synsets)
|
WordNet(java.io.File wn_s,
java.io.File relation,
java.util.EnumSet<WordNet.WordType> lextypes,
int sensesPerWord)
Constructor (main constructor)
|
WordNet(java.io.File wn_s,
java.io.File relation,
WordNet.WordType lextype,
int sensesPerWord)
Constructor
|
WordNet(java.io.File wn_s,
WordNet.WordType lextype,
int sensesPerWord)
Constructor with no relation (only synsets)
|
| Modifier and Type | Method and Description |
|---|---|
int |
ancestor(WordNet.Synset s1,
WordNet.Synset s2)
Returns the distance in the hierarchy upwards from the first node to the second, -1 in case of failure
|
int |
distance(WordNet.Synset s1,
WordNet.Synset s2)
Returns the length of s1->NCA->s2, -1 in case of failure
|
java.util.Map<java.lang.Integer,WordNet.Synset> |
getId2SynsetMap()
Returns the map from ids to synsets
|
WordNet.Synset |
getSynset(int id)
Returns a synset for a given id
|
java.util.Collection<WordNet.Synset> |
getSynsets()
Compiles the set of all Synsets
|
static void |
main(java.lang.String[] argv)
Test routine, requires the Prolog version of WordNet and the paths adjusted.
|
protected WordNet.Synset |
nca(WordNet.Synset destination,
int[] dist,
int d)
Finds the NCA by help of labels
|
WordNet.Synset |
nca(WordNet.Synset s1,
WordNet.Synset s2)
Returns the nearest common ancestor of two synsets.
|
WordNet.Synset |
nca(WordNet.Synset source,
WordNet.Synset destination,
int[] dist1,
int[] dist2)
Returns the nearest common ancestor of two synsets.
|
int |
numSynsets()
Returns the number of synsets
|
void |
remove(WordNet.Synset s)
Removes a synset
|
protected void |
setSource(WordNet.Synset start)
Sets the source for an NCA or distance calculus
|
protected void |
setSource(WordNet.Synset start,
int dist)
Labels all up's of a synset with their distance from start
|
WordNet.Synset |
synsetFor(java.lang.String word,
java.lang.String otherWord)
Returns the synset that contain two words
|
java.util.List<WordNet.Synset> |
synsetsFor(java.lang.String s)
Returns the list of synsets that contain a word
|
java.lang.String |
toString()
Returns a short String description
|
public static java.util.regex.Pattern SYNSETPATTERN
public static final int IDGROUP
public static final int WORDGROUP
public static final int CLASSGROUP
public static final int SENSENUMGROUP
public static java.util.regex.Pattern RELATIONPATTERN
public static final int DOWNGROUP
public static final int UPGROUP
protected WordNet.Synset source
public java.util.Map<java.lang.String,java.util.List<WordNet.Synset>> word2synsets
protected java.util.Map<java.lang.Integer,WordNet.Synset> id2synset
public WordNet(java.io.File wn_s,
java.util.EnumSet<WordNet.WordType> lextypes,
int sensesPerWord)
throws java.io.IOException
java.io.IOExceptionpublic WordNet(java.io.File wn_s,
WordNet.WordType lextype,
int sensesPerWord)
throws java.io.IOException
java.io.IOExceptionpublic WordNet(java.io.File wn_s,
java.io.File relation,
WordNet.WordType lextype,
int sensesPerWord)
throws java.io.IOException
java.io.IOExceptionpublic WordNet(java.io.File wn_s,
java.io.File relation,
java.util.EnumSet<WordNet.WordType> lextypes,
int sensesPerWord)
throws java.io.IOException
java.io.IOExceptionpublic java.util.Map<java.lang.Integer,WordNet.Synset> getId2SynsetMap()
public WordNet.Synset getSynset(int id)
public java.util.Collection<WordNet.Synset> getSynsets()
public java.util.List<WordNet.Synset> synsetsFor(java.lang.String s)
public int numSynsets()
public WordNet.Synset synsetFor(java.lang.String word, java.lang.String otherWord)
public java.lang.String toString()
toString in class java.lang.Objectprotected void setSource(WordNet.Synset start, int dist)
protected void setSource(WordNet.Synset start)
protected WordNet.Synset nca(WordNet.Synset destination, int[] dist, int d)
public WordNet.Synset nca(WordNet.Synset source, WordNet.Synset destination, int[] dist1, int[] dist2)
public WordNet.Synset nca(WordNet.Synset s1, WordNet.Synset s2)
public int distance(WordNet.Synset s1, WordNet.Synset s2)
public int ancestor(WordNet.Synset s1, WordNet.Synset s2)
public void remove(WordNet.Synset s)
public static void main(java.lang.String[] argv)
throws java.lang.Exception
java.lang.Exception