@ThreadSafe @DefaultProvider(value=BinaryRatingDAO.Loader.class) public class BinaryRatingDAO extends Object implements EventDAO, UserEventDAO, ItemEventDAO, UserDAO, ItemDAO, Serializable, Describable
DAO implementation using binary-packed data. This DAO reads ratings from a compact binary format using memory-mapped IO, so the data is efficiently readable (subject to available memory and operating system caching logic) without expanding the Java heap.
To create a file compatible with this DAO, use the BinaryRatingPacker
class or the pack command in the LensKit command line tool.
Currently, serializing a binary rating DAO puts all the rating data into the serialized output stream. When deserialized, the data be written back to a direct buffer (allocated with ByteBuffer.allocateDirect(int)
). When deserializing this DAO, make sure your system has enough virtual memory (beyond what is allowed for Java) to contain the entire data set.
Modifier and Type | Class and Description |
---|---|
static class |
BinaryRatingDAO.Loader |
Modifier and Type | Method and Description |
---|---|
BinaryRatingDAO |
createWindowedView(long timestamp) |
void |
describeTo(DescriptionWriter writer)
Write this class’s description to a sink.
|
List<Event> |
getEventsForItem(long item)
Get the events for a specific item.
|
<E extends Event> |
getEventsForItem(long item,
Class<E> type)
Get the events for a specific item, filtering by type.
|
UserHistory<Event> |
getEventsForUser(long user)
Get the events for a specific user.
|
<E extends Event> |
getEventsForUser(long user,
Class<E> type)
Get the events for a specific user, filtering by type.
|
LongSet |
getItemIds()
Get all known item IDs.
|
Long |
getLimitTimestamp() |
LongSet |
getUserIds()
Get all known user IDs.
|
LongSet |
getUsersForItem(long item)
Get the users who have interacted with an item.
|
static BinaryRatingDAO |
open(File file)
Open a binary rating DAO.
|
ObjectStream<Event> |
streamEvents()
Stream all events.
|
<E extends Event> |
streamEvents(Class<E> type)
Stream all events of a given type.
|
<E extends Event> |
streamEvents(Class<E> type,
SortOrder order)
Stream all events of a given type in a specified order.
|
ObjectStream<ItemEventCollection<Event>> |
streamEventsByItem()
Stream events grouped by item.
|
<E extends Event> |
streamEventsByItem(Class<E> type)
Stream events grouped by item.
|
ObjectStream<UserHistory<Event>> |
streamEventsByUser()
Stream events grouped by user.
|
<E extends Event> |
streamEventsByUser(Class<E> type)
Stream events grouped by user.
|
public static BinaryRatingDAO open(File file) throws IOException
Open a binary rating DAO.
file
- The file to open.file
.IOException
- If there ispublic BinaryRatingDAO createWindowedView(long timestamp)
public Long getLimitTimestamp()
public ObjectStream<Event> streamEvents()
EventDAO
Stream all events.
streamEvents
in interface EventDAO
public <E extends Event> ObjectStream<E> streamEvents(Class<E> type)
EventDAO
Stream all events of a given type.
streamEvents
in interface EventDAO
type
- The event type.public <E extends Event> ObjectStream<E> streamEvents(Class<E> type, SortOrder order)
EventDAO
Stream all events of a given type in a specified order.
streamEvents
in interface EventDAO
type
- The event type.order
- The order.public LongSet getItemIds()
ItemDAO
Get all known item IDs.
getItemIds
in interface ItemDAO
public ObjectStream<ItemEventCollection<Event>> streamEventsByItem()
ItemEventDAO
Stream events grouped by item.
streamEventsByItem
in interface ItemEventDAO
public <E extends Event> ObjectStream<ItemEventCollection<E>> streamEventsByItem(Class<E> type)
ItemEventDAO
Stream events grouped by item.
streamEventsByItem
in interface ItemEventDAO
type
- The type of item to look for.type
from all items. If an item exists but does not have any events, it may or may not be included depending on the DAO implementation.public List<Event> getEventsForItem(long item)
ItemEventDAO
Get the events for a specific item.
getEventsForItem
in interface ItemEventDAO
item
- The item ID.null
if the item is unknown.@Nullable public <E extends Event> List<E> getEventsForItem(long item, Class<E> type)
ItemEventDAO
Get the events for a specific item, filtering by type.
getEventsForItem
in interface ItemEventDAO
item
- The item ID.type
- The type of events to retrieve.null
if the item is unknown.@Nullable public LongSet getUsersForItem(long item)
ItemEventDAO
Get the users who have interacted with an item.
getUsersForItem
in interface ItemEventDAO
item
- The item ID.null
if the item is unknown.public LongSet getUserIds()
UserDAO
Get all known user IDs.
getUserIds
in interface UserDAO
public ObjectStream<UserHistory<Event>> streamEventsByUser()
UserEventDAO
Stream events grouped by user.
streamEventsByUser
in interface UserEventDAO
public <E extends Event> ObjectStream<UserHistory<E>> streamEventsByUser(Class<E> type)
UserEventDAO
Stream events grouped by user.
streamEventsByUser
in interface UserEventDAO
type
- The type of item to look for.type
. If a user exists, but does not have any history, they may or may not be included depending on the DAO implementation.@Nullable public UserHistory<Event> getEventsForUser(long user)
UserEventDAO
Get the events for a specific user.
getEventsForUser
in interface UserEventDAO
user
- The user ID.null
if the user is unknown.@Nullable public <E extends Event> UserHistory<E> getEventsForUser(long user, Class<E> type)
UserEventDAO
Get the events for a specific user, filtering by type.
getEventsForUser
in interface UserEventDAO
user
- The user ID.type
- The type of events to retrieve.null
if the user is unknown.public void describeTo(DescriptionWriter writer)
Describable
Write this class’s description to a sink. Anything relevant to this object’s identity should be digested; the idea is that, barring hash collisions, two objects with the same digest are equivalent. Used for things like deterministically generating cache file names.
describeTo
in interface Describable
writer
- The description writer to use.