org.grouplens.lenskit.data.event

## Class Ratings

• public final class Ratings
extends Object
Utilities for working with ratings.
• ### Field Summary

Fields
Modifier and Type Field and Description
static Ordering<Rating> ITEM_TIME_COMPARATOR
• ### Constructor Summary

Constructors
Constructor and Description
Ratings()
• ### Method Summary

All Methods
Modifier and Type Method and Description
static RatingBuilder copyBuilder(Rating r)
Construct a rating builder initialized with the values of a rating.
static boolean equals(Rating r1, Rating r2)
Compare two ratings for equality.
static int hashRating(Rating rating)
Compute the hash code of a rating.
static MutableSparseVector itemRatingVector(Collection<? extends Rating> ratings)
Construct a rating vector that contains the ratings provided by each user.
static Rating make(long uid, long iid, double value)
Make a fresh rating object with no timestamp.
static Rating make(long uid, long iid, double value, long ts)
Make a fresh rating event.
static RatingBuilder newBuilder()
static MutableSparseVector userRatingVector(Collection<? extends Rating> ratings)
Construct a rating vector that contains the ratings provided for each item.
static MutableSparseVector userRatingVector(Cursor<? extends Rating> ratings)
Extract a user rating vector from a rating cursor.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Field Detail

• #### ITEM_TIME_COMPARATOR

public static final Ordering<Rating> ITEM_TIME_COMPARATOR
• ### Constructor Detail

• #### Ratings

public Ratings()
• ### Method Detail

• #### itemRatingVector

public static MutableSparseVector itemRatingVector(@Nonnull
Collection<? extends Rating> ratings)
Construct a rating vector that contains the ratings provided by each user. If all ratings in ratings are for the same item, then this will be a valid item rating vector. If multiple ratings are by the same user, the one with the highest timestamp is retained. If two ratings by the same user have identical timestamps, then the one that occurs last when the collection is iterated is retained.
Parameters:
ratings - Some ratings (they should all be for the same item)
Returns:
A sparse vector mapping user IDs to ratings.
• #### userRatingVector

public static MutableSparseVector userRatingVector(@Nonnull
Collection<? extends Rating> ratings)
Construct a rating vector that contains the ratings provided for each item. If all ratings in ratings are by the same user, then this will be a valid user rating vector. If multiple ratings are provided for the same item, the one with the greatest timestamp is retained. Ties are broken by preferring ratings which come later when iterating through the collection.
Parameters:
ratings - A collection of ratings (should all be by the same user)
Returns:
A sparse vector mapping item IDs to ratings
• #### userRatingVector

public static MutableSparseVector userRatingVector(@WillClose
Cursor<? extends Rating> ratings)
Extract a user rating vector from a rating cursor.
Parameters:
ratings - The rating cursor.
Returns:
The user rating vector.
userRatingVector(Collection)
• #### make

public static Rating make(long uid,
long iid,
double value,
long ts)
Make a fresh rating event. Event IDs are generated sequentially. This is mostly useful in test cases.
• #### newBuilder

public static RatingBuilder newBuilder()
Returns:
A new rating builder.
Since:
1.3
• #### copyBuilder

public static RatingBuilder copyBuilder(@Nonnull
Rating r)
Construct a rating builder initialized with the values of a rating.
Parameters:
r - The rating.
Returns:
A rating builder that will initially build a copy of r.
Since:
1.e
• #### hashRating

public static int hashRating(Rating rating)
Compute the hash code of a rating. Used to implement Object.hashCode() in rating implementations.
Parameters:
rating - The rating.
Returns:
The rating's hash code.
• #### equals

public static boolean equals(Rating r1,
Rating r2)
Compare two ratings for equality. Used to implement Object.equals(Object) in rating implementations.
Parameters:
r1 - The first rating.
r2 - The second rating.
Returns:
Whether the two ratings are equal.