pub struct EntityExtractor { /* private fields */ }Expand description
Pattern-based entity extractor.
Uses regular expressions and heuristics to extract common entities.
§Examples
use aprender::text::entities::EntityExtractor;
let extractor = EntityExtractor::new();
let text = "Email me at test@example.com or call 555-123-4567";
let entities = extractor.extract(text).unwrap();
assert_eq!(entities.emails.len(), 1);
assert_eq!(entities.phone_numbers.len(), 1);Implementations§
Source§impl EntityExtractor
impl EntityExtractor
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new entity extractor.
§Examples
use aprender::text::entities::EntityExtractor;
let extractor = EntityExtractor::new();Sourcepub fn with_named_entities(self, enable: bool) -> Self
pub fn with_named_entities(self, enable: bool) -> Self
Set whether to extract named entities.
§Examples
use aprender::text::entities::EntityExtractor;
let extractor = EntityExtractor::new().with_named_entities(false);Sourcepub fn extract(&self, text: &str) -> Result<Entities, AprenderError>
pub fn extract(&self, text: &str) -> Result<Entities, AprenderError>
Extract all entities from text.
§Arguments
text- Input text to process
§Examples
use aprender::text::entities::EntityExtractor;
let extractor = EntityExtractor::new();
let text = "Visit https://example.com or email info@example.com";
let entities = extractor.extract(text).unwrap();
assert!(!entities.urls.is_empty());
assert!(!entities.emails.is_empty());Trait Implementations§
Source§impl Debug for EntityExtractor
impl Debug for EntityExtractor
Auto Trait Implementations§
impl Freeze for EntityExtractor
impl RefUnwindSafe for EntityExtractor
impl Send for EntityExtractor
impl Sync for EntityExtractor
impl Unpin for EntityExtractor
impl UnwindSafe for EntityExtractor
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more