コード例 #1
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;
  }
コード例 #2
0
ファイル: WordNetConnector.java プロジェクト: boricles/nor2o
 protected boolean isTermContainedInWords(Synset synset, String term) {
   for (int i = 0; i < synset.getWords().length; i++) {
     if (synset
         .getWord(i)
         .getLemma()
         .equalsIgnoreCase(term) /*|| synset.getWord(i).getLemma().contains(term)*/) return true;
   }
   return false;
 }