我需要找出两个输入单词之间的语义相似性/相关性。以下单词在现实世界中相似或相关:-
- genuineness, genuine, genuinely, valid, reality, fact, really
- painter, painting, paint
以下是我从 here 中截取的代码片段
ILexicalDatabase db = new NictWordNet();
RelatednessCalculator lin = new Lin(db);
RelatednessCalculator wup = new WuPalmer(db);
RelatednessCalculator path = new Path(db);
String w1 = "truth";
String w2 = "genuine";
System.out.println(lin.calcRelatednessOfWords(w1, w2));
System.out.println(wup.calcRelatednessOfWords(w1, w2));
System.out.println(path.calcRelatednessOfWords(w1, w2));
我在 eclipse 3.4 中使用 WS4J Api (ws4j1.0.1.jar) 和 java 1.7。我得到的结果毫无意义,或者可能是我的看法是错误的。
如果我的方法是错误的,请告诉我,如果我想计算单词之间的相似度,那么我应该使用什么其他API。
最佳答案
您配置的数据集中似乎没有找到这些单词,因此它只是返回 0.0
分数:例如,以下无意义单词也会导致 0.0
分数:
ILexicalDatabase db = new NictWordNet();
RelatednessCalculator lin = new Lin(db);
RelatednessCalculator wup = new WuPalmer(db);
RelatednessCalculator path = new Path(db);
String w1 = "iamatotallycompletelyfakewordwithagermanwordinsidevergnügen";
String w2 = "iamevenmorefakeandstrangerossiskajafoderatsija";
System.out.println(lin.calcRelatednessOfWords(w1, w2));
System.out.println(wup.calcRelatednessOfWords(w1, w2));
System.out.println(path.calcRelatednessOfWords(w1, w2));
不幸的是,我无法判断您的配置是什么样的,并且您提供的链接似乎不起作用(至少不再起作用)。但是,ws4j 1.0.1 的 JAR 位于 Google Code包括其自己的信息内容文件(名为ic-semcor.dat),该文件在文件similarity.conf中配置:
# ----------------------------------------------------------------------
# The following option is supported by :
# res, lin, jcn
infocontent = ic-semcor.dat
# Specifies the name of an information content file under
# data/. The value of this option must be the name of a
# file, or a relative or absolute path name. The default
# value of this option ic-semcor.dat.
使用此设置,对于您在表格中列出的单词,我会得到相同的结果。因此,您应该更多地了解不同指标的各个 RelatednessCalculator
实现的配置。
关于用于两个之间语义相似性/相关性的 Java API "WORDS",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28703187/