public final class GenericDataModel extends AbstractDataModel
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 and Description |
---|
GenericDataModel(DataModel dataModel)
Deprecated.
without direct replacement.
Consider
toDataMap(DataModel) with GenericDataModel(FastByIDMap) |
GenericDataModel(FastByIDMap<PreferenceArray> userData)
Creates a new
GenericDataModel from the given users (and their preferences). |
GenericDataModel(FastByIDMap<PreferenceArray> userData,
FastByIDMap<FastByIDMap<Long>> timestamps)
Creates a new
GenericDataModel from the given users (and their preferences). |
Modifier and Type | Method and Description |
---|---|
LongPrimitiveArrayIterator |
getItemIDs() |
FastIDSet |
getItemIDsFromUser(long userID) |
int |
getNumItems() |
int |
getNumUsers() |
int |
getNumUsersWithPreferenceFor(long itemID) |
int |
getNumUsersWithPreferenceFor(long itemID1,
long itemID2) |
PreferenceArray |
getPreferencesForItem(long itemID) |
PreferenceArray |
getPreferencesFromUser(long userID) |
Long |
getPreferenceTime(long userID,
long itemID)
Retrieves the time at which a preference value from a user and item was set, if known.
|
Float |
getPreferenceValue(long userID,
long itemID)
Retrieves the preference value for a single user and item.
|
FastByIDMap<PreferenceArray> |
getRawItemData()
This is used mostly internally to the framework, and shouldn't be relied upon otherwise.
|
FastByIDMap<PreferenceArray> |
getRawUserData()
This is used mostly internally to the framework, and shouldn't be relied upon otherwise.
|
LongPrimitiveArrayIterator |
getUserIDs() |
boolean |
hasPreferenceValues() |
void |
refresh(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(DataModel dataModel)
Exports the simple user IDs and preferences in the data model.
|
static FastByIDMap<PreferenceArray> |
toDataMap(FastByIDMap<Collection<Preference>> data,
boolean byUser)
|
String |
toString() |
getMaxPreference, getMinPreference, setMaxPreference, setMinPreference
public GenericDataModel(FastByIDMap<PreferenceArray> userData)
Creates a new GenericDataModel
from the given users (and their preferences). This
DataModel
retains all this information in memory and is effectively immutable.
userData
- users to include; (see also toDataMap(FastByIDMap, boolean)
)public GenericDataModel(FastByIDMap<PreferenceArray> userData, FastByIDMap<FastByIDMap<Long>> timestamps)
Creates a new GenericDataModel
from the given users (and their preferences). This
DataModel
retains all this information in memory and is effectively immutable.
userData
- users to include; (see also toDataMap(FastByIDMap, boolean)
)timestamps
- optionally, provided timestamps of preferences as milliseconds since the epoch.
User IDs are mapped to maps of item IDs to Long timestamps.@Deprecated public GenericDataModel(DataModel dataModel) throws TasteException
toDataMap(DataModel)
with GenericDataModel(FastByIDMap)
Creates a new GenericDataModel
containing an immutable copy of the data from another given
DataModel
.
dataModel
- DataModel
to copyTasteException
- if an error occurs while retrieving the other DataModel
's userspublic static FastByIDMap<PreferenceArray> toDataMap(FastByIDMap<Collection<Preference>> data, boolean byUser)
public static FastByIDMap<PreferenceArray> toDataMap(DataModel dataModel) throws TasteException
FastByIDMap
mapping user IDs to PreferenceArray
s representing
that user's preferencesTasteException
public FastByIDMap<PreferenceArray> getRawUserData()
public FastByIDMap<PreferenceArray> getRawItemData()
public LongPrimitiveArrayIterator getUserIDs()
public PreferenceArray getPreferencesFromUser(long userID) throws NoSuchUserException
userID
- ID of user to get prefs forNoSuchUserException
- if there is no such userpublic FastIDSet getItemIDsFromUser(long userID) throws TasteException
userID
- ID of user to get prefs forNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic LongPrimitiveArrayIterator getItemIDs()
LongPrimitiveIterator
of all item IDs in the model, in orderpublic PreferenceArray getPreferencesForItem(long itemID) throws NoSuchItemException
itemID
- item IDPreference
s expressed for that item, ordered by user ID, as an arrayNoSuchItemException
- if the item does not existpublic Float getPreferenceValue(long userID, long itemID) throws TasteException
DataModel
userID
- user ID to get pref value fromitemID
- item ID to get pref value forNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic Long getPreferenceTime(long userID, long itemID) throws TasteException
DataModel
userID
- user ID for preference in questionitemID
- item ID for preference in questionNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic int getNumItems()
public int getNumUsers()
public int getNumUsersWithPreferenceFor(long itemID)
itemID
- item ID to check forpublic int getNumUsersWithPreferenceFor(long itemID1, long itemID2)
itemID1
- first item ID to check foritemID2
- second item ID to check forpublic void removePreference(long userID, long itemID)
DataModel
Removes a particular preference for a user.
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.
userID
- user to set preference foritemID
- item to set preference forvalue
- preference valuepublic 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.
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 boolean hasPreferenceValues()
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.