ws4j给出了得分1.3333,用于相似性度量,应该返回0到1之间的回报

时间:2018-01-29 22:57:19

标签: java nlp similarity wordnet ws4j

代码应该计算Wu和Palmer的相似性度量在0和1之间,但是给出的值大于1.我已经研究了类似的例子,但是我没有找到错误。

public class WordsSimilarity{
    public static void main(String[] args) {
    ILexicalDatabase db = new NictWordNet();
    RelatednessCalculator rc = new WuPalmer(db);
    String word1="cancer";
    POS posWord1=  POS.n;
    String word2= "disease";
    POS posWord2= POS.n;
    double maxScore = 0;


    try {
        WS4JConfiguration.getInstance().setMFS(true);

        List<Concept> synsets1 = (List<Concept>)db.getAllConcepts(word1, posWord1.name());
        List<Concept> synsets2 = (List<Concept>)db.getAllConcepts(word2, posWord2.name());

        for(Concept synset1: synsets1) {
            for (Concept synset2: synsets2) {
                Relatedness relatedness = rc.calcRelatednessOfSynset(synset1, synset2);
                double score = relatedness.getScore();
                if (score > maxScore) { 
                    maxScore = score;
                }
            }
        }

    }
    catch(Exception e) {

    }
    if (maxScore == -1D) {
        maxScore = 0.0;
    }

    System.out.println("Similarity score of " + word1 + " & " + word2 + " : " + maxScore);
    }
}

0 个答案:

没有答案