在WS4J中使用wu-palmer计算器来查找单词之间的相似性 [英] Use wu-palmer calculator in WS4J to find similarity between words
问题描述
我正在使用WS4j来查找两个单词之间的相似性。我也在使用Wu-Palmer相关性计算器。它适用于很多单词,但是当我试图找到'play'和'playing'之间的相似性时,它给出了得分1.3333,这是不可能的,因为它必须在0和1或-1之间返回。我无法弄清楚原因。当我使用其网页界面'http://ws4jdemo.appspot.com/?mode=w&s1=&w1=play&s2=&w2=playing'时,它返回0.875。
这是我的代码:
I am using WS4j to find the similarity between two words. Also I am using Wu-Palmer relatedness calculator. It is working fine for many words, but when I tried to find the similarity between 'play' and 'playing', it gave the score 1.3333, which is not possible as it has to return between 0 and 1 or -1. I can't figure out the reason. When I used its web interface 'http://ws4jdemo.appspot.com/?mode=w&s1=&w1=play&s2=&w2=playing' it returned 0.875.
Here is my code:
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);
}
我的尝试:
java - Wu- Palmer相关性计算器返回1.33333得分 - Stack Overflow [ ^ ]
推荐答案
您好y可以使用此代码:
ILexicalDatabase db = new NictWordNet();
WS4JConfiguration.getInstance()。setMFS(true);
RelatednessCalculator rc = new Lin(db);
String word1 =gender;
String word2 =sex;
List< POS []> posPairs = rc.getPOSPairs();
double maxScore = -1D;
for(POS [] posPair:posPairs){
列表< 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(概念synset2:synsets2){
相关性相关性= rc.calcRelatednessOfSynset(synset1,synset2);
double score = relatedness.getScore() ;
if(得分> maxScore){
maxScore =得分;
}
}
}
}
if(maxScore == -1D){
maxScore = 0.0;
}
System.out.println(sim('+ word1 +','+ word2 + ')=+ maxScore);
Hello y can use this code:
ILexicalDatabase db = new NictWordNet();
WS4JConfiguration.getInstance().setMFS(true);
RelatednessCalculator rc = new Lin(db);
String word1 = "gender";
String word2 = "sex";
List<POS[]> posPairs = rc.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 = rc.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);
这篇关于在WS4J中使用wu-palmer计算器来查找单词之间的相似性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!