我正在尝试为我的应用程序计算两个单词之间的相似性。我用过wordnet字典。在执行代码时,它需要在类路径中使用wnjpn.db。当我将代码作为Java应用程序执行时,当我将这个db文件添加到app中的src文件夹时,它工作正常,但是当我尝试从网页运行时,它给出了错误
ERROR: Make sure the NICT wordnet db is stored in classpath at: /wnjpn.db
示例代码看起来像
import edu.cmu.lti.lexical_db.ILexicalDatabase;
import edu.cmu.lti.lexical_db.NictWordNet;
import edu.cmu.lti.ws4j.RelatednessCalculator;
import edu.cmu.lti.ws4j.impl.HirstStOnge;
import edu.cmu.lti.ws4j.impl.JiangConrath;
import edu.cmu.lti.ws4j.impl.LeacockChodorow;
import edu.cmu.lti.ws4j.impl.Lesk;
import edu.cmu.lti.ws4j.impl.Lin;
import edu.cmu.lti.ws4j.impl.Path;
import edu.cmu.lti.ws4j.impl.Resnik;
import edu.cmu.lti.ws4j.impl.WuPalmer;
import edu.cmu.lti.ws4j.util.WS4JConfiguration;
public class similarity {
public static ILexicalDatabase db = new NictWordNet();
/*
//available options of metrics
private static RelatednessCalculator[] rcs = { new HirstStOnge(db),
new LeacockChodorow(db), new Lesk(db), new WuPalmer(db),
new Resnik(db), new JiangConrath(db), new Lin(db), new Path(db) };
*/
public static double compute(String word1, String word2) {
WS4JConfiguration.getInstance().setMFS(true);
double s = new WuPalmer(db).calcRelatednessOfWords(word1, word2);
return s;
}
public static void main(String[] args) {
String[] words = {"add", "get", "filter", "remove", "check", "find", "collect", "create"};
double distance = compute("OTHER OFFENSE","PROSTITUTION");
System.out.println( distance);
}
}