bookdata/interactions/mod.rs
1//! Manage and deduplicate ratings and interactions.
2//!
3//! This code consolidates rating de-duplication into a single place, so we can use the same
4//! logic across data sets. We always store timestamps, dropping them at output time, because
5//! the largest data sets have timestamps. Saving space for the smallest data set doesn't
6//! seem worthwhile.
7use anyhow::Result;
8use std::path::Path;
9
10mod actions;
11mod ratings;
12
13/// Trait for an interaction.
14pub trait Interaction {
15 fn get_user(&self) -> i32;
16 fn get_item(&self) -> i32;
17 fn get_rating(&self) -> Option<f32>;
18 fn get_timestamp(&self) -> i64;
19}
20
21/// Interface for de-duplicating interactions.
22pub trait Dedup<I: Interaction> {
23 /// Save an item in the deduplciator.
24 fn add_interaction(&mut self, act: I) -> Result<()>;
25
26 /// Write the de-duplicated reuslts to a file.
27 fn save(&mut self, path: &Path) -> Result<usize>;
28}
29
30#[derive(Debug, Hash, Eq, PartialEq)]
31struct Key {
32 user: i32,
33 item: i32,
34}
35
36impl Key {
37 fn new(user: i32, item: i32) -> Key {
38 Key { user, item }
39 }
40}