예제 #1
0
 public IWord getIWordForPhrase(String phrase) {
   IWord word = null;
   IIndexWord idxWord = dict.getIndexWord(phrase, POS.NOUN);
   if (idxWord != null) {
     IWordID wordID = (IWordID) idxWord.getWordIDs().get(0);
     word = dict.getWord(wordID);
   }
   return word;
 }
예제 #2
0
  public List getSynonyms(String phrase) {
    List synonymsList = new ArrayList();
    if (dict == null) {
      System.out.println("Dictionary is null");
      System.exit(0);
    }
    IIndexWord idxWord = dict.getIndexWord(phrase, POS.NOUN);
    if (idxWord != null) {
      IWordID wordID = (IWordID) idxWord.getWordIDs().get(0);
      IWord word = dict.getWord(wordID);
      ISynset synset = word.getSynset();
      List words = new ArrayList();
      IWord w;
      for (Iterator iterator = synset.getWords().iterator(); iterator.hasNext(); words.add(w))
        w = (IWord) iterator.next();

      synonymsList = keepUniqueTerms(words);
    }
    return synonymsList;
  }
예제 #3
0
  public double getSynsetDepth(String word, int senseno, String pos) {
    IIndexWord word1 = null;
    // get the WordNet words in *any* POS
    ArrayList<Integer> homehierarchies = null;
    // if(pos.equalsIgnoreCase("n"))
    // {
    try {
      word1 = dict.getIndexWord(word, POS.NOUN);
      homehierarchies = nounroots;
      System.out.println(word1.toString() + "||||");

      // }
      // if(pos.equalsIgnoreCase("v"))
      // {
      //	word1 = dict.getIndexWord(word, POS.VERB);
      //	homehierarchies	=	verbroots;
      // }
      // ...........................................................................................................................................
      IWordID word1ID = word1.getWordIDs().get(senseno - 1); // get the right sense of word 1
      ISynset synset1 = dict.getWord(word1ID).getSynset();
      // ...........................................................................................................................................
      // get a score
      TreeMap<Integer, HashSet<ISynsetID>> depths = new TreeMap<Integer, HashSet<ISynsetID>>();
      HashSet<ISynsetID> synsets = new HashSet<ISynsetID>();
      synsets.add(synset1.getID());
      treecreeper(0, synsets, depths, homehierarchies);
      if (depths.isEmpty()) {
        return (0.0); // i.e. is <root>, nothing 'above' it
      }
      return ((double) (depths.lastKey() + 2.0));

    } catch (Exception ex) {
    }

    return 0.0;
    // ??? node counting, so have to include start and end node
  }
예제 #4
0
  public List getHypernym(String phrase) {
    List hypernymsList = new ArrayList();
    if (dict == null) {
      System.out.println("Dictionary is null");
      System.exit(0);
    }
    IIndexWord idxWord = dict.getIndexWord(phrase, POS.NOUN);
    if (idxWord != null) {
      IWordID wordID = (IWordID) idxWord.getWordIDs().get(0);
      IWord word = dict.getWord(wordID);
      ISynset synset = word.getSynset();
      List hypernyms = synset.getRelatedSynsets(Pointer.HYPERNYM);
      List words;
      for (Iterator iterator = hypernyms.iterator();
          iterator.hasNext();
          hypernymsList.addAll(words)) {
        ISynsetID sid = (ISynsetID) iterator.next();
        words = dict.getSynset(sid).getWords();
      }

      hypernymsList = keepUniqueTerms(hypernymsList);
    }
    return hypernymsList;
  }