GenericItemBasedRecommender extends AbstractRecommender implements ItemBasedRecommender { @Override public List<RecommendedItem> mostSimilarItems(long itemID, int howMany) throws TasteException { return mostSimilarItems(itemID, howMany, null); } GenericItemBasedRecommender(DataModel dataModel,
                                     ItemSimilarity similarity,
                                     CandidateItemsStrategy candidateItemsStrategy,
                                     MostSimilarItemsCandidateItemsStrategy mostSimilarItemsCandidateItemsStrategy);  GenericItemBasedRecommender(DataModel dataModel, ItemSimilarity similarity); ItemSimilarity getSimilarity(); @Override List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems); @Override float estimatePreference(long userID, long itemID); @Override List<RecommendedItem> mostSimilarItems(long itemID, int howMany); @Override List<RecommendedItem> mostSimilarItems(long itemID, int howMany,
                                                Rescorer<LongPair> rescorer); @Override List<RecommendedItem> mostSimilarItems(long[] itemIDs, int howMany); @Override List<RecommendedItem> mostSimilarItems(long[] itemIDs, int howMany,
                                                Rescorer<LongPair> rescorer); @Override List<RecommendedItem> mostSimilarItems(long[] itemIDs,
                                                int howMany,
                                                boolean excludeItemIfNotSimilarToAll); @Override List<RecommendedItem> mostSimilarItems(long[] itemIDs, int howMany,
                                                Rescorer<LongPair> rescorer,
                                                boolean excludeItemIfNotSimilarToAll); @Override List<RecommendedItem> recommendedBecause(long userID, long itemID, int howMany); @Override void refresh(Collection<Refreshable> alreadyRefreshed); @Override String toString();  }
@Test public void testMostSimilar() throws Exception { ItemBasedRecommender recommender = buildRecommender(); List<RecommendedItem> similar = recommender.mostSimilarItems(0, 2); assertNotNull(similar); assertEquals(2, similar.size()); RecommendedItem first = similar.get(0); RecommendedItem second = similar.get(1); assertEquals(1, first.getItemID()); assertEquals(1.0f, first.getValue(), EPSILON); assertEquals(2, second.getItemID()); assertEquals(0.5f, second.getValue(), EPSILON); }
@Test public void testMostSimilarToMultiple() throws Exception { ItemBasedRecommender recommender = buildRecommender2(); List<RecommendedItem> similar = recommender.mostSimilarItems(new long[] {0, 1}, 2); assertNotNull(similar); assertEquals(2, similar.size()); RecommendedItem first = similar.get(0); RecommendedItem second = similar.get(1); assertEquals(2, first.getItemID()); assertEquals(0.85f, first.getValue(), EPSILON); assertEquals(3, second.getItemID()); assertEquals(-0.3f, second.getValue(), EPSILON); }
@Test public void testMostSimilarToMultipleExcludeIfNotSimilarToAll() throws Exception { ItemBasedRecommender recommender = buildRecommender2(); List<RecommendedItem> similar = recommender.mostSimilarItems(new long[] {3, 4}, 2); assertNotNull(similar); assertEquals(1, similar.size()); RecommendedItem first = similar.get(0); assertEquals(0, first.getItemID()); assertEquals(0.2f, first.getValue(), EPSILON); }
@Test public void testMostSimilarToMultipleDontExcludeIfNotSimilarToAll() throws Exception { ItemBasedRecommender recommender = buildRecommender2(); List<RecommendedItem> similar = recommender.mostSimilarItems(new long[] {1, 2, 4}, 10, false); assertNotNull(similar); assertEquals(2, similar.size()); RecommendedItem first = similar.get(0); RecommendedItem second = similar.get(1); assertEquals(0, first.getItemID()); assertEquals(0.933333333f, first.getValue(), EPSILON); assertEquals(3, second.getItemID()); assertEquals(-0.2f, second.getValue(), EPSILON); }