org.mymedialite.data
Class Ratings

java.lang.Object
  extended by org.mymedialite.data.DataSet
      extended by org.mymedialite.data.Ratings
All Implemented Interfaces:
IDataSet, IRatings
Direct Known Subclasses:
CombinedRatings, RatingsProxy, StaticRatings, TimedRatings

public class Ratings
extends DataSet
implements IRatings

Data structure for storing ratings Small memory overhead for added flexibility. This data structure supports incremental updates.


Field Summary
protected  double maxRating
           
protected  double minRating
           
protected  DoubleList values
           
 
Fields inherited from class org.mymedialite.data.DataSet
byItem, byUser, items, maxItemID, maxUserID, users
 
Constructor Summary
Ratings()
           
 
Method Summary
 void add(int user_id, int item_id, byte rating)
          Add byte-valued rating to the collection.
 void add(int user_id, int item_id, double rating)
          Add a new rating.
 void add(int user_id, int item_id, float rating)
          Add float-valued rating to the collection.
 double average()
          Average rating in the dataset.
 void buildByItemCounts()
           
 void buildByUserCounts()
           
 IntList countByItem()
          Get the rating count by item.
 IntList countByUser()
          Get the rating count by user.
 double get(int index)
          Directly access ratings.
 double get(int user_id, int item_id)
          Directly access rating by user and item
 double get(int user_id, int item_id, IntCollection indexes)
          Directly access rating by user and item.
 boolean isReadOnly()
           
 double maxRating()
          Get the maximum rating in the dataset.
 double minRating()
          Get the minimum rating in the dataset.
 void removeAt(int index)
          Remove the rating at the specified index
 void removeItem(int item_id)
          Remove all events related to a given item.
 void removeUser(int user_id)
          Remove all events related to a given user.
 double set(int index, double rating)
          Directly access the ratings
 java.lang.Double tryGet(int user_id, int item_id)
          Try to retrieve a rating for a given user-item combination.
 java.lang.Double tryGet(int user_id, int item_id, IntCollection indexes)
          Try to retrieve a rating for a given user-item combination.
 java.lang.Integer tryGetIndex(int user_id, int item_id)
          Try to get the index for given user and item.
 DoubleList values()
           
 
Methods inherited from class org.mymedialite.data.DataSet
allItems, allUsers, buildItemIndices, buildRandomIndex, buildUserIndices, byItem, byUser, getIndex, getIndex, getItems, getUsers, items, maxItemID, maxUserID, randomIndex, size, tryGetIndex, users
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mymedialite.data.IRatings
size
 
Methods inherited from interface org.mymedialite.data.IDataSet
allItems, allUsers, buildItemIndices, buildRandomIndex, buildUserIndices, byItem, byUser, getIndex, getIndex, getItems, getUsers, items, maxItemID, maxUserID, randomIndex, tryGetIndex, users
 

Field Detail

values

protected DoubleList values

minRating

protected double minRating

maxRating

protected double maxRating
Constructor Detail

Ratings

public Ratings()
Method Detail

values

public DoubleList values()
Specified by:
values in interface IRatings

get

public double get(int index)
Description copied from interface: IRatings
Directly access ratings.

Specified by:
get in interface IRatings
Parameters:
index - the index of the rating
Returns:
the rating value

set

public double set(int index,
                  double rating)
Description copied from interface: IRatings
Directly access the ratings

Specified by:
set in interface IRatings
Parameters:
index - the rating index
rating - the rating value

minRating

public double minRating()
Description copied from interface: IRatings
Get the minimum rating in the dataset.

Specified by:
minRating in interface IRatings

maxRating

public double maxRating()
Description copied from interface: IRatings
Get the maximum rating in the dataset.

Specified by:
maxRating in interface IRatings

countByUser

public IntList countByUser()
Description copied from interface: IRatings
Get the rating count by user.

Specified by:
countByUser in interface IRatings

buildByUserCounts

public void buildByUserCounts()

countByItem

public IntList countByItem()
Description copied from interface: IRatings
Get the rating count by item.

Specified by:
countByItem in interface IRatings

buildByItemCounts

public void buildByItemCounts()

average

public double average()
Description copied from interface: IRatings
Average rating in the dataset.

Specified by:
average in interface IRatings

get

public double get(int user_id,
                  int item_id)
Description copied from interface: IRatings
Directly access rating by user and item

Specified by:
get in interface IRatings
Parameters:
user_id - the user ID
item_id - the item ID
Returns:
the rating value for the given user and item

tryGet

public java.lang.Double tryGet(int user_id,
                               int item_id)
Description copied from interface: IRatings
Try to retrieve a rating for a given user-item combination.

Specified by:
tryGet in interface IRatings
Parameters:
user_id - the user ID
item_id - the item ID
Returns:
the first rating encountered that matches the user ID and item ID, or null if none is found

get

public double get(int user_id,
                  int item_id,
                  IntCollection indexes)
Description copied from interface: IRatings
Directly access rating by user and item.

Specified by:
get in interface IRatings
Parameters:
user_id - the user ID
item_id - the item ID
indexes - the indexes to look at
Returns:
the first rating encountered that matches the user ID and item ID

tryGet

public java.lang.Double tryGet(int user_id,
                               int item_id,
                               IntCollection indexes)
Description copied from interface: IRatings
Try to retrieve a rating for a given user-item combination.

Specified by:
tryGet in interface IRatings
Parameters:
user_id - the user ID
item_id - the item ID
indexes - the indexes to look at
Returns:
the first rating encountered that matches the user ID and item ID, or null if none found

tryGetIndex

public java.lang.Integer tryGetIndex(int user_id,
                                     int item_id)
Description copied from interface: IDataSet
Try to get the index for given user and item.

Specified by:
tryGetIndex in interface IDataSet
Overrides:
tryGetIndex in class DataSet
Parameters:
user_id - the user ID
item_id - the item ID
Returns:
the index of the first event encountered that matches the user ID and item ID or null, if not found

add

public void add(int user_id,
                int item_id,
                float rating)
Description copied from interface: IRatings
Add float-valued rating to the collection.

Specified by:
add in interface IRatings
Parameters:
user_id - the user ID
item_id - the item ID
rating - the rating

add

public void add(int user_id,
                int item_id,
                byte rating)
Description copied from interface: IRatings
Add byte-valued rating to the collection.

Specified by:
add in interface IRatings
Parameters:
user_id - the user ID
item_id - the item ID
rating - the rating

add

public void add(int user_id,
                int item_id,
                double rating)
Description copied from interface: IRatings
Add a new rating.

Specified by:
add in interface IRatings
Parameters:
user_id - the user ID
item_id - the item ID
rating - the rating value

removeAt

public void removeAt(int index)
Description copied from interface: IRatings
Remove the rating at the specified index

Specified by:
removeAt in interface IRatings
Parameters:
index - the rating index

removeUser

public void removeUser(int user_id)
Description copied from interface: IDataSet
Remove all events related to a given user.

Specified by:
removeUser in interface IDataSet
Parameters:
user_id - the user ID

removeItem

public void removeItem(int item_id)
Description copied from interface: IDataSet
Remove all events related to a given item.

Specified by:
removeItem in interface IDataSet
Parameters:
item_id - the item ID

isReadOnly

public boolean isReadOnly()