我正在使用extjwnl(extendedjavawordnet库),需要获得两个单词之间的路径相似性。
这是我现在的代码:
import net.sf.extjwnl.JWNLException;
import net.sf.extjwnl.data.IndexWord;
import net.sf.extjwnl.data.POS;
import net.sf.extjwnl.data.Synset;
import net.sf.extjwnl.dictionary.Dictionary;
import java.util.List;
public class WordNetTest {
public static void main(String[] args) {
try {
Dictionary dictionary = Dictionary.getDefaultResourceInstance();
IndexWord dog = dictionary.getIndexWord(POS.NOUN, "dog");
IndexWord cat = dictionary.getIndexWord(POS.NOUN, "cat");
List<Synset> dogSynset = dog.getSenses();
List<Synset> catSynset = cat.getSenses();
// TODO Get the path similarity between cat & dog
} catch (JWNLException e) {
e.printStackTrace();
}
}
}
在python中,使用nltk wordnet的等效方法是:
from nltk.corpus import wordnet as wn
dog = wn.synsets('dog')
cat = wn.synsets('cat')
print(dog.path_similarity(cat))
print(dog.lch_similarity(cat))
print(dog.wup_similarity(cat))
暂无答案!
目前还没有任何答案,快来回答吧!