pub struct NERDataset { /* private fields */ }Expand description
A collection of annotated NER examples with metadata and filtering.
NERDataset is the primary type for working with NER evaluation data.
It wraps a Vec<AnnotatedExample> with convenient methods for filtering,
statistics, and conversion to evaluation formats.
§Example
use anno_eval::eval::dataset::{NERDataset, Domain};
// Load synthetic data
let mut dataset = NERDataset::synthetic();
// Filter to specific domain
let biomedical = dataset.filter_domain(Domain::Biomedical);
// Get statistics
let stats = biomedical.stats();
println!("Examples: {}, Entities: {}", stats.total_examples, stats.total_entities);
// Convert to test cases for evaluation
let test_cases = biomedical.to_test_cases();Implementations§
Source§impl NERDataset
impl NERDataset
Sourcepub fn from_examples(
name: impl Into<String>,
examples: Vec<AnnotatedExample>,
) -> Self
pub fn from_examples( name: impl Into<String>, examples: Vec<AnnotatedExample>, ) -> Self
Create a dataset from a vector of examples.
Sourcepub fn with_source(self, source: impl Into<String>) -> Self
pub fn with_source(self, source: impl Into<String>) -> Self
Create a dataset with source information.
Sourcepub fn synthetic() -> Self
pub fn synthetic() -> Self
Load the full synthetic dataset (all domains, all difficulties).
This is the primary constructor for testing and development. The synthetic data covers many entity types and edge cases.
§Example
use anno_eval::eval::dataset::NERDataset;
let dataset = NERDataset::synthetic();
assert!(!dataset.is_empty());Sourcepub fn synthetic_domain(domain: Domain) -> Self
pub fn synthetic_domain(domain: Domain) -> Self
Load synthetic data for a specific domain.
Sourcepub fn from_json<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_json<P: AsRef<Path>>(path: P) -> Result<Self>
Load a dataset from a JSON file.
Supports both JSON arrays and JSONL (one object per line).
§Format
[
{
"text": "John works at Google.",
"entities": [
{"text": "John", "label": "PER", "start": 0, "end": 4},
{"text": "Google", "label": "ORG", "start": 14, "end": 20}
]
}
]Sourcepub fn from_conll<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_conll<P: AsRef<Path>>(path: P) -> Result<Self>
Load a dataset from CoNLL-2003 format.
§Format
Each line: word POS chunk NER-tag
Empty lines separate sentences.
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Auto-detect format and load from file.
Tries CoNLL first, then JSON/JSONL.
Sourcepub fn get(&self, index: usize) -> Option<&AnnotatedExample>
pub fn get(&self, index: usize) -> Option<&AnnotatedExample>
Get an example by index.
Sourcepub fn as_slice(&self) -> &[AnnotatedExample]
pub fn as_slice(&self) -> &[AnnotatedExample]
Returns a slice of all examples.
Sourcepub fn as_mut_slice(&mut self) -> &mut [AnnotatedExample]
pub fn as_mut_slice(&mut self) -> &mut [AnnotatedExample]
Returns a mutable slice of all examples.
Sourcepub fn iter(&self) -> impl Iterator<Item = &AnnotatedExample>
pub fn iter(&self) -> impl Iterator<Item = &AnnotatedExample>
Returns an iterator over the examples.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut AnnotatedExample>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut AnnotatedExample>
Returns a mutable iterator over the examples.
Sourcepub fn filter_domain(&self, domain: Domain) -> Self
pub fn filter_domain(&self, domain: Domain) -> Self
Filter to a specific domain, returning a new dataset.
Sourcepub fn filter_difficulty(&self, difficulty: Difficulty) -> Self
pub fn filter_difficulty(&self, difficulty: Difficulty) -> Self
Filter to a specific difficulty, returning a new dataset.
Sourcepub fn filter_entity_type(&self, entity_type: &EntityType) -> Self
pub fn filter_entity_type(&self, entity_type: &EntityType) -> Self
Filter to examples containing a specific entity type.
Sourcepub fn push(&mut self, example: AnnotatedExample)
pub fn push(&mut self, example: AnnotatedExample)
Add an example to the dataset.
Sourcepub fn extend<I: IntoIterator<Item = AnnotatedExample>>(&mut self, iter: I)
pub fn extend<I: IntoIterator<Item = AnnotatedExample>>(&mut self, iter: I)
Extend with examples from another source.
Sourcepub fn to_test_cases(&self) -> Vec<(String, Vec<GoldEntity>)>
pub fn to_test_cases(&self) -> Vec<(String, Vec<GoldEntity>)>
Convert to test cases for evaluation functions.
This is the bridge to evaluate_ner_model() and similar functions.
Sourcepub fn into_test_cases(self) -> Vec<(String, Vec<GoldEntity>)>
pub fn into_test_cases(self) -> Vec<(String, Vec<GoldEntity>)>
Consume and convert to test cases.
Sourcepub fn into_inner(self) -> Vec<AnnotatedExample>
pub fn into_inner(self) -> Vec<AnnotatedExample>
Convert to owned examples vec.
Sourcepub fn stats(&self) -> DatasetStats
pub fn stats(&self) -> DatasetStats
Compute dataset statistics.
Trait Implementations§
Source§impl Clone for NERDataset
impl Clone for NERDataset
Source§fn clone(&self) -> NERDataset
fn clone(&self) -> NERDataset
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 NERDataset
impl Debug for NERDataset
Source§impl Default for NERDataset
impl Default for NERDataset
Source§impl<'de> Deserialize<'de> for NERDataset
impl<'de> Deserialize<'de> for NERDataset
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
Source§impl Index<usize> for NERDataset
impl Index<usize> for NERDataset
Source§impl<'a> IntoIterator for &'a NERDataset
impl<'a> IntoIterator for &'a NERDataset
Source§impl IntoIterator for NERDataset
impl IntoIterator for NERDataset
Auto Trait Implementations§
impl Freeze for NERDataset
impl RefUnwindSafe for NERDataset
impl Send for NERDataset
impl Sync for NERDataset
impl Unpin for NERDataset
impl UnsafeUnpin for NERDataset
impl UnwindSafe for NERDataset
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