// do unit testing of this class
 public static void main(String[] args) {
   WordNet net = new WordNet(args[0], args[1]);
   while (!StdIn.isEmpty()) {
     int v = StdIn.readInt();
     int w = StdIn.readInt();
     int length = net.distance(net.idToSynset.get(v), net.idToSynset.get(w));
     String ancestor = net.sap(net.idToSynset.get(v), net.idToSynset.get(w));
     StdOut.printf("length = %d, ancestor = %s\n", length, ancestor);
   }
 }
Пример #2
0
  /**
   * Given an array of WordNet nouns, return an outcast
   *
   * @param nouns
   * @return
   */
  public String outcast(String[] nouns) {
    int maxDistance = Integer.MIN_VALUE;
    String outcast = null;
    int sumOfDistances = 0;
    int index = 0;
    int distance = 0;

    while (index < nouns.length) {
      for (int i = 0; i < nouns.length; i++) {
        if (index != i) {
          distance = wordNet.distance(nouns[index], nouns[i]);
        }
        sumOfDistances += distance;
      }
      System.out.println("The distance for " + nouns[index] + " is " + sumOfDistances);
      if (sumOfDistances > maxDistance) {
        maxDistance = sumOfDistances;
        outcast = nouns[index];
      }

      sumOfDistances = 0;
      index++;
    }

    return outcast;
  }
Пример #3
0
 // given an array of WordNet nouns, return an outcast
 // Assume that argument to outcast() contains only valid wordnet nouns (and that it contains at
 // least two such nouns).
 public String outcast(String[] nouns) {
   int[] dist = new int[nouns.length];
   int maxD = Integer.MIN_VALUE;
   int maxIndex = -1;
   for (int i = 0; i < nouns.length; i++) {
     for (int j = 0; j < nouns.length; j++) {
       if (j != i) // optimization
       dist[i] += w.distance(nouns[i], nouns[j]);
     }
     if (dist[i] > maxD) {
       maxD = dist[i];
       maxIndex = i;
     }
   }
   return nouns[maxIndex];
 }
Пример #4
0
 public String outcast(String[] nouns) {
   String outcast = null;
   int maxDistance = 0;
   for (int i = 0; i < nouns.length; i++) {
     int distance = 0;
     for (int j = 0; j < nouns.length; j++) {
       if (!nouns[i].equals(nouns[j])) {
         distance += wordnet.distance(nouns[i], nouns[j]);
       }
     }
     if (distance > maxDistance) {
       maxDistance = distance;
       outcast = nouns[i];
     }
   }
   return outcast;
 }
  /**
   * Create caches of WordNet to speed up matching.
   *
   * @param jwnlPropertiesPath extJWNL properties file path
   * @param adjectiveSynonyms adjective synonyms file path
   * @param adjectiveAntonyms adjective antonyms file path
   * @param nounHypernyms noun hypernyms file path
   * @param nounAntonyms noun antonyms file path
   * @param adverbAntonyms adverb antonyms file path
   * @param verbHypernyms verb hypernyms file path
   * @param nominalizations nominalizations file path
   * @throws SMatchException SMatchException
   */
  public static void createWordNetCaches(
      String jwnlPropertiesPath,
      String adjectiveSynonyms,
      String adjectiveAntonyms,
      String nounHypernyms,
      String nounAntonyms,
      String adverbAntonyms,
      String verbHypernyms,
      String nominalizations)
      throws SMatchException {
    Dictionary dic = WordNet.getDictionary(jwnlPropertiesPath);

    log.info("Creating WordNet caches...");
    convertAndWrite(findNominalizations(dic), nominalizations);
    convertAndWrite(findAdjectiveSynonyms(dic), adjectiveSynonyms);
    convertAndWrite(findAdverbAntonyms(dic), adverbAntonyms);
    convertAndWrite(findAdjectiveAntonyms(dic), adjectiveAntonyms);
    convertAndWrite(findNounAntonyms(dic), nounAntonyms);
    convertAndWrite(findNounHypernyms(dic), nounHypernyms);
    convertAndWrite(findVerbHypernyms(dic), verbHypernyms);
    log.info("Created WordNet caches");
  }