Ejemplo n.º 1
0
  public static SimilarUser[] getTopNFriends(List<SimilarUser> similarUsers, int topN) {

    // sort friends based on itemAgreement
    SimilarUser.sort(similarUsers);

    // select top N friends
    List<SimilarUser> topFriends = new ArrayList<SimilarUser>();
    for (SimilarUser f : similarUsers) {
      if (topFriends.size() >= topN) {
        // have enough friends.
        break;
      }

      // This is useful when we compose results from different recommenders
      if (!topFriends.contains(f)) {
        topFriends.add(f);
      }
    }

    return topFriends.toArray(new SimilarUser[topFriends.size()]);
  }
Ejemplo n.º 2
0
 /**
  * Prints a list of user names with their similarities.
  *
  * @param friends similar users
  * @param header title that will be printed at the top of the list.
  */
 public static void print(SimilarUser[] friends, String header) {
   System.out.println("\n" + header + "\n");
   for (SimilarUser f : friends) {
     System.out.printf("name: %-36s, similarity: %f\n", f.getName(), f.getSimilarity());
   }
 }