我使用jaws-wordnet搜索并且是新手。我发现2个感官之间的概念距离,我想知道两个意义之间的路径长度,以及上位词。
有谁知道它是如何计算的?颌部是否有任何功能?
答案 0 :(得分:0)
不,JAWS没有内置功能来找到你想要的东西。
然而,编程非常简单(sourceForm
和targetForm
是你想要计算hypernym-path-length的词:)
WordNetDatabase database = WordNetDatabase.getFileInstance();
// only looks at the first results, and they *must* be a NounSynsets
NounSynset src = (NounSynset)(database.getSynsets(sourceForm)[0]);
NounSynset dst = (NounSynset)(database.getSynsets(targetForm)[0]);
HashMap<NounSynset, Integer> srcHyper = findHypernymsRecursive(src, 0, null);
HashMap<NounSynset, Integer> dstHyper = findHypernymsRecursive(dst, 0, null);
srcHyper.keySet().retainAll(dstHyper.keySet()); // retain only common
int min = Integer.MAX_VALUE;
for (NounSynset n : srcHyper.keySet()) {
int d1 = srcHyper.get(n);
int d2 = dstHyper.get(n);
min = Math.min(min, d1+d2); // update min-distance
}
return min; // if empty intersection, Integer.MAX_VALUE
findHypernymsRecursive的工作原理如下:
public static HashMap<NounSynset, Integer>
findHypernymsRecursive(NounSynset s, int depth, HashMap<NounSynset, Integer> m) {
if (m == null) m = new HashMap<NounSynset, Integer>();
if ( ! m.containsKey(s)) {
m.put(s, depth);
for (NounSynset h : s.getHypernyms()) {
findHypernymsRecursive(h, depth+1, m);
}
}
return m;
}
免责声明:我还没有尝试过这段代码。它可能充满了错别字......