john-slop/examples/analyze_text.rs

31 lines
924 B
Rust

//! Analyze an in-memory document with the embedded heuristic catalog.
use std::error::Error;
use john_slop::{AnalysisContext, Config, Detector};
fn main() -> Result<(), Box<dyn Error>> {
let source = "As an AI language model, I can help—but this draft needs review.";
let detector = Detector::new(&Config::embedded())?;
let analysis = detector.analyze_with(source, &AnalysisContext::for_path("article.md"));
let summary = analysis.summary();
println!(
"confidence={} band={} findings={}",
summary.confidence_score,
summary
.confidence_band
.map_or("none", john_slop::ConfidenceBand::as_str),
summary.findings.total()
);
for finding in analysis.findings {
println!(
"{} {}..{} {:?}",
finding.rule_id, finding.byte_span.start, finding.byte_span.end, finding.matched_text
);
}
Ok(())
}