|
||||||||||
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.cassandra.CassandraDataModel
public final class CassandraDataModel
A DataModel
based on a Cassandra keyspace. By default it uses keyspace "recommender" but this
can be configured. Create the keyspace before using this class; this can be done on the Cassandra command
line with a command linke create keyspace recommender;
.
Within the keyspace, this model uses four column families:
First, it uses a column family called "users". This is keyed by the user ID as an 8-byte long. It contains a column for every preference the user expresses. The column name is item ID, again as an 8-byte long, and value is a floating point value represnted as an IEEE 32-bit floating poitn value.
It uses an analogous column family called "items" for the same data, but keyed by item ID rather than user ID. In this column family, column names are user IDs instead.
It uses a column family called "userIDs" as well, with an identical schema. It has one row under key 0. IT contains a column for every user ID in th emodel. It has no values.
Finally it also uses an analogous column family "itemIDs" containing item IDs.
Each of these four column families needs to be created ahead of time. Again the
Cassandra CLI can be used to do so, with commands like create column family users;
.
Note that this thread uses a long-lived Cassandra client which will run until terminated. You
must close()
this implementation when done or the JVM will not terminate.
This implementation still relies heavily on reading data into memory and caching,
as it remains too data-intensive to be effective even against Cassandra. It will take some time to
"warm up" as the first few requests will block loading user and item data into caches. This is still going
to send a great deal of query traffic to Cassandra. It would be advisable to employ caching wrapper
classes in your implementation, like CachingRecommender
or CachingItemSimilarity
.
Constructor Summary | |
---|---|
CassandraDataModel()
Uses the standard Cassandra host and port (localhost:9160), and keyspace name ("recommender"). |
|
CassandraDataModel(String host,
int port,
String keyspaceName)
|
Method Summary | |
---|---|
void |
close()
|
LongPrimitiveIterator |
getItemIDs()
|
FastIDSet |
getItemIDsFromUser(long userID)
|
float |
getMaxPreference()
|
float |
getMinPreference()
|
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)
|
Float |
getPreferenceValue(long userID,
long itemID)
|
LongPrimitiveIterator |
getUserIDs()
|
boolean |
hasPreferenceValues()
|
void |
refresh(Collection<Refreshable> alreadyRefreshed)
|
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 |
---|
public CassandraDataModel()
public CassandraDataModel(String host, int port, String keyspaceName)
host
- Cassandra server host nameport
- Cassandra server portkeyspaceName
- name of Cassandra keyspace to useMethod Detail |
---|
public LongPrimitiveIterator getUserIDs()
getUserIDs
in interface DataModel
public PreferenceArray getPreferencesFromUser(long userID) throws TasteException
getPreferencesFromUser
in interface DataModel
TasteException
public FastIDSet getItemIDsFromUser(long userID) throws TasteException
getItemIDsFromUser
in interface DataModel
TasteException
public LongPrimitiveIterator getItemIDs()
getItemIDs
in interface DataModel
public PreferenceArray getPreferencesForItem(long itemID) throws TasteException
getPreferencesForItem
in interface DataModel
TasteException
public Float getPreferenceValue(long userID, long itemID)
getPreferenceValue
in interface DataModel
public Long getPreferenceTime(long userID, long itemID)
getPreferenceTime
in interface DataModel
public int getNumItems()
getNumItems
in interface DataModel
public int getNumUsers()
getNumUsers
in interface DataModel
public int getNumUsersWithPreferenceFor(long itemID) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
TasteException
public int getNumUsersWithPreferenceFor(long itemID1, long itemID2) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
TasteException
public void setPreference(long userID, long itemID, float value)
setPreference
in interface DataModel
public void removePreference(long userID, long itemID)
removePreference
in interface DataModel
public boolean hasPreferenceValues()
hasPreferenceValues
in interface DataModel
public float getMaxPreference()
getMaxPreference
in interface DataModel
public float getMinPreference()
getMinPreference
in interface DataModel
public void refresh(Collection<Refreshable> alreadyRefreshed)
refresh
in interface Refreshable
public String toString()
toString
in class Object
public void close()
close
in interface Closeable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |