Skip to main content

EntityBuilder

Struct EntityBuilder 

Source
pub struct EntityBuilder { /* private fields */ }
Expand description

Fluent builder for constructing entities with optional fields.

§Example

use anno_core::{Entity, EntityType, Provenance};

let entity = Entity::builder("Marie Curie", EntityType::Person)
    .span(0, 11)
    .confidence(0.95)
    .kb_id("Q7186")
    .provenance(Provenance::ml("bert", 0.95))
    .build();

Implementations§

Source§

impl EntityBuilder

Source

pub fn new(text: impl Into<String>, entity_type: EntityType) -> Self

Create a new builder.

Source

pub const fn span(self, start: usize, end: usize) -> Self

Set span offsets.

Source

pub fn confidence(self, confidence: f64) -> Self

Set confidence score.

Source

pub fn hierarchical_confidence(self, confidence: HierarchicalConfidence) -> Self

Set hierarchical confidence.

Source

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

Set normalized form.

Source

pub fn provenance(self, provenance: Provenance) -> Self

Set provenance.

Source

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

Set knowledge base ID.

Source

pub const fn canonical_id(self, canonical_id: u64) -> Self

Set canonical (coreference) ID.

Source

pub fn visual_span(self, span: Span) -> Self

Set visual span.

Source

pub fn discontinuous_span(self, span: DiscontinuousSpan) -> Self

Set discontinuous span for non-contiguous entities.

This automatically updates start and end to the bounding range.

Source

pub fn valid_from(self, dt: DateTime<Utc>) -> Self

Set temporal validity start (when this entity assertion became true).

§Example
use anno_core::{EntityBuilder, EntityType};
use chrono::{TimeZone, Utc};

let entity = EntityBuilder::new("CEO of Microsoft", EntityType::Person)
    .span(0, 12)
    .valid_from(Utc.with_ymd_and_hms(2008, 10, 1, 0, 0, 0).unwrap())
    .build();
assert!(entity.valid_from.is_some());
Source

pub fn valid_until(self, dt: DateTime<Utc>) -> Self

Set temporal validity end (when this entity assertion stopped being true).

Source

pub fn temporal_range(self, from: DateTime<Utc>, until: DateTime<Utc>) -> Self

Set temporal validity range (convenience method).

Source

pub fn viewport(self, viewport: EntityViewport) -> Self

Set the viewport context for multi-faceted entity representation.

§Example
use anno_core::{EntityBuilder, EntityType, EntityViewport};

let entity = EntityBuilder::new("Marie Curie", EntityType::Person)
    .span(0, 11)
    .viewport(EntityViewport::Academic)
    .build();
assert_eq!(entity.viewport, Some(EntityViewport::Academic));
Source

pub fn build(self) -> Entity

Build the entity.

Trait Implementations§

Source§

impl Clone for EntityBuilder

Source§

fn clone(&self) -> EntityBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EntityBuilder

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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