org.apache.mahout.cf.taste.impl.recommender.slopeone.jdbc
Class AbstractJDBCDiffStorage

java.lang.Object
  extended by org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent
      extended by org.apache.mahout.cf.taste.impl.recommender.slopeone.jdbc.AbstractJDBCDiffStorage
All Implemented Interfaces:
Refreshable, DiffStorage
Direct Known Subclasses:
MySQLJDBCDiffStorage

public abstract class AbstractJDBCDiffStorage
extends AbstractJDBCComponent
implements DiffStorage

A DiffStorage which stores diffs in a database. Database-specific implementations subclass this abstract class. Note that this implementation has a fairly particular dependence on the DataModel used; it needs a JDBCDataModel attached to the same database since its efficent operation depends on accessing preference data in the database directly.


Field Summary
static java.lang.String DEFAULT_AVERAGE_DIFF_COLUMN
           
static java.lang.String DEFAULT_COUNT_COLUMN
           
static java.lang.String DEFAULT_DIFF_TABLE
           
static java.lang.String DEFAULT_ITEM_A_COLUMN
           
static java.lang.String DEFAULT_ITEM_B_COLUMN
           
 
Fields inherited from class org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent
DEFAULT_DATASOURCE_NAME
 
Constructor Summary
protected AbstractJDBCDiffStorage(JDBCDataModel dataModel, java.lang.String getDiffSQL, java.lang.String getDiffsSQL, java.lang.String getAverageItemPrefSQL, java.lang.String[] updateDiffSQLs, java.lang.String[] removeDiffSQLs, java.lang.String getRecommendableItemsSQL, java.lang.String deleteDiffsSQL, java.lang.String createDiffsSQL, java.lang.String diffsExistSQL, int minDiffCount)
           
 
Method Summary
 RunningAverage getAverageItemPref(long itemID)
           
 RunningAverage getDiff(long itemID1, long itemID2)
           
 RunningAverage[] getDiffs(long userID, long itemID, PreferenceArray prefs)
           
 FastIDSet getRecommendableItemIDs(long userID)
           
 void refresh(java.util.Collection<Refreshable> alreadyRefreshed)
           Triggers "refresh" -- whatever that means -- of the implementation.
 void updateItemPref(long itemID, float prefDelta, boolean remove)
           Updates internal data structures to reflect an update in a preference value for an item.
 
Methods inherited from class org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent
advanceResultSet, checkNotNullAndLog, checkNotNullAndLog, getFetchSize, lookupDataSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DIFF_TABLE

public static final java.lang.String DEFAULT_DIFF_TABLE
See Also:
Constant Field Values

DEFAULT_ITEM_A_COLUMN

public static final java.lang.String DEFAULT_ITEM_A_COLUMN
See Also:
Constant Field Values

DEFAULT_ITEM_B_COLUMN

public static final java.lang.String DEFAULT_ITEM_B_COLUMN
See Also:
Constant Field Values

DEFAULT_COUNT_COLUMN

public static final java.lang.String DEFAULT_COUNT_COLUMN
See Also:
Constant Field Values

DEFAULT_AVERAGE_DIFF_COLUMN

public static final java.lang.String DEFAULT_AVERAGE_DIFF_COLUMN
See Also:
Constant Field Values
Constructor Detail

AbstractJDBCDiffStorage

protected AbstractJDBCDiffStorage(JDBCDataModel dataModel,
                                  java.lang.String getDiffSQL,
                                  java.lang.String getDiffsSQL,
                                  java.lang.String getAverageItemPrefSQL,
                                  java.lang.String[] updateDiffSQLs,
                                  java.lang.String[] removeDiffSQLs,
                                  java.lang.String getRecommendableItemsSQL,
                                  java.lang.String deleteDiffsSQL,
                                  java.lang.String createDiffsSQL,
                                  java.lang.String diffsExistSQL,
                                  int minDiffCount)
                           throws TasteException
Throws:
TasteException
Method Detail

getDiff

public RunningAverage getDiff(long itemID1,
                              long itemID2)
                       throws TasteException
Specified by:
getDiff in interface DiffStorage
Returns:
RunningAverage encapsulating the average difference in preferences between items corresponding to itemID1 and itemID2, in that direction; that is, it's the average of item 2's preferences minus item 1's preferences
Throws:
TasteException

getDiffs

public RunningAverage[] getDiffs(long userID,
                                 long itemID,
                                 PreferenceArray prefs)
                          throws TasteException
Specified by:
getDiffs in interface DiffStorage
Parameters:
userID - user ID to get diffs for
itemID - itemID to assess
prefs - user's preferendces
Returns:
RunningAverages for that user's item-item diffs
Throws:
TasteException

getAverageItemPref

public RunningAverage getAverageItemPref(long itemID)
                                  throws TasteException
Specified by:
getAverageItemPref in interface DiffStorage
Returns:
RunningAverage encapsulating the average preference for the given item
Throws:
TasteException

updateItemPref

public void updateItemPref(long itemID,
                           float prefDelta,
                           boolean remove)
                    throws TasteException
Description copied from interface: DiffStorage

Updates internal data structures to reflect an update in a preference value for an item.

Specified by:
updateItemPref in interface DiffStorage
Parameters:
itemID - item to update preference value for
prefDelta - amount by which preference value changed (or its old value, if being removed
remove - if true, operation reflects a removal rather than change of preference
Throws:
TasteException

getRecommendableItemIDs

public FastIDSet getRecommendableItemIDs(long userID)
                                  throws TasteException
Specified by:
getRecommendableItemIDs in interface DiffStorage
Returns:
item IDs that may possibly be recommended to the given user, which may not be all items since the item-item diff matrix may be sparse
Throws:
TasteException

refresh

public void refresh(java.util.Collection<Refreshable> alreadyRefreshed)
Description copied from interface: Refreshable

Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any 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 - s that are known to have already been refreshed as a result of an initial call to a method on some object. This ensure that objects in a refresh dependency graph aren't refreshed twice needlessly.


Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.