@ThreadSafe @DefaultImplementation(value=PackedPreferenceSnapshot.class) public interface PreferenceSnapshot extends Closeable
The recommender build process often needs to take multiple passes over the rating data. In a
live system, the data provided by a EventDAO
may change
between iterations. Therefore, we introduce build contexts — snapshots of the
rating data at a particular point in time that can be iterated as many times as necessary to
build the recommender.
Implementers have a variety of options for implementing build contexts. They can be in-memory snapshots, database transactions, database clones, or even disk files. Recommender build code does assume, however, that multiple iterations is pretty fast. Therefore, implementations should avoid re-fetching the data over a network connection for each request.
An additional feature provided by build contexts is that of mapping the item and user IDs to consecutive, 0-based indices. The indices may differ from one build context to another.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the build context.
|
LongCollection |
getItemIds()
Get the set of item IDs in the snapshot.
|
FastCollection<IndexedPreference> |
getRatings()
Get the collection of ratings in the snapshot.
|
LongCollection |
getUserIds()
Get the set of user IDs in the snapshot.
|
FastCollection<IndexedPreference> |
getUserRatings(long userId)
Get the ratings for a particular user.
|
IdIndexMapping |
itemIndex()
Get the item ID index.
|
IdIndexMapping |
userIndex()
Get the user ID index.
|
SparseVector |
userRatingVector(long userId)
Get the current preferences of a particular user in SparseVector form.
|
LongCollection getUserIds()
LongCollection getItemIds()
IdIndexMapping userIndex()
IdIndexMapping itemIndex()
FastCollection<IndexedPreference> getRatings()
Modifying the returned indexed preferences will not modify the underlying snapshot.
FastCollection<IndexedPreference> getUserRatings(long userId)
Modifying the returned indexed preferences will not modify the underlying snapshot.
userId
- The user's ID.SparseVector userRatingVector(long userId)
userId
- The user's ID.void close()
Closeable.close()
to drop the exception that
can be thrown.
After the build context has been closed, all methods are allowed to fail. Objects returned from those methods, however, should continue to be valid.
close
in interface AutoCloseable
close
in interface Closeable