Пример #1
0
  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
  public static boolean ancestorWN(Annotation np1, Annotation np2, Document doc)
      throws JWNLException {
    /*
    // Startup Wordnet
    if (wordnet == null) {
    	try {
    		JWNL.initialize(new FileInputStream(propsFile));
    		wordnet = Dictionary.getInstance();
    	} catch (Exception ex) {
    		throw new RuntimeException(ex);
    	}
    }
    IndexWord w1;
    IndexWord w2;

    // This searches the wordnet database w/o any morph processing done
    // to the word.
    w1 = wordnet.getIndexWord(POS.NOUN, word1);
    w2 = wordnet.getIndexWord(POS.NOUN, word2);

    // To have WN do morph processing...
    // IndexWord w1 = wordnet.lookupIndexWord(POS.NOUN, word1);
    // IndexWord w2 = wordnet.lookupIndexWord(POS.NOUN, word2);
     */
    Synset[] synset1 = Synsets.getValue(np1, doc);
    Synset[] synset2 = Synsets.getValue(np2, doc);

    if (synset1 == null || synset2 == null || synset1.length == 0 || synset2.length == 0)
      return false;

    // Check for relationships amongst all senses.
    for (Synset element : synset1) {
      for (Synset element2 : synset2) {
        RelationshipList hypo =
            RelationshipFinder.getInstance()
                .findRelationships(element, element2, PointerType.HYPONYM);
        if (!hypo.isEmpty()) return true;
      }
    }

    return false;
  }
Пример #3
0
  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;
  }
Пример #4
0
  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;
  }