Skip to main content

CorefChain

Struct CorefChain 

Source
pub struct CorefChain {
    pub mentions: Vec<Mention>,
    pub cluster_id: Option<CanonicalId>,
    pub entity_type: Option<String>,
}
Expand description

A coreference chain: mentions that all refer to the same entity.

// "John went to the store. He bought milk."
//  ^^^^                    ^^
let john = Mention::new("John", 0, 4);
let he = Mention::new("He", 25, 27);

let chain = CorefChain::new(vec![john, he]);
assert_eq!(chain.len(), 2);
assert!(!chain.is_singleton());

§Note

This type is for evaluation and intermediate processing. For production pipelines, use Track which integrates with the Signal/Track/Identity hierarchy.

Fields§

§mentions: Vec<Mention>

Mentions in document order (sorted by start position).

§cluster_id: Option<CanonicalId>

Cluster ID from the source data, if any.

§entity_type: Option<String>

Entity type shared by all mentions (e.g., “PERSON”).

Implementations§

Source§

impl CorefChain

Source

pub fn new(mentions: Vec<Mention>) -> Self

Build a chain from mentions. Sorts by position automatically.

let chain = CorefChain::new(vec![
    Mention::new("she", 50, 53),
    Mention::new("Dr. Smith", 0, 9),  // out of order
]);
assert_eq!(chain.mentions[0].text, "Dr. Smith"); // sorted
Source

pub fn with_id( mentions: Vec<Mention>, cluster_id: impl Into<CanonicalId>, ) -> Self

Build a chain with an explicit cluster ID.

Source

pub fn singleton(mention: Mention) -> Self

A chain with exactly one mention (entity mentioned only once).

Source

pub fn len(&self) -> usize

Number of mentions. A chain with 3 mentions has 2 implicit “links”.

Source

pub fn is_empty(&self) -> bool

True if chain has no mentions. Shouldn’t happen in valid data.

Source

pub fn is_singleton(&self) -> bool

True if chain has exactly one mention (singleton entity).

All pairwise links. For MUC: n mentions = n*(n-1)/2 links.

let chain = CorefChain::new(vec![
    Mention::new("A", 0, 1),
    Mention::new("B", 2, 3),
    Mention::new("C", 4, 5),
]);
assert_eq!(chain.links().len(), 3); // A-B, A-C, B-C

Number of coreference links.

For a chain of n mentions: n*(n-1)/2 pairs, but only n-1 links needed to connect all mentions (spanning tree).

Source

pub fn all_pairs(&self) -> Vec<(&Mention, &Mention)>

Get all pairwise mention combinations (for B³, CEAF).

Source

pub fn contains_span(&self, start: usize, end: usize) -> bool

Check if chain contains a mention with given span.

Source

pub fn first(&self) -> Option<&Mention>

Get first mention (usually the most salient/representative).

Source

pub fn mention_spans(&self) -> HashSet<(usize, usize)>

Get set of mention span IDs for set operations.

Source

pub fn canonical_mention(&self) -> Option<&Mention>

Get the canonical (representative) mention for this chain.

Prefers proper nouns over other mention types, then longest mention. Falls back to first mention if no proper noun exists.

Source

pub fn canonical_id(&self) -> Option<CanonicalId>

Get the canonical ID for this chain (cluster_id if set).

Trait Implementations§

Source§

impl Clone for CorefChain

Source§

fn clone(&self) -> CorefChain

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 CorefChain

Source§

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

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

impl<'de> Deserialize<'de> for CorefChain

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 Display for CorefChain

Source§

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

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

impl PartialEq for CorefChain

Source§

fn eq(&self, other: &CorefChain) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CorefChain

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

impl Eq for CorefChain

Source§

impl StructuralPartialEq for CorefChain

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,