示例#1
0
 public void getSynonym(List words) {
   for (int i = 0; i < words.size(); i++) {
     IWord word = (IWord) words.get(i);
     System.out.println((new StringBuilder("\n\nFor Word:")).append(word.getLemma()).toString());
     List hypernymList = getHypernym(word.getLemma());
     for (int j = 0; j < hypernymList.size(); j++) {
       IWord hypernym = (IWord) hypernymList.get(j);
       System.out.println((new StringBuilder("Hypernym:")).append(hypernym.getLemma()).toString());
     }
   }
 }
示例#2
0
  List keepUniqueTerms(List hypernymsList) {
    ArrayList uniqueList = new ArrayList();
    ArrayList uniqueHypernymList = new ArrayList();
    for (int i = 0; i < hypernymsList.size(); i++) {
      IWord word = (IWord) hypernymsList.get(i);
      if (!uniqueList.contains(word.getLemma().toString())) {
        uniqueList.add(word.getLemma().toString());
        uniqueHypernymList.add(word);
      }
    }

    return uniqueHypernymList;
  }
示例#3
0
  public static void main(String args[]) {
    WordnetTester wordnetTester = new WordnetTester();
    List hypernymList = wordnetTester.getHypernym("fauna");
    for (int i = 0; i < hypernymList.size(); i++) {
      IWord word = (IWord) hypernymList.get(i);
      System.out.println(
          (new StringBuilder("Hypernym is:")).append(word.getLemma().toString()).toString());
    }

    wordnetTester.getHypernym(hypernymList);
  }
示例#4
0
  public boolean areSynoynyms(String word1, String word2) {
    boolean synonyms = false;
    List synoymList = getSynonyms(word1);
    List synoym1List = getSynonyms(word2);
    ArrayList word1List = new ArrayList();
    ArrayList word2List = new ArrayList();
    for (int i = 0; i < synoymList.size(); i++) {
      IWord word = (IWord) synoymList.get(i);
      word1List.add(word.getLemma());
    }

    for (int i = 0; i < synoym1List.size(); i++) {
      IWord word = (IWord) synoym1List.get(i);
      word2List.add(word.getLemma());
    }

    word1List.retainAll(word2List);
    if (word1List.size() > 0) synonyms = true;
    return synonyms;
  }
示例#5
0
  private Set<String> getHypernyms(
      String word, POS posTag, boolean firstSenseOnly, int maxIterations) {

    Set<String> hypernyms = new HashSet<String>();

    IIndexWord iIndexWordRoot = dict.getIndexWord(word, posTag);
    if (iIndexWordRoot == null) {
      return hypernyms; // no senses found
    }

    List<IWordID> todo = iIndexWordRoot.getWordIDs();

    int iterations = 0;

    while (iterations++ < maxIterations && !todo.isEmpty()) {
      List<IWordID> tmp = Lists.newArrayList();
      // iterate over senses
      for (IWordID iWordId : todo) {
        IWord iWord1 = dict.getWord(iWordId);
        ISynset iSynset = iWord1.getSynset();

        // multiple hypernym chains are possible for a synset
        for (ISynsetID iSynsetId : iSynset.getRelatedSynsets(Pointer.HYPERNYM)) {
          List<IWord> iWords = dict.getSynset(iSynsetId).getWords();
          for (IWord iWord2 : iWords) {
            String lemma = iWord2.getLemma().replace('_', ' ');
            hypernyms.add(lemma);
            tmp.add(iWord2.getID());
          }
        }

        if (firstSenseOnly) {
          break;
        }
      }
      todo = tmp;
    }

    return hypernyms;
  }