Reputation: 9356
I have extracted the synsets for each word. Now I want to get the domain or category for each synset meaning for example that if I have the word light
I want to get physics
i.e. the domain(s) of the synset.
Now supposing I have the synset sense
this should be done by:
Pointer[] domain = sense.getPointers(PointerType.CATEGORY);
By doing this I get always domain" empty
error. Where am I wrong?
Furthermore, is there a way to get a string indicating the domain?
Upvotes: 0
Views: 1128
Reputation: 109
Thank you so much for posting your solution. It is a good example and it becomes very useful for me. However I thought I can also share this with the rest of the community.
WordNet has a hypernym / hyponym hierarchy. For instance, when you look up goalkeeper:
Synset('physical_entity.n.01')
Synset('causal_agent.n.01')
Synset('person.n.01')
Synset('contestant.n.01')
Synset('athlete.n.01')
Synset('soccer_player.n.01')
Synset('goalkeeper.n.01')
However, using WordNet Domains project could be a different approach. Going back to the goalkeeper example, it can return [sport->football; sport->hockey] or [football;hockey] or just 'football'
For more information please feel free to check out Get WordNet's domain name for the specified word
Upvotes: 0
Reputation: 9356
Ok, nobody seems interested in it but I'll post my working solution.
//'WordnetPOS' is an instance of the class POS defined in JWNL. It indicates the part of
//speech tag. token
JWNL.initialize(new FileInputStream("path/file_properties.xml"));
Dictionary wordnet = Dictionary.getInstance();
IndexWord token = wordnet.lookupIndexWord(WordnetPos, word); //word is a string
Synset[] senses = token.getSenses();
String Dom = new String();
for (int i = 0; i < senses.length; i++) {
String domSet = new String();
try {
//CATEGORY is the pointer type of the synset containing the domains
Pointer[] pointerArr = senses[i].getPointers(PointerType.CATEGORY);
for (Pointer pointer : pointerArr) {
Synset syn = pointer.getTargetSynset();
Word[] words = syn.getWords();
for (Word word : words) {
domaSet = domaSet + word.getLemma().trim().toLowerCase() + " ";
}
}
catch (NullPointerException e) {
}
Dom = Dom + domSet;
}
Upvotes: 1