2015-02-24 53 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