2015-02-24 95 views
1

我需要找出两个输入词之间的语义相似性/相关性。下面的话是相似的或现实世界相关: -两个“词”之间的语义相似性/相关性的Java API

- 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)); 

了我使用WS4J API(ws4j1.0.1.jar)与Java 1.7在Eclipse 3.4中。我得到以下结果是没有意义的,或者可能是我的看法是错误的。

enter image description here

如果我的做法是错误的,请让我知道如果我要工作了词与词之间的相似性,那么我应该使用什么其他的API。

回答

0

看起来好像是你已经配置了数据集都没有找到的话,那么它只是返回的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)); 

不幸的是,我不知道你的配置是什么样的,你提供的链接似乎不起作用(至少,至少)。然而,在Google Code的JAR的ws4j 1.0.1包括它自己的信息内容文件(名为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. 

使用此设置,对于您在表格中列出的字词,我会得到相同的结果。因此,您应该更多地了解各个度量标准的各个实现的配置。

+0

@ jaykio77:如果它对你有帮助,你能接受这个答案吗? - 我目前正在挖掘一些额外的声望点。非常感谢。 – errantlinguist 2016-04-13 18:06:54