pub struct GoldEntity {
pub text: String,
pub entity_type: EntityType,
pub original_label: String,
pub start: usize,
pub end: usize,
}Expand description
Gold standard entity annotation.
This is the canonical entity type for all NER evaluation. Use this instead of creating local entity structs.
§Example
use anno_eval::eval::GoldEntity;
use anno::EntityType;
let entity = GoldEntity::new("John Doe", EntityType::Person, 0);
assert_eq!(entity.end, 8);Fields§
§text: StringThe entity text (surface form)
entity_type: EntityTypeNormalized entity type
original_label: StringOriginal label from dataset (e.g., “B-PER”, “ACTOR”)
start: usizeCharacter offset (start)
end: usizeCharacter offset (end, exclusive)
Implementations§
Source§impl GoldEntity
impl GoldEntity
Sourcepub fn new(
text: impl Into<String>,
entity_type: EntityType,
start: usize,
) -> Self
pub fn new( text: impl Into<String>, entity_type: EntityType, start: usize, ) -> Self
Create a new gold entity with computed end offset.
Note: Uses character count (not byte count) for Unicode correctness.
Sourcepub fn with_span(
text: impl Into<String>,
entity_type: EntityType,
start: usize,
end: usize,
) -> Self
pub fn with_span( text: impl Into<String>, entity_type: EntityType, start: usize, end: usize, ) -> Self
Create with explicit span (start, end).
Sourcepub fn with_label(
text: impl Into<String>,
entity_type: EntityType,
original_label: impl Into<String>,
start: usize,
) -> Self
pub fn with_label( text: impl Into<String>, entity_type: EntityType, original_label: impl Into<String>, start: usize, ) -> Self
Create with explicit original label.
Note: Uses character count (not byte count) for Unicode correctness.
Sourcepub fn full(
text: impl Into<String>,
entity_type: EntityType,
original_label: impl Into<String>,
start: usize,
end: usize,
) -> Self
pub fn full( text: impl Into<String>, entity_type: EntityType, original_label: impl Into<String>, start: usize, end: usize, ) -> Self
Create with all fields explicit.
Sourcepub fn extract_text(&self, source_text: &str) -> String
pub fn extract_text(&self, source_text: &str) -> String
Safely extract text from source using character offsets.
GoldEntity stores character offsets, not byte offsets. This method correctly extracts text by iterating over characters.
§Arguments
source_text- The original text from which this entity was extracted
§Returns
The extracted text, or empty string if offsets are invalid
Sourcepub fn span_matches(&self, other: &Self) -> bool
pub fn span_matches(&self, other: &Self) -> bool
Check if spans match exactly.
Sourcepub fn exact_matches(&self, other: &Self) -> bool
pub fn exact_matches(&self, other: &Self) -> bool
Check if this is an exact match (span + type).
Trait Implementations§
Source§impl Clone for GoldEntity
impl Clone for GoldEntity
Source§fn clone(&self) -> GoldEntity
fn clone(&self) -> GoldEntity
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 GoldEntity
impl Debug for GoldEntity
Source§impl<'de> Deserialize<'de> for GoldEntity
impl<'de> Deserialize<'de> for GoldEntity
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 PartialEq for GoldEntity
impl PartialEq for GoldEntity
Source§fn eq(&self, other: &GoldEntity) -> bool
fn eq(&self, other: &GoldEntity) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for GoldEntity
impl Serialize for GoldEntity
impl StructuralPartialEq for GoldEntity
Auto Trait Implementations§
impl Freeze for GoldEntity
impl RefUnwindSafe for GoldEntity
impl Send for GoldEntity
impl Sync for GoldEntity
impl Unpin for GoldEntity
impl UnsafeUnpin for GoldEntity
impl UnwindSafe for GoldEntity
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