Skip to main content

Model

Trait Model 

Source
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:

  1. Maintain invariants: All backends must produce entities with valid character offsets, confidence in [0, 1], and non-empty text.
  2. Allow evolution: New methods can be added with default implementations without breaking external code.
  3. 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§

Source

fn extract_entities( &self, text: &str, language: Option<&str>, ) -> Result<Vec<Entity>>

Extract entities from text.

Source

fn supported_types(&self) -> Vec<EntityType>

Get supported entity types.

Source

fn is_available(&self) -> bool

Check if model is available and ready.

Provided Methods§

Source

fn name(&self) -> &'static str

Get the model name/identifier.

Source

fn description(&self) -> &'static str

Get a description of the model.

Source

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.

Source

fn version(&self) -> String

Get a version identifier for the model configuration/weights.

Used for cache invalidation. Default implementation returns “1”.

Implementors§

Source§

impl Model for ALBERTNER

Source§

impl Model for BiLstmCrfNER

Source§

impl Model for CrfNER

Source§

impl Model for DeBERTaV3NER

Source§

impl Model for EnsembleNER

Source§

impl Model for NERExtractor

Source§

impl Model for GLiNER2Onnx

Available on crate feature onnx only.
Source§

impl Model for GLiNEROnnx

Source§

impl Model for GLiNERPoly

Source§

impl Model for HeuristicNER

Source§

impl Model for HmmNER

Source§

impl Model for LexiconNER

Source§

impl Model for NuNER

Source§

impl Model for BertNEROnnx

Available on crate feature onnx only.
Source§

impl Model for RegexNER

Source§

impl Model for AutoNER

Source§

impl Model for RuleBasedNER

Source§

impl Model for StackedNER

Source§

impl Model for TPLinker

Source§

impl Model for UniversalNER

Source§

impl Model for W2NER

Source§

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.

Source§

impl Model for AnyModel

Source§

impl Model for MockModel