tktax-transaction-category 0.2.2

A Rust library for categorizing financial transactions using Porter stemming, CSV-driven classification, and advanced trait-based extensibility.
Documentation
// ---------------- [ File: tktax-transaction-category/src/stemmed_token.rs ]
crate::ix!();

#[derive(Clone,Debug,PartialEq,Eq,Hash)]
pub struct StemmedToken(String);

impl StemmedToken {
    pub fn as_str(&self) -> &str {
        &self.0
    }
}

impl FromStr for StemmedToken {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        // Strip punctuation ourselves:
        let cleaned: String = s.chars().filter(|c| c.is_alphanumeric()).collect();
        // Then stem the cleaned string:
        let stemmer = Stemmer::create(Algorithm::English);
        let stemmed = stemmer.stem(&cleaned).to_string();
        Ok(Self(stemmed))
    }
}