org.lenskit.data.ratings

Class Ratings

• java.lang.Object
• org.lenskit.data.ratings.Ratings

• public final class Ratings
extends java.lang.Object

Utilities for working with ratings.

• Field Summary

Fields
Modifier and Type Field and Description
static java.util.Comparator<Rating> TIMESTAMP_COMPARATOR
Compare two events by timestamp.
• Method Summary

All Methods
Modifier and Type Method and Description
static Long2DoubleMap itemRatingVector(java.util.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)
Deprecated.
static Rating make(long uid, long iid, double value, long ts)
Deprecated.
static Equivalence<Preference> preferenceEquivalence()
An equivalence relation over preferences.
static Long2DoubleMap userRatingVector(java.util.Collection<Rating> ratings)
Construct a rating vector that contains the ratings provided for each item.
static Long2DoubleMap userRatingVector(ObjectStream<? extends Rating> ratings)
Extract a user rating vector from a rating stream.
• Methods inherited from class java.lang.Object

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

• TIMESTAMP_COMPARATOR

public static final java.util.Comparator<Rating> TIMESTAMP_COMPARATOR

Compare two events by timestamp.

• Method Detail

• itemRatingVector

public static Long2DoubleMap itemRatingVector(@Nonnull
java.util.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 Long2DoubleMap userRatingVector(@Nonnull
java.util.Collection<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.

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 Long2DoubleMap userRatingVector(@WillClose
ObjectStream<? extends Rating> ratings)

Extract a user rating vector from a rating stream.

Parameters:
ratings - The rating stream.
Returns:
The user rating vector.
userRatingVector(Collection)
• preferenceEquivalence

public static Equivalence<Preference> preferenceEquivalence()

An equivalence relation over preferences.

Returns:
An equivalence relation over preferences where two preferences are equivalent if they have the same user, item, and value.
• make

@Deprecated
public static Rating make(long uid,
long iid,
double value)
Deprecated.

Make a fresh rating object with no timestamp.

make(long, long, double, long)
@Deprecated
long ts)