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).expect("extract should succeed");
assert_eq!(entities.emails.len(), 1);
assert_eq!(entities.phone_numbers.len(), 1);Implementations§
Source§impl EntityExtractor
impl EntityExtractor
Sourcepub fn new() -> EntityExtractor
pub fn new() -> EntityExtractor
Create a new entity extractor.
§Examples
use aprender::text::entities::EntityExtractor;
let extractor = EntityExtractor::new();Sourcepub fn with_named_entities(self, enable: bool) -> EntityExtractor
pub fn with_named_entities(self, enable: bool) -> EntityExtractor
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).expect("extract should succeed");
assert!(!entities.urls.is_empty());
assert!(!entities.emails.is_empty());Trait Implementations§
Source§impl Debug for EntityExtractor
impl Debug for EntityExtractor
Source§impl Default for EntityExtractor
impl Default for EntityExtractor
Source§fn default() -> EntityExtractor
fn default() -> EntityExtractor
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for EntityExtractor
impl RefUnwindSafe for EntityExtractor
impl Send for EntityExtractor
impl Sync for EntityExtractor
impl Unpin for EntityExtractor
impl UnsafeUnpin for EntityExtractor
impl UnwindSafe for EntityExtractor
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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