gpt4 book ai didi

java - 计算相似性度量

转载 作者:行者123 更新时间:2023-12-01 14:53:34 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com