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>) -> Self
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"); // sortedSourcepub fn with_id(
mentions: Vec<Mention>,
cluster_id: impl Into<CanonicalId>,
) -> Self
pub fn with_id( mentions: Vec<Mention>, cluster_id: impl Into<CanonicalId>, ) -> Self
Build a chain with an explicit cluster ID.
Sourcepub fn singleton(mention: Mention) -> Self
pub fn singleton(mention: Mention) -> Self
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 more