我已经为每个单词提取了同义词集。现在我想获取每个synset的域或类别,例如,如果我有单词light
,我想获得physics
,即synset的域。
现在假设我有synset sense
,这应该通过以下方式完成:
Pointer[] domain = sense.getPointers(PointerType.CATEGORY);
通过这样做,我总是遇到domain" empty
错误。我哪里错了?
此外,有没有办法获得一个表明域的字符串?
答案 0 :(得分:1)
好的,似乎没有人对它感兴趣,但我会发布我的工作解决方案。
//'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;
}
答案 1 :(得分:0)
非常感谢您发布解决方案。这是一个很好的例子,它对我来说非常有用。但是我想我也可以和社区其他人分享这个。
WordNet有一个上位词/下位词层次结构。例如,当你查找守门员时:
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')
但是,使用WordNet域名项目可能是一种不同的方法。回到守门员的例子,它可以返回[sport-&gt; football;运动 - >曲棍球]或[足球;曲棍球]或只是&#39;足球&#39;
如需了解更多信息,请随时查看Get WordNet's domain name for the specified word