org.apache.mahout.cf.taste.model
Interface DataModel

All Superinterfaces:
Refreshable
All Known Subinterfaces:
JDBCDataModel
All Known Implementing Classes:
AbstractBooleanPrefJDBCDataModel, AbstractJDBCDataModel, FileDataModel, GenericBooleanPrefDataModel, GenericDataModel, GenericJDBCDataModel, MySQLBooleanPrefJDBCDataModel, MySQLJDBCDataModel, PlusAnonymousUserDataModel

public interface DataModel
extends Refreshable

Implementations represent a repository of information about users and their associated Preferences for items.


Method Summary
 LongPrimitiveIterator getItemIDs()
           
 FastIDSet getItemIDsFromUser(long userID)
           
 int getNumItems()
           
 int getNumUsers()
           
 int getNumUsersWithPreferenceFor(long... itemIDs)
           
 PreferenceArray getPreferencesForItem(long itemID)
           
 PreferenceArray getPreferencesFromUser(long userID)
           
 java.lang.Float getPreferenceValue(long userID, long itemID)
          Retrieves the preference value for a single user and item.
 LongPrimitiveIterator getUserIDs()
           
 boolean hasPreferenceValues()
           
 void removePreference(long userID, long itemID)
           Removes a particular preference for a user.
 void setPreference(long userID, long itemID, float value)
           Sets a particular preference (item plus rating) for a user.
 
Methods inherited from interface org.apache.mahout.cf.taste.common.Refreshable
refresh
 

Method Detail

getUserIDs

LongPrimitiveIterator getUserIDs()
                                 throws TasteException
Returns:
all user IDs in the model, in order
Throws:
TasteException - if an error occurs while accessing the data

getPreferencesFromUser

PreferenceArray getPreferencesFromUser(long userID)
                                       throws TasteException
Parameters:
userID - ID of user to get prefs for
Returns:
user's preferences, ordered by item ID
Throws:
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data

getItemIDsFromUser

FastIDSet getItemIDsFromUser(long userID)
                             throws TasteException
Parameters:
userID - ID of user to get prefs for
Returns:
IDs of items user expresses a preference for
Throws:
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data

getItemIDs

LongPrimitiveIterator getItemIDs()
                                 throws TasteException
Returns:
a List of all item IDs in the model, in order
Throws:
TasteException - if an error occurs while accessing the data

getPreferencesForItem

PreferenceArray getPreferencesForItem(long itemID)
                                      throws TasteException
Parameters:
itemID - item ID
Returns:
all existing Preferences expressed for that item, ordered by user ID, as an array
Throws:
NoSuchItemException - if the item does not exist
TasteException - if an error occurs while accessing the data

getPreferenceValue

java.lang.Float getPreferenceValue(long userID,
                                   long itemID)
                                   throws TasteException
Retrieves the preference value for a single user and item.

Parameters:
userID - user ID to get pref value from
itemID - item ID to get pref value for
Returns:
preference value from the given user for the given item or null if none exists
Throws:
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data

getNumItems

int getNumItems()
                throws TasteException
Returns:
total number of items known to the model. This is generally the union of all items preferred by at least one user but could include more.
Throws:
TasteException - if an error occurs while accessing the data

getNumUsers

int getNumUsers()
                throws TasteException
Returns:
total number of users known to the model.
Throws:
TasteException - if an error occurs while accessing the data

getNumUsersWithPreferenceFor

int getNumUsersWithPreferenceFor(long... itemIDs)
                                 throws TasteException
Parameters:
itemIDs - item IDs to check for
Returns:
the number of users who have expressed a preference for all of the items
Throws:
TasteException - if an error occurs while accessing the data
java.lang.IllegalArgumentException - if itemIDs is null, empty, or larger than 2 elements since currently only queries of up to 2 items are needed and supported
NoSuchItemException - if an item does not exist

setPreference

void setPreference(long userID,
                   long itemID,
                   float value)
                   throws TasteException

Sets a particular preference (item plus rating) for a user.

Parameters:
userID - user to set preference for
itemID - item to set preference for
value - preference value
Throws:
NoSuchItemException - if the item does not exist
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data

removePreference

void removePreference(long userID,
                      long itemID)
                      throws TasteException

Removes a particular preference for a user.

Parameters:
userID - user from which to remove preference
itemID - item to remove preference for
Throws:
NoSuchItemException - if the item does not exist
NoSuchUserException - if the user does not exist
TasteException - if an error occurs while accessing the data

hasPreferenceValues

boolean hasPreferenceValues()


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