public final class CachingRecommender extends Object implements Recommender
A Recommender
which caches the results from another Recommender
in memory.
TODO: Should be checked for thread safety
Constructor and Description |
---|
CachingRecommender(Recommender recommender) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all cached recommendations.
|
void |
clear(long userID)
Clears cached recommendations for the given user.
|
float |
estimatePreference(long userID,
long itemID) |
DataModel |
getDataModel() |
List<RecommendedItem> |
recommend(long userID,
int howMany) |
List<RecommendedItem> |
recommend(long userID,
int howMany,
boolean includeKnownItems) |
List<RecommendedItem> |
recommend(long userID,
int howMany,
IDRescorer rescorer) |
List<RecommendedItem> |
recommend(long userID,
int howMany,
IDRescorer rescorer,
boolean includeKnownItems) |
void |
refresh(Collection<Refreshable> alreadyRefreshed)
Triggers "refresh" -- whatever that means -- of the implementation.
|
void |
removePreference(long userID,
long itemID) |
void |
setCurrentlyIncludeKnownItems(boolean currentlyIncludeKnownItems) |
void |
setPreference(long userID,
long itemID,
float value) |
String |
toString() |
public CachingRecommender(Recommender recommender) throws TasteException
TasteException
public void setCurrentlyIncludeKnownItems(boolean currentlyIncludeKnownItems)
public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException
recommend
in interface Recommender
userID
- user for which recommendations are to be computedhowMany
- desired number of recommendationsList
of recommended RecommendedItem
s, ordered from most strongly recommend to
leastTasteException
- if an error occurs while accessing the DataModel
public List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException
recommend
in interface Recommender
userID
- user for which recommendations are to be computedhowMany
- desired number of recommendationsincludeKnownItems
- whether to include items already known by the user in recommendationsList
of recommended RecommendedItem
s, ordered from most strongly recommend to
leastTasteException
- if an error occurs while accessing the DataModel
public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException
recommend
in interface Recommender
userID
- user for which recommendations are to be computedhowMany
- desired number of recommendationsrescorer
- rescoring function to apply before final list of recommendations is determinedList
of recommended RecommendedItem
s, ordered from most strongly recommend to
leastTasteException
- if an error occurs while accessing the DataModel
public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems) throws TasteException
recommend
in interface Recommender
userID
- user for which recommendations are to be computedhowMany
- desired number of recommendationsrescorer
- rescoring function to apply before final list of recommendations is determinedincludeKnownItems
- whether to include items already known by the user in recommendationsList
of recommended RecommendedItem
s, ordered from most strongly recommend to
leastTasteException
- if an error occurs while accessing the DataModel
public float estimatePreference(long userID, long itemID) throws TasteException
estimatePreference
in interface Recommender
userID
- user ID whose preference is to be estimateditemID
- item ID to estimate preference forDouble.NaN
TasteException
- if an error occurs while accessing the DataModel
public void setPreference(long userID, long itemID, float value) throws TasteException
setPreference
in interface Recommender
userID
- user to set preference foritemID
- item to set preference forvalue
- preference valueTasteException
- if an error occurs while accessing the DataModel
public void removePreference(long userID, long itemID) throws TasteException
removePreference
in interface Recommender
userID
- user from which to remove preferenceitemID
- item for which to remove preferenceTasteException
- if an error occurs while accessing the DataModel
public DataModel getDataModel()
getDataModel
in interface Recommender
DataModel
used by this Recommender
implementationpublic void refresh(Collection<Refreshable> alreadyRefreshed)
Refreshable
Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any
Refreshable
should always leave itself in a consistent, operational state, and that the refresh
atomically updates internal state from old to new.
refresh
in interface Refreshable
alreadyRefreshed
- Refreshable
s that are known to have already been
refreshed as a result of an initial call to a {#refresh(Collection)} method on some
object. This ensure that objects in a refresh dependency graph aren't refreshed twice
needlessly.public void clear(long userID)
Clears cached recommendations for the given user.
userID
- clear cached data associated with this user IDpublic void clear()
Clears all cached recommendations.
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.