use std::collections::HashMap;
mod document_processor;
mod tf_idf_logic;
pub mod tf_idf_params;
use tf_idf_logic::TfIdfLogic;
pub use tf_idf_params::{TextSplit, TfIdfParams};
use crate::common::{get_ranked_scores, get_ranked_strings};
pub struct TfIdf(HashMap<String, f32>);
impl TfIdf {
pub fn new(params: TfIdfParams) -> Self {
let documents = params.get_documents();
Self(TfIdfLogic::build_tfidf(&documents))
}
pub fn get_score(&self, word: &str) -> f32 {
*self.0.get(word).unwrap_or(&0.0)
}
pub fn get_ranked_words(&self, n: usize) -> Vec<String> {
get_ranked_strings(&self.0, n)
}
pub fn get_ranked_word_scores(&self, n: usize) -> Vec<(String, f32)> {
get_ranked_scores(&self.0, n)
}
pub fn get_word_scores_map(&self) -> &HashMap<String, f32> {
&self.0
}
}