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
impl CorefChain
Sourcepub fn new(mentions: Vec<Mention>) -> CorefChain
pub fn new(mentions: Vec<Mention>) -> CorefChain
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"); // sortedSourcepub fn with_id(
mentions: Vec<Mention>,
cluster_id: impl Into<CanonicalId>,
) -> CorefChain
pub fn with_id( mentions: Vec<Mention>, cluster_id: impl Into<CanonicalId>, ) -> CorefChain
Build a chain with an explicit cluster ID.
Sourcepub fn singleton(mention: Mention) -> CorefChain
pub fn singleton(mention: Mention) -> CorefChain
A chain with exactly one mention (entity mentioned only once).
Sourcepub fn is_singleton(&self) -> bool
pub fn is_singleton(&self) -> bool
True if chain has exactly one mention (singleton entity).
Sourcepub fn links(&self) -> Vec<(&Mention, &Mention)>
pub fn links(&self) -> Vec<(&Mention, &Mention)>
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-CSourcepub fn link_count(&self) -> usize
pub fn link_count(&self) -> usize
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).
Sourcepub fn all_pairs(&self) -> Vec<(&Mention, &Mention)>
pub fn all_pairs(&self) -> Vec<(&Mention, &Mention)>
Get all pairwise mention combinations (for B³, CEAF).
Sourcepub fn contains_span(&self, start: usize, end: usize) -> bool
pub fn contains_span(&self, start: usize, end: usize) -> bool
Check if chain contains a mention with given span.
Sourcepub fn first(&self) -> Option<&Mention>
pub fn first(&self) -> Option<&Mention>
Get first mention (usually the most salient/representative).
Sourcepub fn mention_spans(&self) -> HashSet<(usize, usize)>
pub fn mention_spans(&self) -> HashSet<(usize, usize)>
Get set of mention span IDs for set operations.
Sourcepub fn canonical_mention(&self) -> Option<&Mention>
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.
Sourcepub fn canonical_id(&self) -> Option<CanonicalId>
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
impl Clone for CorefChain
Source§fn clone(&self) -> CorefChain
fn clone(&self) -> CorefChain
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CorefChain
impl Debug for CorefChain
Source§impl<'de> Deserialize<'de> for CorefChain
impl<'de> Deserialize<'de> for CorefChain
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CorefChain, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CorefChain, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for CorefChain
impl Display for CorefChain
Source§impl PartialEq for CorefChain
impl PartialEq for CorefChain
Source§impl Serialize for CorefChain
impl Serialize for CorefChain
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for CorefChain
impl StructuralPartialEq for CorefChain
Auto Trait Implementations§
impl Freeze for CorefChain
impl RefUnwindSafe for CorefChain
impl Send for CorefChain
impl Sync for CorefChain
impl Unpin for CorefChain
impl UnsafeUnpin for CorefChain
impl UnwindSafe for CorefChain
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.