|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.mahout.cf.taste.impl.model.GenericDataModel
public final class GenericDataModel
A simple DataModel
which uses a given List
of users as its data source. This implementation
is mostly useful for small experiments and is not recommended for contexts where performance is important.
Constructor Summary | |
---|---|
GenericDataModel(DataModel dataModel)
Creates a new containing an immutable copy of the data from another given DataModel . |
|
GenericDataModel(FastByIDMap<PreferenceArray> userData)
Creates a new from the given users (and their preferences). |
Method Summary | |
---|---|
LongPrimitiveArrayIterator |
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. |
FastByIDMap<PreferenceArray> |
getRawUserData()
This is used mostly internally to the framework, and shouldn't be relied upon otherwise. |
LongPrimitiveArrayIterator |
getUserIDs()
|
boolean |
hasPreferenceValues()
|
void |
refresh(java.util.Collection<Refreshable> alreadyRefreshed)
Triggers "refresh" -- whatever that means -- of the implementation. |
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. |
static FastByIDMap<PreferenceArray> |
toDataMap(FastByIDMap<java.util.Collection<Preference>> data,
boolean byUser)
Swaps, in-place, List s for arrays in Map values . |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GenericDataModel(FastByIDMap<PreferenceArray> userData)
Creates a new from the given users (and their preferences). This
DataModel
retains all this information in memory and is effectively immutable.
userData
- users to include in this (see also
toDataMap(FastByIDMap, boolean)
)public GenericDataModel(DataModel dataModel) throws TasteException
Creates a new containing an immutable copy of the data from another given
DataModel
.
dataModel
- DataModel
to copy
TasteException
- if an error occurs while retrieving the other DataModel
's usersMethod Detail |
---|
public static FastByIDMap<PreferenceArray> toDataMap(FastByIDMap<java.util.Collection<Preference>> data, boolean byUser)
List
s for arrays in Map
values .
public FastByIDMap<PreferenceArray> getRawUserData()
public LongPrimitiveArrayIterator getUserIDs()
getUserIDs
in interface DataModel
public PreferenceArray getPreferencesFromUser(long userID) throws NoSuchUserException
getPreferencesFromUser
in interface DataModel
userID
- ID of user to get prefs for
NoSuchUserException
- if there is no such userpublic FastIDSet getItemIDsFromUser(long userID) throws TasteException
getItemIDsFromUser
in interface DataModel
userID
- ID of user to get prefs for
NoSuchUserException
- if the user does not exist
TasteException
- if an error occurs while accessing the datapublic LongPrimitiveArrayIterator getItemIDs()
getItemIDs
in interface DataModel
List
of all item IDs in the model, in orderpublic PreferenceArray getPreferencesForItem(long itemID) throws NoSuchItemException
getPreferencesForItem
in interface DataModel
itemID
- item ID
Preference
s expressed for that item, ordered by user ID, as an array
NoSuchItemException
- if the item does not existpublic java.lang.Float getPreferenceValue(long userID, long itemID) throws TasteException
DataModel
getPreferenceValue
in interface DataModel
userID
- user ID to get pref value fromitemID
- item ID to get pref value for
NoSuchUserException
- if the user does not exist
TasteException
- if an error occurs while accessing the datapublic int getNumItems()
getNumItems
in interface DataModel
public int getNumUsers()
getNumUsers
in interface DataModel
public int getNumUsersWithPreferenceFor(long... itemIDs)
getNumUsersWithPreferenceFor
in interface DataModel
itemIDs
- item IDs to check for
public void removePreference(long userID, long itemID)
DataModel
Removes a particular preference for a user.
removePreference
in interface DataModel
userID
- user from which to remove preferenceitemID
- item to remove preference forpublic void setPreference(long userID, long itemID, float value)
DataModel
Sets a particular preference (item plus rating) for a user.
setPreference
in interface DataModel
userID
- user to set preference foritemID
- item to set preference forvalue
- preference valuepublic void refresh(java.util.Collection<Refreshable> alreadyRefreshed)
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.
refresh
in interface Refreshable
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.public boolean hasPreferenceValues()
hasPreferenceValues
in interface DataModel
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |