use crate::{
common::{Documents, Punctuation, Stopwords, Text},
tokenizer::Tokenizer,
};
use super::document_processor::DocumentProcessor;
pub enum TextSplit {
Sentences,
Paragraphs,
Phrases,
}
pub enum TfIdfParams<'a> {
UnprocessedDocuments(Documents<'a>, Stopwords<'a>, Punctuation<'a>),
ProcessedDocuments(Documents<'a>),
TextBlock(Text<'a>, Stopwords<'a>, Punctuation<'a>, TextSplit),
}
impl<'a> TfIdfParams<'a> {
pub fn get_documents(&self) -> Vec<String> {
match self {
TfIdfParams::UnprocessedDocuments(documents, stopwords, punctuatuion) => {
DocumentProcessor::new(documents, stopwords, punctuatuion).process_documents()
}
TfIdfParams::ProcessedDocuments(documents) => documents.to_vec(),
TfIdfParams::TextBlock(text, stop_words, punctuation, split) => {
let tokenizer = Tokenizer::new(text, stop_words, *punctuation);
match split {
TextSplit::Sentences => tokenizer.split_into_sentences(),
TextSplit::Paragraphs => tokenizer.split_into_paragraphs(),
TextSplit::Phrases => tokenizer.split_into_phrases(None),
}
}
}
}
}