public abstract class AbstractItemRecommender extends Object implements ItemRecommender
Base class to ease implementation of item recommenders.
Constructor and Description |
---|
AbstractItemRecommender() |
Modifier and Type | Method and Description |
---|---|
List<Long> |
recommend(long user)
Recommend all possible items for a user using the default exclude set.
|
List<Long> |
recommend(long user,
int n)
Recommend up to
n items for a user using the default exclude set. |
protected List<Long> |
recommend(long user,
int n,
LongSet candidates,
LongSet exclude)
Primary method for implementing an item recommender without details.
|
List<Long> |
recommend(long user,
int n,
Set<Long> candidates,
Set<Long> exclude)
Produce a set of recommendations for the user.
|
protected abstract ResultList |
recommendWithDetails(long user,
int n,
LongSet candidates,
LongSet exclude)
Primary method for implementing an item recommender.
|
ResultList |
recommendWithDetails(long user,
int n,
Set<Long> candidates,
Set<Long> exclude)
Produce a set of recommendations for the user with additional details.
|
public List<Long> recommend(long user)
Recommend all possible items for a user using the default exclude set.
This implementation delegates to recommend(long, int)
with a length of -1.
recommend
in interface ItemRecommender
user
- The user ID.ItemRecommender.recommend(long, int, Set, Set)
public List<Long> recommend(long user, int n)
Recommend up to n
items for a user using the default exclude set.
This implementation delegates to recommend(long, int, Set, Set)
with a length of -1 and null sets.
recommend
in interface ItemRecommender
user
- The user ID.n
- The number of recommendations to return. Negative values indicate no preference of recommendation list size.ItemRecommender.recommend(long, int, Set, Set)
public List<Long> recommend(long user, int n, @Nullable Set<Long> candidates, @Nullable Set<Long> exclude)
Produce a set of recommendations for the user. This is the most general recommendation method, allowing the recommendations to be constrained by both a candidate set and an exclude set. The exclude set is applied to the candidate set, so the final effective candidate set is canditates minus exclude.
This implementation delegates to recommend(long, int, LongSet, LongSet)
.
recommend
in interface ItemRecommender
user
- The user’s IDn
- The number of ratings to return. If negative, there is no specific recommendation list size requested.candidates
- A set of candidate items which can be recommended. If null
, all items are considered candidates.exclude
- A set of items to be excluded. If null
, a default exclude set is used.protected List<Long> recommend(long user, int n, @Nullable LongSet candidates, @Nullable LongSet exclude)
Primary method for implementing an item recommender without details. The default implementation delegates to recommendWithDetails(long, int, LongSet, LongSet)
.
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.recommend(long, int, Set, Set)
public ResultList recommendWithDetails(long user, int n, @Nullable Set<Long> candidates, @Nullable Set<Long> exclude)
ItemRecommender
Produce a set of recommendations for the user with additional details. This method functions identically to ItemRecommender.recommend(long, int, Set, Set)
, except that it may produce more detailed results. Implementations will return subclasses of ResultList
that provide access to additional details about each recommendation.
recommendWithDetails
in interface ItemRecommender
user
- The user’s IDn
- The number of ratings to return. If negative, there is no specific recommendation list size requested.candidates
- A set of candidate items which can be recommended. If null
, all items are considered candidates.exclude
- A set of items to be excluded. If null
, a default exclude set is used.Double.NaN
. For most scoring recommenders, the items will be ordered in decreasing order of score. This is not a hard requirement — e.g. set recommenders are allowed to be more flexible.protected abstract ResultList recommendWithDetails(long user, int n, @Nullable LongSet candidates, @Nullable LongSet exclude)
Primary method for implementing an item recommender.
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.recommendWithDetails(long, int, Set, Set)