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 ItemDAO |
itemDAO |
protected ItemScorer |
scorer |
protected UserEventDAO |
userEventDAO |
Constructor and Description |
---|
TopNItemRecommender(UserEventDAO uedao,
ItemDAO idao,
ItemScorer scorer) |
Modifier and Type | Method and Description |
---|---|
protected LongSet |
getDefaultExcludes(long user)
Get the default exclude set for a user.
|
protected LongSet |
getDefaultExcludes(UserHistory<? extends Event> 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 List<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 UserEventDAO userEventDAO
protected final ItemDAO itemDAO
protected final ItemScorer scorer
@Inject public TopNItemRecommender(UserEventDAO uedao, ItemDAO idao, ItemScorer scorer)
public ItemScorer getScorer()
protected List<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 getDefaultExcludes(@Nullable UserHistory<? extends Event> user)
Get the default exclude set for a user. The base implementation returns all the items they have interacted with (from UserHistory.itemSet()
).
user
- The user history.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.