use core::panic; use reco_forge::{create_model, pass_item, Data, Tensor, HashMap}; fn main() -> Result<(), Box> { println!("This is an example of how you can find similar items to another item in a dataset. You must input an item in the dataset for this example to work so check the github repositoy (https://github.com/jameslk3/reco-forge) to find the dataset used (sample-json/movies/movies_clean_10.json)."); println!("Either input a path to your JSON file or press enter to use the default dataset (small dataset on movies)."); println!("Creating the model may take a while, please be patient."); println!(); let model_wrapped: Result>, ()>; let mut path = String::new(); println!("Please enter the file path:"); std::io::stdin().read_line(&mut path).expect("Failed to read line"); loop { path = path.trim().to_string(); if path.is_empty() { println!("No file path entered, using default dataset (movies)."); path = "sample-json/movies/movies_clean_10.json".to_string(); if let Ok(model) = create_model(&path) { model_wrapped = Ok(model); break; } else { panic!("File path is not valid or file cannot be deserialized, please input the correct file path and try again:"); } } if let Ok(model) = create_model(&path) { model_wrapped = Ok(model); break; } else { println!("File path is not valid or file cannot be deserialized, please input the correct file path and try again:"); path.clear(); std::io::stdin().read_line(&mut path).expect("Failed to read line"); } } let model: HashMap> = model_wrapped.unwrap(); println!("Input tags that you would like to use to filter, else enter NONE"); let mut tags_input: String = String::new(); std::io::stdin().read_line(&mut tags_input).expect("Failed to read line"); tags_input = tags_input.trim().to_string(); println!("Find something similar to... (input an item in the dataset)"); let mut query: String = String::new(); std::io::stdin().read_line(&mut query).expect("Failed to read line"); query = query.trim().to_string(); println!(); let recommendations = pass_item(&model, query, tags_input, 10); match recommendations { Ok(recommendations) => { println!("Recommendations:"); for recommendation in recommendations { println!("{}% {}", (recommendation.1 * 100.0).round(), recommendation.0); } }, Err(_) => println!("No recommendations found, either an error occurred or the item you inputted is not in the dataset. Please try again."), } Ok(()) }