我已经提取了每个单词的同义词集。现在我想获取每个同义词集的域或类别,这意味着例如,如果我有单词 light
我想获取 physicals
即同义词集的域.
现在假设我有同义词集 sense
这应该通过以下方式完成:
Pointer[] domain = sense.getPointers(PointerType.CATEGORY);
通过这样做,我总是得到 domain"empty
错误。我哪里错了?
此外,有没有办法获取表示域的字符串?
最佳答案
好吧,似乎没有人对此感兴趣,但我会发布我的工作解决方案。
//'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;
}
关于java - 如何获取 Java WordNet 库中的类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19774359/