【问题标题】:Java API for Semantic Similarity / Relatedness between two "WORDS"用于两个“单词”之间语义相似性/相关性的 Java API
【发布时间】:2015-04-26 12:17:42
【问题描述】:

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

- 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。

【问题讨论】:

    标签: java semantics similarity wordnet ws4j


    【解决方案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 实现的配置。

    【讨论】:

    • @jaykio77:如果它对你有帮助,你能接受这个答案吗?——我目前正在挖掘一些额外的声望点。非常感谢。
    猜你喜欢
    • 2013-04-18
    • 2014-11-19
    • 2022-08-19
    • 2014-12-26
    • 2020-09-19
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 2011-09-30
    相关资源
    最近更新 更多