pub trait Model:
Sealed
+ Send
+ Sync {
// Required methods
fn extract_entities(
&self,
text: &str,
language: Option<&str>,
) -> Result<Vec<Entity>>;
fn supported_types(&self) -> Vec<EntityType>;
fn is_available(&self) -> bool;
// Provided methods
fn name(&self) -> &'static str { ... }
fn description(&self) -> &'static str { ... }
fn capabilities(&self) -> ModelCapabilities { ... }
fn version(&self) -> String { ... }
}Expand description
Trait for NER model backends.
§Sealed Trait
Model is intentionally sealed (cannot be implemented outside this crate) to:
- Maintain invariants: All backends must produce entities with valid character
offsets, confidence in
[0, 1], and non-empty text. - Allow evolution: New methods can be added with default implementations without breaking external code.
- Ensure consistency: All backends share standardized behavior for
is_available(),supported_types(), etc.
§For External Backends
If you need to integrate an external NER backend (e.g., a REST API, Python model
via PyO3, or custom implementation), use the AnyModel wrapper:
use anno::{AnyModel, Entity, EntityType, Result};
struct MyExternalNER { /* ... */ }
impl MyExternalNER {
fn extract(&self, text: &str) -> Vec<Entity> {
// Your implementation
vec![]
}
}
// Wrap in AnyModel to use with anno's infrastructure
let model = AnyModel::new(
"my-ner",
vec![EntityType::Person, EntityType::Organization],
move |text, _lang| Ok(my_ner.extract(text)),
);
// Now usable wherever Box<dyn Model> is expected
let entities = model.extract_entities("Hello world", None)?;Required Methods§
Sourcefn extract_entities(
&self,
text: &str,
language: Option<&str>,
) -> Result<Vec<Entity>>
fn extract_entities( &self, text: &str, language: Option<&str>, ) -> Result<Vec<Entity>>
Extract entities from text.
Sourcefn supported_types(&self) -> Vec<EntityType>
fn supported_types(&self) -> Vec<EntityType>
Get supported entity types.
Sourcefn is_available(&self) -> bool
fn is_available(&self) -> bool
Check if model is available and ready.
Provided Methods§
Sourcefn description(&self) -> &'static str
fn description(&self) -> &'static str
Get a description of the model.
Sourcefn capabilities(&self) -> ModelCapabilities
fn capabilities(&self) -> ModelCapabilities
Get capability summary for this model.
Override this in implementations that support additional capabilities (batch, GPU, streaming, etc.) to enable runtime discovery.
§Default
Returns a ModelCapabilities with all fields set to false/None.
Implementors§
impl Model for ALBERTNER
impl Model for BiLstmCrfNER
impl Model for CrfNER
impl Model for DeBERTaV3NER
impl Model for EnsembleNER
impl Model for NERExtractor
impl Model for GLiNER2Onnx
onnx only.impl Model for GLiNEROnnx
impl Model for GLiNERPoly
impl Model for HeuristicNER
impl Model for HmmNER
impl Model for LexiconNER
impl Model for NuNER
impl Model for BertNEROnnx
onnx only.impl Model for RegexNER
impl Model for AutoNER
impl Model for RuleBasedNER
impl Model for StackedNER
impl Model for TPLinker
impl Model for UniversalNER
impl Model for W2NER
impl Model for JointModel
Implement the Model trait for JointModel to allow it to be used as an NER backend.
Note: JointModel requires pre-extracted entities as input, so extract_entities
uses an internal regex-based mention detector as a fallback.