How to find the path length between 2 senses?

239 views Asked by At

I use jaws-wordnet searching and am new to it. I am finding the conceptual distance between 2 senses for which I wanted to know the length of path between 2 senses in terms of hypernym.

Do anybody know how is it calculated? Is there any function in jaws for this?

1

There are 1 answers

1
tucuxi On

No, JAWS has no built-in functions to find what you seek.

However, it is pretty simple to program (sourceForm and targetForm are the words you want to calculate hypernym-path-length from):

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

Where findHypernymsRecursive works like this:

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;
}

Disclaimer: I haven't actually tried this code out. It is probably full of typos...