|
CFEngine API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.recommender.server.DataManager
Implementation of the DataManager. This class handles all the cached data in a CF Engine Application. This includes reading and writing out User Info, Item Info, Ratings Info. It will also be responsible for deciding when to cache in data and when to write it out to disk. The interface should be generic enough so that the transition is painless.
Field Summary | |
(package private) java.util.LinkedList |
dbUsers
|
Constructor Summary | |
DataManager(boolean loadRatings,
boolean doSampling)
Create a new DataManager object, establish connection with database, and cache ratings into memory. |
Method Summary | |
void |
addCachedRating(ItemRating rating)
Add ratings to cache but not to the database. |
void |
addRating(ItemRating rating)
Adds a new rating to both database and the cache. |
void |
cacheRatingGroup(java.util.Iterator iter)
|
void |
cacheTypedItemList()
Cache typed item list from database into memory - avoid too many disk IO access |
void |
cacheUserTopN(int userID,
ItemPrediction[] predictions)
Cache user TopN data computed by one of our algorithms. |
boolean |
checkCachedTopN(int userID)
Check wether a user's TopN data is cached on the server side. |
void |
checkCachedUser(int userID)
Check this user's ratings records and load into cache if not done yet Upon return from this method, the user's record is guaranteed to be in memory and will not be evicted until you call decUserCount() on the UserInfo structure. |
void |
decCachedUsers()
|
void |
decNumItems()
|
void |
decNumUsers()
|
void |
decUseCount(int userID)
Sets the inUse field of the specified user. |
int |
getAddedRatings(int userID)
Get the value of a user's counter of added ratings. |
java.util.Iterator |
getAllUsers()
Return an iterator through all user ID's, each one an Integer object. |
ItemPrediction[] |
getCachedTopN(int userID,
int number,
int offset)
Returns a user's top N recommendations, retrieved from the server side memory cache. |
java.util.Vector |
getCachedTypedItemList(int typeID)
Get a vector of specific typed Item List. |
java.util.Iterator |
getCachedTypedItemLists(int typeID)
Get an iterator through a list of specific typed Item List. |
float |
getCoverage()
Get the percentage of item entries that are not null i.e., items for which we can compute a prediction. |
float |
getErrRating()
Accessor, return error rating |
ItemInfo |
getItemInfo(int itemID)
|
java.util.Iterator |
getItemList(int userID)
Returns a list of item ratings for a given user using the cached data Load the user into the cache if not done yet (because of data sampling). |
ItemRating |
getItemRatingCached(int userID,
int itemID)
Get rating from the cache. |
ItemRating[] |
getItemRatingList(int itemID)
Return an array of userIDs who have rated the given item. |
float |
getItemSD(int itemID)
Returns the standard deviation of the item's ratings from the cache. |
java.lang.String |
getItemTypeInfoDatabaseName()
Accessor, return itemTypeTableName |
int |
getMaxItem()
Accessor, return max item ID |
float |
getMaxRating()
Accessor, return MaxRating |
int |
getMaxType()
|
int |
getMaxUser()
Accessor, return max user ID |
float |
getMeanItemRatingCached(int itemID)
Return the mean of item's ratings from the cache. |
float |
getMeanRatingCached(int userID)
Return the mean of user's ratings from the cache. |
float |
getMinRating()
Accessor, return MinRating |
java.util.Iterator |
getNeighborhood(int itemID)
Returns a list of ItemRatings representing ratings of users. |
int |
getNextItemId()
|
int |
getNextUserId()
|
int |
getNumItems()
|
int |
getNumRaters(int itemID)
Returns the number of users who have rated the corresponding item. |
int |
getNumRatings(int userID)
Returns the number of ratings for the corresponding user. |
int |
getNumTopNRecords()
Accessor, return num of recommendations cached |
int |
getNumUsers()
|
int |
getNumUsersCached()
|
float |
getRatingCached(int userID,
int itemID)
Get rating from the cache. |
java.lang.String |
getRatingDatabaseName()
Accessor, return ratingTableName |
java.util.Iterator |
getRatingList(java.lang.String whereClause)
Get an iterator through a list of all ItemRatings in the given table, ordered by UserID. |
int |
getSizeOfTypedItemList(int typeID)
Get size of specific typed Item List. |
java.lang.String |
getStatistics()
|
ItemPrediction[] |
getTopNByType(int userID,
int number,
int offset,
int type,
ItemPrediction[] pred)
Returns a user's typed top N recommendations, No caching |
java.util.LinkedList |
getTypedItemIDList(int typeID)
Get the whole list of ItemID of specific type |
UserInfo |
getUser(int userID)
Accessor, return UserInfo |
UserInfo |
getUserInfo(int userID)
Return a UserInfo object to methods that need to perfrom multiple computations on a single user |
java.lang.String |
getUserInfoTableName()
Accessor, return userInfo table's name |
java.util.Iterator |
getUserList(java.lang.String tableName)
Get an iterator through a list of all userIDs in the given table, ordered by UserID. |
ItemRating[] |
getUserRatingList(int userID)
Return an array of itemIDs which the given user has rated. |
float |
getUserSD(int userID)
Returns the standard deviation of the user's ratings from the cache. |
java.util.LinkedList |
givenNHide(int userID,
int NumParam,
int option)
|
void |
hideRatingFromRecords(int user,
int item)
Hiding the rating value for the item we are trying to predict for, re-compute the user SD and user average rating. |
void |
incCachedUsers()
|
void |
incCacheHits()
|
void |
incCacheMisses()
|
void |
incNumItems()
|
void |
incNumUsers()
|
void |
initializeData()
This method initializes the data structures for caching with the sizes of the max user and item ID. |
static void |
insertionSort(int[] a,
float[] b)
Simple insertion sort. |
UserInfo |
loadUser(int userID,
boolean sampled)
Cache new user. |
void |
printAllTables()
Method to print contents of all tables. |
void |
printRatingTable()
Print ratingTable |
void |
refreshCache()
Remove useless data from the cache. |
void |
removeCachedRating(ItemRating rating)
Remove rating from the cache. |
void |
removeCachedRatingGroup(java.util.Iterator iter)
|
void |
removeRating(int userID,
int itemID)
Remove rating from our cache. |
void |
resetUserCounter(int userID)
Reset a user's counter of added ratings. |
void |
sampleUsers()
Function called by the Resample Thread, at regular intervals of time. |
void |
setMaxItems(int itemID)
|
void |
setMaxUsers(int userID)
|
void |
setNumItems(int numItems)
|
void |
setNumUsers(int numUsers)
|
void |
setNumUsersCached(int numUsersCached)
|
void |
shutdown()
|
java.util.LinkedList |
sparcifyData(java.util.Iterator iter,
int NumParam,
int option)
|
void |
updateStats(int userID)
Recalculate mean and standard deviation for a given user. |
void |
userUnload(int userID)
Remove a user from the cache. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
java.util.LinkedList dbUsers
Constructor Detail |
public DataManager(boolean loadRatings, boolean doSampling)
loadRatings
- doSampling
- Method Detail |
public float getRatingCached(int userID, int itemID)
userID
- itemID
-
public ItemRating getItemRatingCached(int userID, int itemID) throws java.sql.SQLException
userID
- itemID
-
java.sql.SQLException
public void printAllTables()
public void printRatingTable()
public java.util.Iterator getNeighborhood(int itemID)
itemID
-
public ItemInfo getItemInfo(int itemID)
public java.util.Iterator getItemList(int userID)
userID
-
public ItemRating[] getItemRatingList(int itemID)
itemID
-
public ItemRating[] getUserRatingList(int userID)
userID
-
public java.util.Iterator getAllUsers()
public float getMeanRatingCached(int userID)
userID
-
public float getMeanItemRatingCached(int itemID)
itemID
-
public void updateStats(int userID)
userID
- public float getUserSD(int userID)
userID
-
public float getItemSD(int itemID)
itemID
-
public static void insertionSort(int[] a, float[] b)
a
- an array of int items - the sort key.b
- an array of parallel ratings of the same length as apublic void sampleUsers()
public java.util.Iterator getRatingList(java.lang.String whereClause) throws java.sql.SQLException
whereClause
-
java.sql.SQLException
public void cacheTypedItemList() throws java.sql.SQLException
java.sql.SQLException
public java.util.LinkedList getTypedItemIDList(int typeID) throws java.sql.SQLException
typeID
-
java.sql.SQLException
public java.util.Iterator getCachedTypedItemLists(int typeID)
typeID
-
public java.util.Vector getCachedTypedItemList(int typeID)
typeID
-
public int getSizeOfTypedItemList(int typeID)
typeID
-
public java.lang.String getItemTypeInfoDatabaseName()
public UserInfo getUser(int userID)
public java.util.Iterator getUserList(java.lang.String tableName) throws java.sql.SQLException
tableName
-
java.sql.SQLException
public void initializeData() throws java.sql.SQLException
java.sql.SQLException
public float getCoverage() throws java.sql.SQLException, CFInternalErrorException
java.sql.SQLException
CFInternalErrorException
public java.lang.String getRatingDatabaseName()
public float getMinRating()
public float getMaxRating()
public float getErrRating()
public int getMaxUser()
public int getMaxItem()
public int getMaxType()
public java.lang.String getUserInfoTableName()
public int getNumTopNRecords()
public void hideRatingFromRecords(int user, int item)
user
- item
- public int getNumRatings(int userID)
userID
-
public int getNumRaters(int itemID)
itemID
-
public UserInfo loadUser(int userID, boolean sampled) throws java.sql.SQLException
userID
-
java.sql.SQLException
public void userUnload(int userID)
userID
- public void checkCachedUser(int userID) throws java.sql.SQLException
userID
-
java.sql.SQLException
public void addRating(ItemRating rating) throws java.sql.SQLException
rating
- - an ItemRating
java.sql.SQLException
public void addCachedRating(ItemRating rating)
rating
- - an ItemRatingpublic void removeRating(int userID, int itemID) throws java.sql.SQLException
userID
- itemID
-
java.sql.SQLException
public void removeCachedRating(ItemRating rating)
public void refreshCache()
public boolean checkCachedTopN(int userID)
userID
-
public void cacheUserTopN(int userID, ItemPrediction[] predictions)
predictions
- public ItemPrediction[] getCachedTopN(int userID, int number, int offset)
public ItemPrediction[] getTopNByType(int userID, int number, int offset, int type, ItemPrediction[] pred)
public void resetUserCounter(int userID)
userID
- public int getAddedRatings(int userID)
userID
- public void incNumItems()
public void decNumItems()
public void incNumUsers()
public void decNumUsers()
public void incCachedUsers()
public void decCachedUsers()
public void setMaxUsers(int userID)
public void setMaxItems(int itemID)
public void shutdown()
public void cacheRatingGroup(java.util.Iterator iter)
public void removeCachedRatingGroup(java.util.Iterator iter)
public java.util.LinkedList sparcifyData(java.util.Iterator iter, int NumParam, int option)
public java.util.LinkedList givenNHide(int userID, int NumParam, int option)
public UserInfo getUserInfo(int userID)
userID
-
public int getNextItemId() throws java.sql.SQLException, CFInternalErrorException
java.sql.SQLException
CFInternalErrorException
public int getNextUserId() throws java.sql.SQLException, CFInternalErrorException
java.sql.SQLException
CFInternalErrorException
public java.lang.String getStatistics()
public int getNumItems()
public void setNumItems(int numItems)
public int getNumUsersCached()
public void setNumUsersCached(int numUsersCached)
public int getNumUsers()
public void setNumUsers(int numUsers)
public void incCacheHits()
public void incCacheMisses()
public void decUseCount(int userID)
userID
-
|
CFEngine API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |