public class TopNItemRecommender extends AbstractItemRecommender
Recommender that recommends the top N items by a scorer. Implements all methods required by AbstractItemRecommender
. The default exclude set is all items rated by the user.
Recommendations are returned in descending order of score.
Modifier and Type | Field and Description |
---|---|
protected DataAccessObject |
dao |
protected ItemScorer |
scorer |
Constructor and Description |
---|
TopNItemRecommender(DataAccessObject data,
ItemScorer scorer) |
Modifier and Type | Method and Description |
---|---|
protected LongSet |
getDefaultExcludes(long user)
Get the default exclude set for a user.
|
protected LongSet |
getPredictableItems(long user)
Determine the items for which predictions can be made for a certain user.
|
ItemScorer |
getScorer() |
protected java.util.List<java.lang.Long> |
recommend(long user,
int n,
LongSet candidates,
LongSet exclude)
Implement recommendation by calling
ItemScorer.score(long, Collection) and sorting the results by score. |
protected ResultList |
recommendWithDetails(long user,
int n,
LongSet candidates,
LongSet exclude)
Implement recommendation by calling
ItemScorer.scoreWithDetails(long, Collection) and sorting the results. |
recommend, recommend, recommend, recommendWithDetails
protected final DataAccessObject dao
protected final ItemScorer scorer
@Inject public TopNItemRecommender(DataAccessObject data, ItemScorer scorer)
public ItemScorer getScorer()
protected java.util.List<java.lang.Long> recommend(long user, int n, LongSet candidates, LongSet exclude)
Implement recommendation by calling ItemScorer.score(long, Collection)
and sorting the results by score. This method uses getDefaultExcludes(long)
to get the default exclude set for the user, if none is provided.
recommend
in class AbstractItemRecommender
user
- The user ID.n
- The number of recommendations to produce, or a negative value to produce unlimited recommendations.candidates
- The candidate items, or null
for default.exclude
- The exclude set, or null
for default.AbstractItemRecommender.recommend(long, int, Set, Set)
protected ResultList recommendWithDetails(long user, int n, LongSet candidates, LongSet exclude)
Implement recommendation by calling ItemScorer.scoreWithDetails(long, Collection)
and sorting the results. This method uses getDefaultExcludes(long)
to get the default exclude set for the user, if none is provided.
recommendWithDetails
in class AbstractItemRecommender
user
- The user ID.n
- The number of recommendations to produce, or a negative value to produce unlimited recommendations.candidates
- The candidate items, or null
for default.exclude
- The exclude set, or null
for default.AbstractItemRecommender.recommendWithDetails(long, int, Set, Set)
protected LongSet getDefaultExcludes(long user)
Get the default exclude set for a user. The base implementation gets all the items they have interacted with.
user
- The user ID.protected LongSet getPredictableItems(long user)
Determine the items for which predictions can be made for a certain user. This implementation is naive and asks the DAO for all items; subclasses should override it with something more efficient if practical.
user
- The user’s ID.