pub struct GraphCoref { /* private fields */ }Expand description
Graph-based coreference resolver with iterative refinement.
This implements a heuristic version of the G2GT architecture, preserving the key insight that iterative graph refinement enables global consistency in coreference decisions.
§Algorithm
- Initialize: Empty graph with mentions as nodes
- Iterate: For each mention pair, compute score with graph context
- Update: Add/remove edges based on threshold
- Converge: Stop when graph unchanged or max iterations reached
- Extract: Connected components become coreference chains
§Complexity
- Time: O(N² × T) where N = mentions, T = iterations (typically 4)
- Space: O(N²) for adjacency representation
Compare to Lee et al. (2017): O(N⁴) for full span enumeration.
§Feature Usage
The resolver uses available Mention fields when present:
| Field | Used For | Fallback |
|---|---|---|
mention_type | Pronoun detection, type compatibility | Heuristic detection |
head_start/head_end | Head word matching | Last word of mention |
entity_type | Type compatibility check | Ignored |
Implementations§
Source§impl GraphCoref
impl GraphCoref
Sourcepub fn with_config(config: GraphCorefConfig) -> Self
pub fn with_config(config: GraphCorefConfig) -> Self
Create with custom configuration.
Sourcepub fn resolve(&self, mentions: &[Mention]) -> Vec<CorefChain>
pub fn resolve(&self, mentions: &[Mention]) -> Vec<CorefChain>
Resolve coreferences among mentions using iterative graph refinement.
§Arguments
mentions- Pre-detected mentions (from NER or mention detector). For best results, setmention_typeon each mention.
§Returns
Coreference chains (clusters) where each chain contains mentions
referring to the same entity. By default, singletons are filtered;
set config.include_singletons = true to include them.
§Panics
Does not panic. Empty input returns empty output.
§Example
use anno::backends::graph_coref::GraphCoref;
use anno::{Mention, MentionType};
let coref = GraphCoref::new();
let mut john = Mention::new("John", 0, 4);
john.mention_type = Some(MentionType::Proper);
let mut he = Mention::new("he", 20, 22);
he.mention_type = Some(MentionType::Pronominal);
let chains = coref.resolve(&[john, he]);Sourcepub fn config(&self) -> &GraphCorefConfig
pub fn config(&self) -> &GraphCorefConfig
Get configuration.
Source§impl GraphCoref
impl GraphCoref
Sourcepub fn resolve_with_stats(
&self,
mentions: &[Mention],
) -> (Vec<CorefChain>, GraphCorefStats)
pub fn resolve_with_stats( &self, mentions: &[Mention], ) -> (Vec<CorefChain>, GraphCorefStats)
Resolve coreferences and return detailed statistics.
Useful for debugging, tuning parameters, and understanding convergence.
§Example
use anno::backends::graph_coref::GraphCoref;
use anno::Mention;
let coref = GraphCoref::new();
let mentions = vec![
Mention::new("John", 0, 4),
Mention::new("John", 50, 54),
];
let (chains, stats) = coref.resolve_with_stats(&mentions);
println!("Converged in {} iterations", stats.iterations);
println!("Edge history: {:?}", stats.edge_history);Trait Implementations§
Source§impl Clone for GraphCoref
impl Clone for GraphCoref
Source§fn clone(&self) -> GraphCoref
fn clone(&self) -> GraphCoref
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GraphCoref
impl Debug for GraphCoref
Auto Trait Implementations§
impl Freeze for GraphCoref
impl RefUnwindSafe for GraphCoref
impl Send for GraphCoref
impl Sync for GraphCoref
impl Unpin for GraphCoref
impl UnsafeUnpin for GraphCoref
impl UnwindSafe for GraphCoref
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<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 more