ares/checkers/
lemmeknow_checker.rs

1use super::checker_type::{Check, Checker};
2use crate::checkers::checker_result::CheckResult;
3use lemmeknow::{Data, Identifier};
4
5/// The LemmeKnow Checker checks if the text matches a known Regex pattern.
6/// This is the struct for it.
7pub struct LemmeKnow;
8
9impl Check for Checker<LemmeKnow> {
10    fn new() -> Self {
11        Checker {
12            // TODO: Update fields with proper values
13            name: "LemmeKnow Checker",
14            description: "Uses LemmeKnow to check for regex matches",
15            link: "https://swanandx.github.io/lemmeknow-frontend/",
16            tags: vec!["lemmeknow", "regex"],
17            expected_runtime: 0.01,
18            popularity: 1.0,
19            lemmeknow_config: Identifier::default().min_rarity(0.1),
20            _phantom: std::marker::PhantomData,
21        }
22    }
23
24    fn check(&self, text: &str) -> CheckResult {
25        let lemmeknow_result = self.lemmeknow_config.identify(text);
26        let mut is_identified = false;
27        let mut description = "".to_string();
28        if !lemmeknow_result.is_empty() {
29            is_identified = true;
30            description = format_data_result(&lemmeknow_result[0].data)
31        }
32
33        CheckResult {
34            is_identified,
35            text: text.to_owned(),
36            checker_name: self.name,
37            checker_description: self.description,
38            // Returns a vector of matches
39            description,
40            link: self.link,
41        }
42    }
43}
44
45/// Formats the data result to a string
46/// This is used to display the result in the UI
47fn format_data_result(input: &Data) -> String {
48    input.name.to_string()
49}