pub struct AnyModel { /* private fields */ }Expand description
A wrapper that turns an extractor closure into a Model.
AnyModel supports ZeroShotNER and
RelationCapable via closures (see with_zero_shot
and with_relations).
Implementations§
Source§impl AnyModel
impl AnyModel
Sourcepub fn new(
name: &'static str,
description: &'static str,
supported_types: Vec<EntityType>,
extractor: impl Fn(&str, Option<Language>) -> Result<Vec<Entity>, Error> + Send + Sync + 'static,
) -> AnyModel
pub fn new( name: &'static str, description: &'static str, supported_types: Vec<EntityType>, extractor: impl Fn(&str, Option<Language>) -> Result<Vec<Entity>, Error> + Send + Sync + 'static, ) -> AnyModel
Create a new AnyModel wrapper.
§Arguments
name- Model identifier (e.g., “my-ner”)description- Human-readable descriptionsupported_types- Entity types this model can extractextractor- Closure that performs the actual extraction
Sourcepub fn with_version(self, version: impl Into<String>) -> AnyModel
pub fn with_version(self, version: impl Into<String>) -> AnyModel
Set the version string for cache invalidation.
Sourcepub fn with_zero_shot(
self,
f: impl Fn(&str, &[&str], f32) -> Result<Vec<Entity>, Error> + Send + Sync + 'static,
) -> AnyModel
pub fn with_zero_shot( self, f: impl Fn(&str, &[&str], f32) -> Result<Vec<Entity>, Error> + Send + Sync + 'static, ) -> AnyModel
Attach a ZeroShotNER implementation via closure.
When set, AnyModel will implement ZeroShotNER by delegating to this
closure, and Model::capabilities() will report zero_shot = true.
Sourcepub fn with_relations(
self,
f: impl Fn(&str, Option<Language>) -> Result<(Vec<Entity>, Vec<Relation>), Error> + Send + Sync + 'static,
) -> AnyModel
pub fn with_relations( self, f: impl Fn(&str, Option<Language>) -> Result<(Vec<Entity>, Vec<Relation>), Error> + Send + Sync + 'static, ) -> AnyModel
Attach a RelationCapable implementation via closure.
When set, AnyModel will implement RelationCapable by delegating to this
closure, and Model::capabilities() will report relation_capable = true.
Trait Implementations§
Source§impl Model for AnyModel
impl Model for AnyModel
Source§fn extract_entities(
&self,
text: &str,
language: Option<Language>,
) -> Result<Vec<Entity>, Error>
fn extract_entities( &self, text: &str, language: Option<Language>, ) -> Result<Vec<Entity>, Error>
Extract entities from text.
Source§fn supported_types(&self) -> Vec<EntityType>
fn supported_types(&self) -> Vec<EntityType>
Get supported entity types.
Source§fn is_available(&self) -> bool
fn is_available(&self) -> bool
Check if model is available and ready.
Source§fn description(&self) -> &'static str
fn description(&self) -> &'static str
Get a description of the model.
Source§fn capabilities(&self) -> ModelCapabilities
fn capabilities(&self) -> ModelCapabilities
Get capability summary for this model. Read more
Source§impl RelationCapable for AnyModel
impl RelationCapable for AnyModel
Source§impl ZeroShotNER for AnyModel
impl ZeroShotNER for AnyModel
Source§fn extract_with_types(
&self,
text: &str,
entity_types: &[&str],
threshold: f32,
) -> Result<Vec<Entity>, Error>
fn extract_with_types( &self, text: &str, entity_types: &[&str], threshold: f32, ) -> Result<Vec<Entity>, Error>
Extract entities with custom types. Read more
Source§fn extract_with_descriptions(
&self,
text: &str,
descriptions: &[&str],
threshold: f32,
) -> Result<Vec<Entity>, Error>
fn extract_with_descriptions( &self, text: &str, descriptions: &[&str], threshold: f32, ) -> Result<Vec<Entity>, Error>
Extract entities with natural language descriptions. Read more
Source§fn default_types(&self) -> &[&'static str]
fn default_types(&self) -> &[&'static str]
Get default entity types for this model. Read more
Auto Trait Implementations§
impl Freeze for AnyModel
impl !RefUnwindSafe for AnyModel
impl Send for AnyModel
impl Sync for AnyModel
impl Unpin for AnyModel
impl UnsafeUnpin for AnyModel
impl !UnwindSafe for AnyModel
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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