@@ -21,20 +21,32 @@ fn main() -> Result<(), Box<dyn Error>> {
2121 client. execute ( "CREATE EXTENSION IF NOT EXISTS vector" , & [ ] ) ?;
2222 client. execute ( "DROP TABLE IF EXISTS users" , & [ ] ) ?;
2323 client. execute ( "DROP TABLE IF EXISTS movies" , & [ ] ) ?;
24- client. execute ( "CREATE TABLE users (id integer PRIMARY KEY, factors vector(20))" , & [ ] ) ?;
25- client. execute ( "CREATE TABLE movies (name text PRIMARY KEY, factors vector(20))" , & [ ] ) ?;
24+ client. execute (
25+ "CREATE TABLE users (id integer PRIMARY KEY, factors vector(20))" ,
26+ & [ ] ,
27+ ) ?;
28+ client. execute (
29+ "CREATE TABLE movies (name text PRIMARY KEY, factors vector(20))" ,
30+ & [ ] ,
31+ ) ?;
2632
2733 let data = load_movielens ( Path :: new ( & movielens_path) ) ;
2834 let recommender = RecommenderBuilder :: new ( ) . factors ( 20 ) . fit_explicit ( & data) ;
2935
3036 for user_id in recommender. user_ids ( ) {
3137 let factors = Vector :: from ( recommender. user_factors ( user_id) . unwrap ( ) . to_vec ( ) ) ;
32- client. execute ( "INSERT INTO users (id, factors) VALUES ($1, $2)" , & [ & user_id, & factors] ) ?;
38+ client. execute (
39+ "INSERT INTO users (id, factors) VALUES ($1, $2)" ,
40+ & [ & user_id, & factors] ,
41+ ) ?;
3342 }
3443
3544 for item_id in recommender. item_ids ( ) {
3645 let factors = Vector :: from ( recommender. item_factors ( item_id) . unwrap ( ) . to_vec ( ) ) ;
37- client. execute ( "INSERT INTO movies (name, factors) VALUES ($1, $2)" , & [ & item_id, & factors] ) ?;
46+ client. execute (
47+ "INSERT INTO movies (name, factors) VALUES ($1, $2)" ,
48+ & [ & item_id, & factors] ,
49+ ) ?;
3850 }
3951
4052 let movie = "Star Wars (1977)" ;
0 commit comments