Skip to main content

NERDataset

Struct NERDataset 

Source
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

Source

pub fn new(name: impl Into<String>) -> Self

Create an empty dataset with a name.

Source

pub fn from_examples( name: impl Into<String>, examples: Vec<AnnotatedExample>, ) -> Self

Create a dataset from a vector of examples.

Source

pub fn with_source(self, source: impl Into<String>) -> Self

Create a dataset with source information.

Source

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());
Source

pub fn synthetic_domain(domain: Domain) -> Self

Load synthetic data for a specific domain.

Source

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}
    ]
  }
]
Source

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.

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>

Auto-detect format and load from file.

Tries CoNLL first, then JSON/JSONL.

Source

pub fn name(&self) -> &str

Returns the dataset name.

Source

pub fn source(&self) -> Option<&str>

Returns the source (file path, URL, etc.) if known.

Source

pub fn len(&self) -> usize

Returns the number of examples.

Source

pub fn is_empty(&self) -> bool

Returns true if the dataset is empty.

Source

pub fn get(&self, index: usize) -> Option<&AnnotatedExample>

Get an example by index.

Source

pub fn as_slice(&self) -> &[AnnotatedExample]

Returns a slice of all examples.

Source

pub fn as_mut_slice(&mut self) -> &mut [AnnotatedExample]

Returns a mutable slice of all examples.

Source

pub fn iter(&self) -> impl Iterator<Item = &AnnotatedExample>

Returns an iterator over the examples.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut AnnotatedExample>

Returns a mutable iterator over the examples.

Source

pub fn filter_domain(&self, domain: Domain) -> Self

Filter to a specific domain, returning a new dataset.

Source

pub fn filter_difficulty(&self, difficulty: Difficulty) -> Self

Filter to a specific difficulty, returning a new dataset.

Source

pub fn filter_entity_type(&self, entity_type: &EntityType) -> Self

Filter to examples containing a specific entity type.

Source

pub fn filter<F>(&self, predicate: F) -> Self
where F: Fn(&AnnotatedExample) -> bool,

Filter using a custom predicate.

Source

pub fn take(&self, n: usize) -> Self

Take the first n examples.

Source

pub fn skip(&self, n: usize) -> Self

Skip the first n examples.

Source

pub fn push(&mut self, example: AnnotatedExample)

Add an example to the dataset.

Source

pub fn extend<I: IntoIterator<Item = AnnotatedExample>>(&mut self, iter: I)

Extend with examples from another source.

Source

pub fn merge(&mut self, other: Self)

Merge another dataset into this one.

Source

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.

Source

pub fn into_test_cases(self) -> Vec<(String, Vec<GoldEntity>)>

Consume and convert to test cases.

Source

pub fn into_inner(self) -> Vec<AnnotatedExample>

Convert to owned examples vec.

Source

pub fn stats(&self) -> DatasetStats

Compute dataset statistics.

Trait Implementations§

Source§

impl Clone for NERDataset

Source§

fn clone(&self) -> NERDataset

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NERDataset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NERDataset

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for NERDataset

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Extend<AnnotatedExample> for NERDataset

Source§

fn extend<I: IntoIterator<Item = AnnotatedExample>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<AnnotatedExample> for NERDataset

Source§

fn from_iter<I: IntoIterator<Item = AnnotatedExample>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<usize> for NERDataset

Source§

type Output = AnnotatedExample

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a NERDataset

Source§

type Item = &'a AnnotatedExample

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, AnnotatedExample>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for NERDataset

Source§

type Item = AnnotatedExample

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<AnnotatedExample>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Serialize for NERDataset

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more