pub struct TypeMapper { /* private fields */ }Expand description
Maps domain-specific entity types to standard NER types.
§Research Context (Familiarity paper, arXiv:2412.10121)
Type mapping creates “label overlap” between training and evaluation:
- Mapping ACTOR → Person increases overlap
- This can inflate zero-shot F1 scores
Use LabelShift::from_type_sets() to quantify how much overlap exists.
High overlap (>80%) means the evaluation is NOT truly zero-shot.
§When to Use TypeMapper
- Cross-dataset comparison (normalize schemas for fair eval)
- Domain adaptation (map new labels to known types)
§When NOT to Use TypeMapper
- True zero-shot evaluation (keep labels distinct)
- Measuring generalization (overlap hides generalization failures)
§Example
use anno_core::{TypeMapper, EntityType, EntityCategory};
// MIT Movie dataset mapping
let mut mapper = TypeMapper::new();
mapper.add("ACTOR", EntityType::Person);
mapper.add("DIRECTOR", EntityType::Person);
mapper.add("TITLE", EntityType::custom("WORK_OF_ART", EntityCategory::Creative));
assert_eq!(mapper.map("ACTOR"), Some(&EntityType::Person));
assert_eq!(mapper.normalize("DIRECTOR"), EntityType::Person);Implementations§
Source§impl TypeMapper
impl TypeMapper
Sourcepub fn new() -> TypeMapper
pub fn new() -> TypeMapper
Create empty mapper.
Sourcepub fn mit_movie() -> TypeMapper
pub fn mit_movie() -> TypeMapper
Create mapper for MIT Movie dataset.
Sourcepub fn mit_restaurant() -> TypeMapper
pub fn mit_restaurant() -> TypeMapper
Create mapper for MIT Restaurant dataset.
Sourcepub fn biomedical() -> TypeMapper
pub fn biomedical() -> TypeMapper
Create mapper for biomedical datasets (BC5CDR, NCBI).
Create mapper for social media NER datasets (TweetNER7, etc.).
Sourcepub fn manufacturing() -> TypeMapper
pub fn manufacturing() -> TypeMapper
Create mapper for manufacturing domain datasets (FabNER, etc.).
Sourcepub fn add(&mut self, source: impl Into<String>, target: EntityType)
pub fn add(&mut self, source: impl Into<String>, target: EntityType)
Add a mapping from source label to target type.
Sourcepub fn map(&self, label: &str) -> Option<&EntityType>
pub fn map(&self, label: &str) -> Option<&EntityType>
Get mapped type for a label (returns None if not mapped).
Sourcepub fn normalize(&self, label: &str) -> EntityType
pub fn normalize(&self, label: &str) -> EntityType
Normalize a label to EntityType, using mapping if available.
Falls back to EntityType::from_label() if no mapping exists.
Trait Implementations§
Source§impl Clone for TypeMapper
impl Clone for TypeMapper
Source§fn clone(&self) -> TypeMapper
fn clone(&self) -> TypeMapper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TypeMapper
impl Debug for TypeMapper
Source§impl Default for TypeMapper
impl Default for TypeMapper
Source§fn default() -> TypeMapper
fn default() -> TypeMapper
Auto Trait Implementations§
impl Freeze for TypeMapper
impl RefUnwindSafe for TypeMapper
impl Send for TypeMapper
impl Sync for TypeMapper
impl Unpin for TypeMapper
impl UnsafeUnpin for TypeMapper
impl UnwindSafe for TypeMapper
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,
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