コード例 #1
0
ファイル: WordNetConnector.java プロジェクト: boricles/nor2o
  protected boolean isMeronym(String term1, String term2) {
    try {

      List<PointerType> pts = new ArrayList<PointerType>();
      pts.add(PointerType.SUBSTANCE_HOLONYM);
      pts.add(PointerType.REGION);
      pts.add(PointerType.PART_HOLONYM);
      pts.add(PointerType.MEMBER_HOLONYM);

      IndexWord[] concept1iWord = getIWords(term1);
      IndexWord[] concept2iWord = getIWords(term2);

      for (PointerType pt : pts) {

        for (int i = 0; i < concept1iWord.length; i++)
          for (int j = 0; j < concept2iWord.length; j++) {
            if (concept1iWord[i].getSenseCount() != 0 && concept2iWord[j].getSenseCount() != 0) {
              RelationshipList list =
                  relationFinder.findRelationships(
                      concept1iWord[i].getSenses()[0],
                      concept2iWord[j].getSenses()[0],
                      pt,
                      RELATIONSHIP_DEEP);
              if (!list.isEmpty()) return true;
            }
          }
      }

    } catch (JWNLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return false;
  }
コード例 #2
0
ファイル: WordNetConnector.java プロジェクト: boricles/nor2o
  protected boolean isHolonym(String term1, String term2) {
    try {

      List<PointerType> pts = new ArrayList<PointerType>();
      pts.add(PointerType.MEMBER_MERONYM);
      pts.add(PointerType.PART_MERONYM);
      // pts.add(PointerType.REGION_MEMBER);
      pts.add(PointerType.SUBSTANCE_MERONYM);

      IndexWord[] concept1iWord = getIWords(term1);
      IndexWord[] concept2iWord = getIWords(term2);

      for (PointerType pt : pts) {

        for (int i = 0; i < concept1iWord.length; i++)
          for (int j = 0; j < concept2iWord.length; j++) {
            if (concept1iWord[i].getSenseCount() != 0 && concept2iWord[j].getSenseCount() != 0) {
              RelationshipList list =
                  relationFinder.findRelationships(
                      concept1iWord[i].getSenses()[0],
                      concept2iWord[j].getSenses()[0],
                      pt,
                      RELATIONSHIP_DEEP);

              for (int p = 0; p < list.size(); p++) {
                AsymmetricRelationship ptnl = (AsymmetricRelationship) list.get(p);
                for (int q = 0; q < ptnl.getSize(); q++) {
                  // PointerTargetNode ptn = (PointerTargetNode)ptnl.
                  if (isTermContainedInWords(ptnl.getSourceSynset(), term1)
                      && (ptnl.getType().equals(PointerType.MEMBER_HOLONYM)
                          || ptnl.getType().equals(PointerType.PART_HOLONYM)
                          || ptnl.getType().equals(PointerType.SUBSTANCE_HOLONYM))) return true;
                }
              }

              if (!list.isEmpty()) {
                Relationship shall = list.getShallowest();
              }

              if (!list.isEmpty()) return true;
            }
          }
      }

    } catch (JWNLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return false;
  }
コード例 #3
0
ファイル: WordNetConnector.java プロジェクト: boricles/nor2o
  protected String getSpecificRelation(
      IndexWord word1, String term1, IndexWord word2, String term2, POS[] posES) {
    String relation = "";
    int depth = 1110;
    // int depth = 1;
    try {
      List<PointerType> typesconcept1 = PointerType.getAllPointerTypesForPOS(word1.getPOS());
      List<PointerType> typesconcept2 = PointerType.getAllPointerTypesForPOS(word2.getPOS());

      Set<PointerType> pointersSet = new HashSet<PointerType>();
      pointersSet.addAll(typesconcept1);
      pointersSet.addAll(typesconcept2);

      Synset[] concept1Synsets = word1.getSenses();
      // Synset concept1Synset = concept1Synsets[0];

      Synset[] concept2Synsets = word2.getSenses();
      // Synset concept2Synset = concept2Synsets[0];

      List<PointerType> pts = PointerType.getAllPointerTypes();

      if (concept1Synsets != null && concept2Synsets != null) {
        Set<Relationship> relsSet = new HashSet<Relationship>();

        for (int i = 0; i < concept1Synsets.length; i++) {
          Synset concept1Synset, concept2Synset;

          if (isSynsetOfPOS(concept1Synsets[i], posES)
              && isTermContainedInWords(concept1Synsets[i], term1)) {
            concept1Synset = concept1Synsets[i];

            for (int j = 0; j < concept2Synsets.length; j++)
              if (isSynsetOfPOS(concept2Synsets[j], posES)
                  && isTermContainedInWords(concept2Synsets[i], term2)) {
                concept2Synset = concept2Synsets[j];

                for (PointerType pt : pts) {
                  // RelationshipList list = relationFinder.findRelationships(concept1Synset,
                  // concept2Synset, pt);
                  RelationshipList list =
                      relationFinder.findRelationships(
                          concept1Synset, concept2Synset, pt, RELATIONSHIP_DEEP);

                  if (list != null && !list.isEmpty()) {
                    Relationship rel = list.getShallowest();
                    if (rel.getDepth() < depth) depth = rel.getDepth();
                    relsSet.add(rel);
                    list.clear();
                    list = null;
                  }
                }
              }
          }
        }
        relation = getRelevantRelation(relsSet, depth);
      }
    } catch (JWNLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return relation;
  }