//! CLI: stem words from stdin, one per line. Also the differential-test driver.
//!
//! `argv[1]` selects the mode: `nltk` (default), `martin`, or `original`.

use std::io::{self, BufRead, Write};

use nltk_porter::{Mode, PorterStemmer};

fn main() -> io::Result<()> {
    let mode = match std::env::args().nth(1).as_deref() {
        Some("martin") => Mode::Martin,
        Some("original") => Mode::Original,
        _ => Mode::Nltk,
    };
    let stemmer = PorterStemmer::new(mode);

    let stdin = io::stdin();
    let mut out = io::BufWriter::new(io::stdout().lock());
    for line in stdin.lock().lines() {
        let line = line?;
        writeln!(out, "{}", stemmer.stem(line.trim_end_matches('\r')))?;
    }
    Ok(())
}
