SlopeOneRecommender extends AbstractRecommender { @Override public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException { Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); log.debug("Recommending items for user ID '{}'", userID); FastIDSet possibleItemIDs = diffStorage.getRecommendableItemIDs(userID); TopItems.Estimator<Long> estimator = new Estimator(userID); List<RecommendedItem> topItems = TopItems.getTopItems(howMany, possibleItemIDs.iterator(), rescorer, estimator); log.debug("Recommendations are: {}", topItems); return topItems; } SlopeOneRecommender(DataModel dataModel);  SlopeOneRecommender(DataModel dataModel,
                             Weighting weighting,
                             Weighting stdDevWeighting,
                             DiffStorage diffStorage); @Override List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer); @Override float estimatePreference(long userID, long itemID); @Override void setPreference(long userID, long itemID, float value); @Override void removePreference(long userID, long itemID); @Override void refresh(Collection<Refreshable> alreadyRefreshed); @Override String toString();  }
@Test public void testRescorer() throws Exception { DataModel dataModel = getDataModel( new long[] {1, 2, 3}, new Double[][] { {0.1, 0.2}, {0.2, 0.3, 0.3, 0.6}, {0.4, 0.4, 0.5, 0.9}, }); Recommender recommender = new SlopeOneRecommender(dataModel); List<RecommendedItem> originalRecommended = recommender.recommend(1, 2); List<RecommendedItem> rescoredRecommended = recommender.recommend(1, 2, new ReversingRescorer<Long>()); assertNotNull(originalRecommended); assertNotNull(rescoredRecommended); assertEquals(2, originalRecommended.size()); assertEquals(2, rescoredRecommended.size()); assertEquals(originalRecommended.get(0).getItemID(), rescoredRecommended.get(1).getItemID()); assertEquals(originalRecommended.get(1).getItemID(), rescoredRecommended.get(0).getItemID()); }
@Test public void testBestRating() throws Exception { DataModel dataModel = getDataModel( new long[] {1, 2, 3}, new Double[][] { {0.0, 0.3}, {0.2, 0.3, 0.3}, {0.4, 0.3, 0.5}, }); Recommender recommender = new SlopeOneRecommender(dataModel); List<RecommendedItem> recommended = recommender.recommend(1, 1); assertNotNull(recommended); assertEquals(1, recommended.size()); RecommendedItem firstRecommended = recommended.get(0); assertEquals(2, firstRecommended.getItemID()); assertEquals(0.2400938676203033, firstRecommended.getValue(), EPSILON); }