Пример #1
0
 /**
  * @param v The synsets
  * @param t The Topic
  * @return The number of words in the synset also found in the topic
  */
 public static int checkAmbig(Vector<Synset> v, Topic t) {
   int count = 0;
   boolean result = false;
   if (v == null) return count;
   for (Synset set : v) {
     Word[] w = set.getWords();
     for (Word word : w) {
       String rec = word.getLemma();
       String toLookup = WNLookup.getStaticStem(rec);
       result = t.containsKey(toLookup);
       if (result || t.containsKey(rec)) {
         count++;
         Log.logger.debug(
             "[found a related word on my mind: '"
                 + toLookup
                 + "', recent count for this topic '"
                 + t.getName()
                 + "' is: "
                 + count
                 + "]");
       }
     }
   }
   return count;
 }
Пример #2
0
  public Map<RelationType, Set<String>> getAllRelatedWords(String word) {
    Map<RelationType, Set<String>> ret = createContainer();
    identity.add(word);
    relatedWord.add(word);

    getAllSenses(word);
    if (allSenses.size() == 0) {
      relatedWordWithPOS.add(new String[] {word});
      return ret;
    }

    Iterator<Synset> senseItr = allSenses.iterator();
    Synset sense = null;
    Word[] words = null;
    Word w = null;
    POS pos = null;
    String lemma = null;

    while (senseItr.hasNext()) {
      sense = senseItr.next();
      words = sense.getWords();
      /** Synonyms */
      String syn = null;
      for (int i = 0; i < words.length; i++) {
        w = words[i];
        syn = w.getLemma();
        pos = w.getPOS();
        // System.out.println("Synonym:"+syn);
        synonyms.add(syn);
        // relatedWord.add(word);
        checkWordWithPOS(syn, pos);
      }

      /** Morphological variation */
      POS sensePOS = sense.getPOS();
      if (sensePOS == POS.NOUN) {
        addMorph(word + "s", sensePOS);
        addMorph(word + "es", sensePOS);
        addMorph(word.substring(0, word.length() - 1) + "ies", sensePOS);
      } else if (sensePOS == POS.VERB) {
        if (word.endsWith("e")) {
          addMorph(word + "r", sensePOS);
          addMorph(word.substring(0, word.length() - 1) + "ing", sensePOS);
          addMorph(word + "d", sensePOS);
        } else {
          addMorph(word + "er", sensePOS);
          addMorph(word + "ing", sensePOS);
          addMorph(word + "ed", sensePOS);
        }
      }

      /** Hypernyms, etc */
      for (RelationType relation : RelationType.values()) {
        PointerTargetNodeList nodeList = null;
        Set<String> listToStore = null;
        // RelationType relation = relations[i];
        try {
          switch (relation) {
            case hype:
              nodeList = pUtils.getDirectHypernyms(sense);
              break;
            case hypo:
              nodeList = pUtils.getDirectHyponyms(sense);
              break;
            case derv:
              nodeList = pUtils.getDerived(sense);
              break;
            case vgrp:
              nodeList = pUtils.getVerbGroup(sense);
              break;
            case cause:
              nodeList = pUtils.getCauses(sense);
              break;
            case entl:
              nodeList = pUtils.getEntailments(sense);
              break;
            case entlby:
              nodeList = pUtils.getEntailedBy(sense);
              break;
            case antm:
              nodeList = pUtils.getAntonyms(sense);
              break;
            case syn2:
              nodeList = pUtils.getSynonyms(sense);
              break;
            case alsoc:
              nodeList = pUtils.getAlsoSees(sense);
              break;
            case extd:
              // pUtils.getExtendedAntonyms(sense).print();
              nodeList = (PointerTargetNodeList) pUtils.getExtendedAntonyms(sense).toList();
              break;
            case indi:
              // pUtils.getIndirectAntonyms(sense).print();
              nodeList = (PointerTargetNodeList) pUtils.getIndirectAntonyms(sense).toList();
              break;
          }
        } catch (Exception e) {
        }
        if (nodeList != null) {
          listToStore = ret.get(relation);
          Iterator targetItr = nodeList.iterator();
          PointerTargetNode pTargetNode = null;
          while (targetItr.hasNext()) {
            pTargetNode = (PointerTargetNode) targetItr.next();
            if (!pTargetNode.isLexical()) {
              words = pTargetNode.getSynset().getWords();
              for (int j = 0; j < words.length; j++) {
                w = words[j];
                lemma = w.getLemma();
                pos = w.getPOS();
                if (lemma.contains("_")) {
                  String[] parts = lemma.split("_");
                  if (parts.length == 2) {
                    multiword.add(lemma.toLowerCase());
                  }
                } else {
                  listToStore.add(lemma);
                  checkWordWithPOS(lemma, pos);
                }
              }
            } else {
              w = pTargetNode.getWord();
              lemma = w.getLemma();
              pos = w.getPOS();
              if (lemma.contains("_")) {
                String[] parts = lemma.split("_");
                if (parts.length == 2) {
                  multiword.add(lemma.toLowerCase());
                }
              } else {
                listToStore.add(lemma);
                checkWordWithPOS(lemma, pos);
              }
            }
          }
        }
        nodeList = null;
      }
    } // end for all senses
    // System.out.println("Synonyms:");
    // for(String w: synonyms)
    //  System.out.println("\t"+w);
    // System.out.println("\nSynonym2:");
    // for(String w: synonyms2)
    //  System.out.println("\t"+w);
    // System.out.println("\nHypernyms:");
    // for(String w: hypernyms)
    //  System.out.println("\t"+w);
    // System.out.println("\nHyponyms:");
    // for(String w: hyponyms)
    //  System.out.println("\t"+w);
    // System.out.println("\nCoordinates:");
    // for(String w: coordinates)
    //  System.out.println("\t"+w);
    // System.out.println("\nDerived:");
    // for(String w: derived)
    //  System.out.println("\t"+w);
    // System.out.println("\nVerbGroup:");
    // for(String w: verbGroup)
    //  System.out.println("\t"+w);
    // System.out.println("\nCauses:");
    // for(String w: causes)
    //  System.out.println("\t"+w);
    // System.out.println("\nEntailments:");
    // for(String w: entailments)
    //  System.out.println("\t"+w);
    // System.out.println("\nEntailedBys:");
    // for(String w: entailedBys)
    //  System.out.println("\t"+w);
    // System.out.println("\nAntonym:");
    // for(String w: antonyms)
    //  System.out.println("\t"+w);
    // System.out.println("\nExtendedAntonym:");
    // for(String w: extendedAntonyms)
    //  System.out.println("\t"+w);
    // System.out.println("\nIndirectAntonym:");
    // for(String w: indirectAntonyms)
    //  System.out.println("\t"+w);
    // System.out.println("\nAlso See:");
    // for(String w: alsosees)
    //  System.out.println("\t"+w);
    return ret;
  }