Java 计算相似性度量
我使用JWNL并根据wordnet计算字符串之间的相似性度量,我运行以下代码:Java 计算相似性度量,java,wordnet,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.SimilarityMeas
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);
}
}
import java.io.FileInputStream;
导入java.util.HashMap;
导入java.util.Map;
导入net.didion.jwnl.jwnl;
导入shef.nlp.wordnet.similarity.SimilarityInfo;
导入shef.nlp.wordnet.similarity.SimilarityMeasure;
公共类wordnet
{
公共静态void main(字符串[]args)引发异常
{
//初始化WordNet-这必须在尝试之前完成
//并创建一个相似性度量,否则会让事情变得糟糕
//可能会发生!
初始化(新文件输入流(“test/wordnet.xml”);
//创建一个映射来保存相似性配置参数
Map params=新的HashMap();
//simType参数是要使用的度量值的类名
参数put(“simType”、“shef.nlp.wordnet.similarity.JCn”);
//此参数应为infocontent文件的URL(如果需要
//(通过加载的相似性度量)
参数put(“信息内容”,“文件:test/ic-bnc-resnik-add1.dat”);
//如果
//用户需要进行synset映射
参数put(“映射”,“文件:test/domain_independent.txt”);
//创建相似性度量
SimilarityMeasure sim=SimilarityMeasure.newInstance(参数);
//获取涉及映射的相似性
SimilarityInfo d=sim.getSimilarity(“英语”、“英语”);
System.out.println(d.getSynset1());
System.out.println(d.getSynset2());
System.out.println(d.getSimilarity());
系统输出打印ln(d);
}
}
但我不知道为什么结果是零
结果是:
2013年1月27日晚上7:03:00 net.didion.jwnl.util.MessageLog doLog信息:正在安装dictionary net.didio.jwnl.dictionary。FileBackedDictionary@48fbc0
[Synset:[Offset:6074471][POS:noun]单词:英语--(研究英语语言和文学的学科)]
[Synset:[Offset:6074471][POS:noun]单词:英语--(研究英语语言和文学的学科)]
0.0
英语#n#3英语#n#3 0.0
你能帮帮我吗?你必须确保使用Coresponding WordNet字典试试WordNet 2.0
否则,请尝试WS4J在嵌入Wordnet 3.0的系统集之间使用相似性度量。我认为这些系统集没有等价关系-您应该尝试两个具有相同含义的不同单词,而不是两个相同单词。@Randy:我对几个同义词进行了测试,但结果总是为零!