java - 计算相似性度量

标签 java wordnet

我正在使用 JWNL 并根据 wordnet 计算字符串之间的相似性度量,我运行以下代码:

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;

import net.didion.jwnl.JWNL;
import shef.nlp.wordnet.similarity.SimilarityInfo;
import shef.nlp.wordnet.similarity.SimilarityMeasure;

public class wordnet
{

public static void main(String[] args) throws Exception 
{
    //Initialize WordNet - this must be done before you try
    //and create a similarity measure otherwise nasty things
    //might happen!
    JWNL.initialize(new FileInputStream("test/wordnet.xml"));

    //Create a map to hold the similarity config params
    Map<String,String> params = new HashMap<String,String>();

    //the simType parameter is the class name of the measure to use
    params.put("simType","shef.nlp.wordnet.similarity.JCn");

    //this param should be the URL to an infocontent file (if required
    //by the similarity measure being loaded)
    params.put("infocontent","file:test/ic-bnc-resnik-add1.dat");

    //this param should be the URL to a mapping file if the
    //user needs to make synset mappings
    params.put("mapping","file:test/domain_independent.txt");

    //create the similarity measure
    SimilarityMeasure sim = SimilarityMeasure.newInstance(params);


    //get a similarity that involves a mapping
    SimilarityInfo d=sim.getSimilarity("english", "english");
    System.out.println(d.getSynset1());
    System.out.println(d.getSynset2());
    System.out.println(d.getSimilarity());
    System.out.println(d);

}

}

但我不知道为什么结果是零?!

结果是:

Jan 27, 2013 7:03:00 PM net.didion.jwnl.util.MessageLog doLog
INFO: Installing dictionary net.didion.jwnl.dictionary.FileBackedDictionary@48fbc0
[Synset: [Offset: 6074471] [POS: noun] Words: English -- (the discipline that studies the English language and literature)]
[Synset: [Offset: 6074471] [POS: noun] Words: English -- (the discipline that studies the English language and literature)]
0.0
english#n#3 english#n#3 0.0

你能帮我一下吗?

最佳答案

你必须确保使用相应的WordNet词典尝试Wordnet 2.0 否则尝试 WS4J 在嵌入了 Wordnet 3.0 的 sysnsets 之间使用相似性度量

关于java - 计算相似性度量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14548971/

相关文章:

java - G1GC 日志中的时间

python - 从 NLTK for Python 中的同义词集列表中提取单词

prolog - 普林斯顿 wordnet prolog 文件 - 如何使用 sense key

java - 麻省理工学院 Java WordNet 接口(interface) : Getting WordNet lexicographer classes or super-senses

php - 如何在 php 中使用 word Net

java - 使用 2 个堆栈的队列,O(1) 中的删除

java - 在 Java 中分割行并填充数组并跳过空白值

java - 我无法在 Selenium 中将 Java 的解决方案重写为 C#

python - 如何在 wordnet 词典中添加新词?

java - Lua 到 JVM 编译器?