public class WordNet extends Object implements 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<WordNet.WordType> 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 Map<Integer,WordNet.Synset> |
id2synset
Maps ids to synsets (compiled on demand)
|
static int |
IDGROUP |
static Pattern |
RELATIONPATTERN
Pattern for relation definitions
|
static int |
SENSENUMGROUP |
protected WordNet.Synset |
source
Holds the current source synset for NCA calculi
|
static Pattern |
SYNSETPATTERN
Pattern for synset definitions
|
static int |
UPGROUP |
Map<String,List<WordNet.Synset>> |
word2synsets
Maps words to synsets
|
static int |
WORDGROUP |
| Constructor and Description |
|---|
WordNet(File wn_s,
EnumSet<WordNet.WordType> lextypes,
int sensesPerWord)
Constructor with no relation (only synsets)
|
WordNet(File wn_s,
File relation,
EnumSet<WordNet.WordType> lextypes,
int sensesPerWord)
Constructor (main constructor)
|
WordNet(File wn_s,
File relation,
WordNet.WordType lextype,
int sensesPerWord)
Constructor
|
WordNet(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
|
Map<Integer,WordNet.Synset> |
getId2SynsetMap()
Returns the map from ids to synsets
|
WordNet.Synset |
getSynset(int id)
Returns a synset for a given id
|
Collection<WordNet.Synset> |
getSynsets()
Compiles the set of all Synsets
|
static void |
main(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(String word,
String otherWord)
Returns the synset that contain two words
|
List<WordNet.Synset> |
synsetsFor(String s)
Returns the list of synsets that contain a word
|
String |
toString()
Returns a short String description
|
public static Pattern SYNSETPATTERN
public static final int IDGROUP
public static final int WORDGROUP
public static final int CLASSGROUP
public static final int SENSENUMGROUP
public static Pattern RELATIONPATTERN
public static final int DOWNGROUP
public static final int UPGROUP
protected WordNet.Synset source
public Map<String,List<WordNet.Synset>> word2synsets
protected Map<Integer,WordNet.Synset> id2synset
public WordNet(File wn_s, EnumSet<WordNet.WordType> lextypes, int sensesPerWord) throws IOException
IOExceptionpublic WordNet(File wn_s, WordNet.WordType lextype, int sensesPerWord) throws IOException
IOExceptionpublic WordNet(File wn_s, File relation, WordNet.WordType lextype, int sensesPerWord) throws IOException
IOExceptionpublic WordNet(File wn_s, File relation, EnumSet<WordNet.WordType> lextypes, int sensesPerWord) throws IOException
IOExceptionpublic Map<Integer,WordNet.Synset> getId2SynsetMap()
public WordNet.Synset getSynset(int id)
public Collection<WordNet.Synset> getSynsets()
public List<WordNet.Synset> synsetsFor(String s)
public int numSynsets()
public WordNet.Synset synsetFor(String word, String otherWord)
public String toString()
protected 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)
Copyright © 2018. All rights reserved.