Struct lemmeknow::identifier::Identifier
source · pub struct Identifier {
pub min_rarity: f32,
pub max_rarity: f32,
pub tags: Vec<String>,
pub exclude_tags: Vec<String>,
pub boundaryless: bool,
pub file_support: bool,
}
Fields§
§min_rarity: f32
Keep Data having minimum Rarity of supplied min_rarity
max_rarity: f32
Keep Data having maximum Rarity of supplied max_rarity
Only include the Data which have at least one of the specified tags
Only include Data which doesn’t have any of the excluded_tags
boundaryless: bool
Use boundaryless regex
file_support: bool
Scan files having supplied text as filename
Implementations§
source§impl Identifier
impl Identifier
pub fn min_rarity(self, rarity: f32) -> Self
pub fn max_rarity(self, rarity: f32) -> Self
pub fn boundaryless(self, boundaryless: bool) -> Self
pub fn file_support(self, support: bool) -> Self
source§impl Identifier
impl Identifier
sourcepub fn identify(&self, text: &str) -> Vec<Match>
pub fn identify(&self, text: &str) -> Vec<Match>
Identify the given text.
This will read strings from file with text as filename if file_support
is true
and the file exists
Finds all possible identifications.
Arguments
- text: &str - text which we want to identify
Examples
let identifier = lemmeknow::Identifier::default();
let result = identifier.identify("UC11L3JDgDQMyH8iolKkVZ4w");
assert_eq!(result[0].data.name, "YouTube Channel ID");
sourcepub fn first_match(&self, text: &str) -> Option<Match>
pub fn first_match(&self, text: &str) -> Option<Match>
This returns the first identification.
Due to how data is stored, this means that the returned result has the highest rarity
.
Arguments
- text: &str - text which we want to identify
Examples
let identifier = lemmeknow::Identifier::default();
let some_result = identifier.first_match("8888888888");
let not_gonna_find = identifier.first_match("a friend for swanandx");
assert_eq!(some_result.unwrap().data.name, "Phone Number");
assert!(not_gonna_find.is_none());
source§impl Identifier
impl Identifier
sourcepub fn to_json(result: &[Match]) -> String
pub fn to_json(result: &[Match]) -> String
Convert Vec<Match>
to JSON
Returns prettified JSON string.
Helpful if you want to convert possible identifications to JSON for using in web APIs or something else.
Arguments
- result: &Match - Reference to
Vec<Match>
.
Examples
use lemmeknow::Identifier;
let identifier = Identifier::default();
let result = identifier.identify("UC11L3JDgDQMyH8iolKkVZ4w");
let result_in_json = Identifier::to_json(&result);
println!("{result_in_json}");
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Identifier
impl Send for Identifier
impl Sync for Identifier
impl Unpin for Identifier
impl UnwindSafe for Identifier
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more