org.apache.mahout.cf.taste.impl.recommender
Class CachingRecommender

java.lang.Object
  extended by org.apache.mahout.cf.taste.impl.recommender.CachingRecommender
All Implemented Interfaces:
Refreshable, Recommender

public final class CachingRecommender
extends Object
implements Recommender

A Recommender which caches the results from another Recommender in memory.


Constructor Summary
CachingRecommender(Recommender recommender)
           
 
Method Summary
 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, IDRescorer rescorer)
           
 void refresh(Collection<Refreshable> alreadyRefreshed)
           Triggers "refresh" -- whatever that means -- of the implementation.
 void removePreference(long userID, long itemID)
           
 void setPreference(long userID, long itemID, float value)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CachingRecommender

public CachingRecommender(Recommender recommender)
                   throws TasteException
Throws:
TasteException
Method Detail

recommend

public List<RecommendedItem> recommend(long userID,
                                       int howMany)
                                throws TasteException
Specified by:
recommend in interface Recommender
Parameters:
userID - user for which recommendations are to be computed
howMany - desired number of recommendations
Returns:
List of recommended RecommendedItems, ordered from most strongly recommend to least
Throws:
TasteException - if an error occurs while accessing the DataModel

recommend

public List<RecommendedItem> recommend(long userID,
                                       int howMany,
                                       IDRescorer rescorer)
                                throws TasteException
Specified by:
recommend in interface Recommender
Parameters:
userID - user for which recommendations are to be computed
howMany - desired number of recommendations
rescorer - rescoring function to apply before final list of recommendations is determined
Returns:
List of recommended RecommendedItems, ordered from most strongly recommend to least
Throws:
TasteException - if an error occurs while accessing the DataModel

estimatePreference

public float estimatePreference(long userID,
                                long itemID)
                         throws TasteException
Specified by:
estimatePreference in interface Recommender
Parameters:
userID - user ID whose preference is to be estimated
itemID - item ID to estimate preference for
Returns:
an estimated preference if the user has not expressed a preference for the item, or else the user's actual preference for the item. If a preference cannot be estimated, returns Double.NaN
Throws:
TasteException - if an error occurs while accessing the DataModel

setPreference

public void setPreference(long userID,
                          long itemID,
                          float value)
                   throws TasteException
Specified by:
setPreference in interface Recommender
Parameters:
userID - user to set preference for
itemID - item to set preference for
value - preference value
Throws:
TasteException - if an error occurs while accessing the DataModel

removePreference

public void removePreference(long userID,
                             long itemID)
                      throws TasteException
Specified by:
removePreference in interface Recommender
Parameters:
userID - user from which to remove preference
itemID - item for which to remove preference
Throws:
TasteException - if an error occurs while accessing the DataModel

getDataModel

public DataModel getDataModel()
Specified by:
getDataModel in interface Recommender
Returns:
underlying DataModel used by this Recommender implementation

refresh

public void refresh(Collection<Refreshable> alreadyRefreshed)
Description copied from interface: 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.

Specified by:
refresh in interface Refreshable
Parameters:
alreadyRefreshed - Refreshables that are known to have already been refreshed as a result of an initial call to a Refreshable.refresh(Collection) method on some object. This ensure that objects in a refresh dependency graph aren't refreshed twice needlessly.

clear

public void clear(long userID)

Clears cached recommendations for the given user.

Parameters:
userID - clear cached data associated with this user ID

clear

public void clear()

Clears all cached recommendations.


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.