예제 #1
0
 /**
  * Returns the ranking <i>k</i> such that {@code other} is the k<sup>th</th> most similar word to
  * {@code target} in the semantic space.
  */
 private int findRank(SemanticSpace sspace, String target, String other) {
   Vector v1 = sspace.getVector(target);
   Vector v2 = sspace.getVector(other);
   // Compute the base similarity between the two words
   double baseSim = Similarity.cosineSimilarity(v1, v2);
   int rank = 0;
   // Next, count how many words are more similar to the target than the
   // other word is
   for (String word : sspace.getWords()) {
     Vector v = sspace.getVector(word);
     double sim = Similarity.cosineSimilarity(v1, v);
     if (sim > baseSim) rank++;
   }
   return rank;
 }