org.lenskit.data.ratings

## Class Ratings

• public final class Ratings
extends Object

Utilities for working with ratings.

• ### Method Summary

All Methods
Modifier and Type Method and Description
static Long2DoubleMap 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)
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(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.
static Function<UserHistory<? extends Event>,Long2DoubleMap> userRatingVectorFunction()
Obtain a function that converts a user history to a rating vector.
• ### Methods inherited from class java.lang.Object

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

• #### itemRatingVector

public static Long2DoubleMap 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 Long2DoubleMap userRatingVector(@Nonnull
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. 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
• #### userRatingVectorFunction

public static Function<UserHistory<? extends Event>,Long2DoubleMap> userRatingVectorFunction()

Obtain a function that converts a user history to a rating vector.

Returns:
A function converting a user history to a rating vector.
• #### 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)