pub struct AnnotatedExample {
pub text: String,
pub entities: Vec<GoldEntity>,
pub domain: Domain,
pub difficulty: Difficulty,
}Expand description
A single annotated NER example with text, entities, and metadata.
This is the canonical type for representing labeled NER data, whether from synthetic generation, manual annotation, or loaded from files.
§Example
use anno_eval::eval::dataset::{AnnotatedExample, Domain, Difficulty};
use anno_eval::eval::GoldEntity;
use anno::EntityType;
let example = AnnotatedExample::new(
"Microsoft announced earnings",
vec![GoldEntity::new("Microsoft", EntityType::Organization, 0)],
);
assert_eq!(example.text, "Microsoft announced earnings");
assert_eq!(example.entities.len(), 1);Fields§
§text: StringThe input text.
entities: Vec<GoldEntity>Gold standard entity annotations.
domain: DomainDomain classification (e.g., News, Biomedical).
difficulty: DifficultyDifficulty level (e.g., Easy, Hard).
Implementations§
Source§impl AnnotatedExample
impl AnnotatedExample
Sourcepub fn new(text: impl Into<String>, entities: Vec<GoldEntity>) -> Self
pub fn new(text: impl Into<String>, entities: Vec<GoldEntity>) -> Self
Create a new annotated example with default domain/difficulty.
Sourcepub fn simple(text: impl Into<String>, entities: Vec<(&str, &str)>) -> Self
pub fn simple(text: impl Into<String>, entities: Vec<(&str, &str)>) -> Self
Convenience constructor from text and entity tuples (alias for from_tuples).
This is the same as from_tuples but with the shorter name commonly used
in test code.
Sourcepub fn with_metadata(
text: impl Into<String>,
entities: Vec<GoldEntity>,
domain: Domain,
difficulty: Difficulty,
) -> Self
pub fn with_metadata( text: impl Into<String>, entities: Vec<GoldEntity>, domain: Domain, difficulty: Difficulty, ) -> Self
Create with explicit domain and difficulty.
Sourcepub fn from_tuples(text: impl Into<String>, entities: Vec<(&str, &str)>) -> Self
pub fn from_tuples(text: impl Into<String>, entities: Vec<(&str, &str)>) -> Self
Convenience constructor for doctests and simple examples.
Entity positions are computed by finding each entity text within the input.
§Panics
Panics if an entity text is not found in the input text.
§Example
use anno_eval::eval::dataset::AnnotatedExample;
let example = AnnotatedExample::from_tuples(
"John works at Google.",
vec![("John", "PER"), ("Google", "ORG")],
);
assert_eq!(example.entities.len(), 2);Sourcepub fn with_domain(self, domain: Domain) -> Self
pub fn with_domain(self, domain: Domain) -> Self
Set the domain and return self (builder pattern).
Sourcepub fn with_difficulty(self, difficulty: Difficulty) -> Self
pub fn with_difficulty(self, difficulty: Difficulty) -> Self
Set the difficulty and return self (builder pattern).
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if this example has no entities (negative example).
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Returns the number of entities.
Sourcepub fn entity_types(&self) -> Vec<&EntityType>
pub fn entity_types(&self) -> Vec<&EntityType>
Returns unique entity types in this example.
Sourcepub fn as_test_case(&self) -> (&str, &[GoldEntity])
pub fn as_test_case(&self) -> (&str, &[GoldEntity])
Convert to (text, entities) tuple for evaluation functions.
Sourcepub fn into_test_case(self) -> (String, Vec<GoldEntity>)
pub fn into_test_case(self) -> (String, Vec<GoldEntity>)
Consume and convert to owned (text, entities) tuple.
Trait Implementations§
Source§impl Clone for AnnotatedExample
impl Clone for AnnotatedExample
Source§fn clone(&self) -> AnnotatedExample
fn clone(&self) -> AnnotatedExample
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AnnotatedExample
impl Debug for AnnotatedExample
Source§impl<'de> Deserialize<'de> for AnnotatedExample
impl<'de> Deserialize<'de> for AnnotatedExample
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Extend<AnnotatedExample> for NERDataset
impl Extend<AnnotatedExample> for NERDataset
Source§fn extend<I: IntoIterator<Item = AnnotatedExample>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = AnnotatedExample>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<AnnotatedExample> for NERDataset
impl FromIterator<AnnotatedExample> for NERDataset
Source§fn from_iter<I: IntoIterator<Item = AnnotatedExample>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = AnnotatedExample>>(iter: I) -> Self
Auto Trait Implementations§
impl Freeze for AnnotatedExample
impl RefUnwindSafe for AnnotatedExample
impl Send for AnnotatedExample
impl Sync for AnnotatedExample
impl Unpin for AnnotatedExample
impl UnsafeUnpin for AnnotatedExample
impl UnwindSafe for AnnotatedExample
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
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>
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>
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