我正在使用 WS4j 来查找两个单词之间的相似性。我也在使用 Wu-Palmer 相关性计算器。它适用于许多单词,但是当我试图找到“play”和“playing”之间的相似性时,它给出的分数是 1.3333,这是不可能的,因为它必须在 0 和 1 或 -1 之间返回。我想不出原因。当我使用它的网络界面' http://ws4jdemo.appspot.com/?mode=w&s1=&w1=play&s2=&w2=playing '它返回0.875。这是我的代码:
private static void findSimilarity(String word1, String word2) {
WS4JConfiguration.getInstance().setMFS(true);
List<POS[]> posPairs = wup.getPOSPairs();
double maxScore = -1D;
for(POS[] posPair: posPairs) {
List<Concept> synsets1 =
(List<Concept>)db.getAllConcepts(word1, posPair[0].toString());
List<Concept> synsets2 =
(List<Concept>)db.getAllConcepts(word2, posPair[1].toString());
for(Concept synset1: synsets1) {
for (Concept synset2: synsets2) {
Relatedness relatedness = wup.calcRelatednessOfSynset(synset1, synset2);
double score = relatedness.getScore();
if (score > maxScore) {
maxScore = score;
}
}
}
}
if (maxScore == -1D) {
maxScore = 0.0;
}
System.out.println("sim('" + word1 + "', '" + word2 + "') = " + maxScore);
}