Skip to main content

EntitySliceExt

Trait EntitySliceExt 

Source
pub trait EntitySliceExt {
Show 13 methods // Required methods fn above_confidence(&self, min: f64) -> impl Iterator<Item = &Entity>; fn of_type(&self, ty: &EntityType) -> impl Iterator<Item = &Entity>; fn has_overlaps(&self) -> bool; fn overlapping_pairs(&self) -> Vec<(&Entity, &Entity)>; fn sorted_by_confidence(&self) -> Vec<&Entity>; fn sorted_by_position(&self) -> Vec<&Entity>; fn highest_confidence(&self) -> Option<&Entity>; fn mean_confidence(&self) -> Option<f64>; fn group_by_type(&self) -> HashMap<String, Vec<&Entity>>; fn contains_position(&self, pos: usize) -> bool; fn at_position(&self, pos: usize) -> Option<&Entity>; fn named_only(&self) -> impl Iterator<Item = &Entity>; fn structured_only(&self) -> impl Iterator<Item = &Entity>;
}
Expand description

Extension methods for slices of entities.

This trait adds useful operations to [Entity] and Vec<Entity> without requiring you to wrap them in a newtype.

§Example

use anno::{Entity, EntityType};
use anno::types::EntitySliceExt;

let entities = vec![
    Entity::new("John", EntityType::Person, 0, 4, 0.9),
    Entity::new("$100", EntityType::Money, 10, 14, 0.95),
    Entity::new("Paris", EntityType::Location, 20, 25, 0.7),
];

// Filter by confidence
let high_conf: Vec<_> = entities.above_confidence(0.8).collect();
assert_eq!(high_conf.len(), 2);

// Check for overlaps
assert!(!entities.has_overlaps());

Required Methods§

Source

fn above_confidence(&self, min: f64) -> impl Iterator<Item = &Entity>

Filter entities by minimum confidence threshold.

Source

fn of_type(&self, ty: &EntityType) -> impl Iterator<Item = &Entity>

Filter entities by type.

Source

fn has_overlaps(&self) -> bool

Check if any entities overlap with each other.

Source

fn overlapping_pairs(&self) -> Vec<(&Entity, &Entity)>

Find all overlapping pairs of entities.

Source

fn sorted_by_confidence(&self) -> Vec<&Entity>

Get entities sorted by confidence (descending).

Source

fn sorted_by_position(&self) -> Vec<&Entity>

Get entities sorted by position (ascending).

Source

fn highest_confidence(&self) -> Option<&Entity>

Get the entity with highest confidence.

Source

fn mean_confidence(&self) -> Option<f64>

Calculate average confidence across all entities.

Source

fn group_by_type(&self) -> HashMap<String, Vec<&Entity>>

Group entities by type.

Source

fn contains_position(&self, pos: usize) -> bool

Check if a position falls within any entity span.

Source

fn at_position(&self, pos: usize) -> Option<&Entity>

Get entity at a specific position (if any).

Source

fn named_only(&self) -> impl Iterator<Item = &Entity>

Filter to only named entities (Person, Org, Location).

Source

fn structured_only(&self) -> impl Iterator<Item = &Entity>

Filter to only structured entities (Date, Money, Email, etc.).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl EntitySliceExt for [Entity]

Implementors§