pub struct DeferredResolutionContext {
pub pending: Vec<UncertainReference>,
pub resolved: Vec<UncertainReference>,
pub entity_mentions: HashMap<u64, Vec<usize>>,
pub position: usize,
}Expand description
Context for managing multiple uncertain references across a discourse.
This is the “virtual machine” state for deferred coreference resolution, tracking pending references and resolving them as context becomes available.
§Example
use anno::discourse::uncertain_reference::{
DeferredResolutionContext, UncertainReference, ReferenceCandidate,
};
let mut context = DeferredResolutionContext::new();
// Encounter a cataphoric pronoun "When she arrived..."
let cataphoric = UncertainReference::new("she").cataphoric().at_position(5);
context.add_uncertain(cataphoric);
// Process more text...
context.advance();
// Later, encounter "Mary walked in"
context.try_resolve_cataphoric(&[(1, "Mary".to_string(), 0.9)]);
// At discourse end, resolve all pending
context.resolve_all();
// Check statistics
let stats = context.statistics();
assert_eq!(stats.resolved, 1);§Workflow
- Create context at discourse start
- Add uncertain references as they’re encountered
- Call
advanceto track position - When new entities appear, call
try_resolve_cataphoric - At discourse end, call
resolve_all - Inspect
statisticsfor analysis
Fields§
§pending: Vec<UncertainReference>Uncertain references not yet resolved.
resolved: Vec<UncertainReference>References that have been resolved (for tracking and analysis).
entity_mentions: HashMap<u64, Vec<usize>>Entity mentions seen so far: entity_id -> list of positions.
position: usizeCurrent discourse position (incremented via advance).
Implementations§
Source§impl DeferredResolutionContext
impl DeferredResolutionContext
Sourcepub fn new() -> DeferredResolutionContext
pub fn new() -> DeferredResolutionContext
Create a new context.
Sourcepub fn add_uncertain(&mut self, reference: UncertainReference)
pub fn add_uncertain(&mut self, reference: UncertainReference)
Add a new uncertain reference.
Sourcepub fn record_mention(&mut self, entity_id: u64)
pub fn record_mention(&mut self, entity_id: u64)
Record an entity mention at the current position.
Sourcepub fn try_resolve_cataphoric(&mut self, new_entities: &[(u64, String, f64)])
pub fn try_resolve_cataphoric(&mut self, new_entities: &[(u64, String, f64)])
Try to resolve pending cataphoric references.
Called when new entities become available.
Sourcepub fn resolve_all(&mut self)
pub fn resolve_all(&mut self)
Force resolution of all pending references.
Used at discourse end or when resolution is required.
Sourcepub fn ambiguous_references(&self, threshold: f64) -> Vec<&UncertainReference>
pub fn ambiguous_references(&self, threshold: f64) -> Vec<&UncertainReference>
Get pending references that are ambiguous.
Sourcepub fn statistics(&self) -> ResolutionStatistics
pub fn statistics(&self) -> ResolutionStatistics
Get statistics about resolution.
Trait Implementations§
Source§impl Clone for DeferredResolutionContext
impl Clone for DeferredResolutionContext
Source§fn clone(&self) -> DeferredResolutionContext
fn clone(&self) -> DeferredResolutionContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DeferredResolutionContext
impl Debug for DeferredResolutionContext
Source§impl Default for DeferredResolutionContext
impl Default for DeferredResolutionContext
Source§fn default() -> DeferredResolutionContext
fn default() -> DeferredResolutionContext
Auto Trait Implementations§
impl Freeze for DeferredResolutionContext
impl RefUnwindSafe for DeferredResolutionContext
impl Send for DeferredResolutionContext
impl Sync for DeferredResolutionContext
impl Unpin for DeferredResolutionContext
impl UnsafeUnpin for DeferredResolutionContext
impl UnwindSafe for DeferredResolutionContext
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,
impl<T> ErasedDestructor for Twhere
T: 'static,
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