The TextData struct is the core component for license matching. It handles text normalization, n-gram generation, and scoring. It can be used to calculate similarity scores between two texts or to locate the specific line range where a license exists within a larger body of text.
Basic Scoring
Use match_score to get a similarity value (0.0 to 1.0) between two TextData instances. Pre-processing automatically strips out identifiable copyright statements to improve matching accuracy.
use askalono::TextData;
let license = TextData::from("My First License");
let sample = TextData::from("copyright 20xx me irl\n\n // my first license");
assert_eq!(sample.match_score(&license), 1.0);
Locating License Bounds
If you have a high match score but need to know exactly where the license is located in a file, use optimize_bounds. This returns a new TextData instance with a restricted lines_view and the calculated score.
# use std::error::Error;
# use askalono::TextData;
# fn main() -> Result<(), Box<dyn Error>> {
let license = TextData::from("My First License");
let sample = TextData::from("copyright 20xx me irl\n// My First License\nfn hello() {\n ...");
let (optimized, score) = sample.optimize_bounds(&license);
// Check the line range (start, end) where the match was found
assert_eq!((1, 2), optimized.lines_view());
assert!(score > 0.99f32);
# Ok(())
# }
use askalono::TextData;
let license = TextData::from("My First License");
let sample = TextData::from("copyright 20xx me irl\n\n // my first license");
assert_eq!(sample.match_score(&license), 1.0);