Example #1
0
  public static int isWNHypernym(Synset child, Synset parent, int depth) {
    initializeWordNet();
    PointerTargetNodeList dp;
    if (child.equals(parent)) return 0;
    Synset cur = child;
    int curDepth = 0;
    try {
      while ((dp = PointerUtils.getInstance().getDirectHypernyms(cur)) != null
          && !dp.isEmpty()
          && curDepth < depth) {
        curDepth++;
        // if (dp.size() > 1)
        // throw new RuntimeException("More than 1 hypernym");

        Object pt = dp.get(0);
        PointerTargetNode ptn = (PointerTargetNode) pt;
        cur = ptn.getSynset();
        if (cur.equals(parent)) return curDepth;
      }

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return -1;
  }
Example #2
0
  public static int getDistance(Synset s1, Synset s2, int max) {
    initializeWordNet();
    PointerTargetNodeList dp;
    if (s1.equals(s2)) return 0;

    Synset cur = s2;
    int depth = 0, depth2 = isWNHypernym(s1, cur, max);
    if (depth2 >= 0) return depth2;
    try {
      while ((dp = PointerUtils.getInstance().getDirectHypernyms(cur)) != null
          && !dp.isEmpty()
          && depth < max) {
        depth++;
        Object pt = dp.get(0);
        PointerTargetNode ptn = (PointerTargetNode) pt;

        cur = ptn.getSynset();
        // System.out.println(cur);
        if ((depth2 = isWNHypernym(s1, cur, max)) >= 0)
          return depth + depth2 < max ? depth + depth2 : max;
      }

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return max;
  }
Example #3
0
  public static int isWNHypernym(Synset child, String parent) {
    initializeWordNet();
    PointerTargetNodeList dp;
    if (child.getWord(0).getLemma().equalsIgnoreCase(parent)) return 0;
    Synset cur = child;
    int curDepth = 0;
    try {
      while ((dp = PointerUtils.getInstance().getDirectHypernyms(cur)) != null && !dp.isEmpty()) {
        curDepth++;
        // System.out.println("*****");
        Object pt = dp.get(0);
        PointerTargetNode ptn = (PointerTargetNode) pt;
        // System.out.println(ptn.getSynset().getWords()[0].getLemma());
        cur = ptn.getSynset();
        // System.out.println(cur.getWord(0).getLemma());
        if (cur.getWord(0).getLemma().equalsIgnoreCase(parent)) return curDepth;

        // if (dp.size() > 1)
        // throw new RuntimeException("More than 1 hypernym");

      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return -1;
  }
Example #4
0
 public FeatureUtils() {
   initializeWordNet();
   // // Startup Wordnet
   // try {
   // JWNL.initialize(new FileInputStream(propsFile));
   // wordnet = Dictionary.getInstance();
   // } catch (Exception ex) {
   // throw new RuntimeException(ex);
   // }
 }