1

我需要找出两个输入词之间的语义相似性/相关性。以下单词在现实世界中相似或相关:-

- genuineness, genuine, genuinely, valid, reality, fact, really   
- painter, painting, paint

以下是我从这里截取的代码

    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。

4

1 回答 1

1

看起来在您配置的数据集中找不到单词,因此它仅返回分数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中 ws4j 1.0.1 的 JAR包含其自己的信息内容文件(名为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不同指标的各个实现的配置。

于 2016-03-31T09:53:58.890 回答