wordnet:如何获得路径相似性?

6bc51xsx  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(235)

我正在使用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))

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题