pub struct UncertainReference {
pub description: String,
pub candidates: Vec<ReferenceCandidate>,
pub resolved: bool,
pub resolved_entity: Option<u64>,
pub constraints: Vec<ReferenceConstraint>,
pub discourse_position: Option<usize>,
pub is_cataphoric: bool,
}Expand description
An uncertain reference awaiting resolution.
This is anno’s implementation of epsilon-term semantics for coreference. The reference maintains a distribution over possible antecedents that is refined as more context arrives, allowing deferred commitment.
§Lifecycle
- Create: Initialize with descriptive content (the anaphor)
- Populate: Add candidate antecedents via
add_candidate - Refine: Update evidence as context arrives via
update_evidence - Prune: Remove unlikely candidates via
pruneorprune_violations - Resolve: Force resolution via
resolvewhen needed
§Example
use anno::discourse::uncertain_reference::{
UncertainReference, ReferenceCandidate, ConstraintKind,
};
// Create uncertain reference for "she"
let mut reference = UncertainReference::new("she");
// Add hard constraint: must be feminine
reference.add_constraint(ConstraintKind::Gender, "feminine", true);
// Add candidates
reference.add_candidate(ReferenceCandidate::new(1, "Mary", 0.6));
reference.add_candidate(
ReferenceCandidate::new(2, "John", 0.4)
.violates("gender:feminine")
);
// Prune candidates violating hard constraints
reference.prune_violations();
assert_eq!(reference.candidate_count(), 1);
// Resolve
let resolved = reference.resolve().unwrap();
assert_eq!(resolved.entity_id, 1);§Uncertainty Measures
entropy: Shannon entropy of candidate distributionis_ambiguous: Multiple high-probability candidates?probabilities: Softmax distribution over candidates
Fields§
§description: StringDescriptive content — the anaphor text or the “A” in ε_x A[x].
candidates: Vec<ReferenceCandidate>Candidate referents with weights (in log-odds space).
resolved: boolWhether resolution has been forced via resolve.
resolved_entity: Option<u64>The resolved entity ID (set after calling resolve).
constraints: Vec<ReferenceConstraint>Constraints from the anaphor (gender, number, animacy, etc.). Hard constraints filter candidates; soft constraints rank them.
discourse_position: Option<usize>Position in discourse (character offset or utterance index).
is_cataphoric: boolWhether this is cataphoric (forward-referencing). Cataphoric references are resolved when later context provides the antecedent.
Implementations§
Source§impl UncertainReference
impl UncertainReference
Sourcepub fn new(description: impl Into<String>) -> UncertainReference
pub fn new(description: impl Into<String>) -> UncertainReference
Create a new uncertain reference.
Sourcepub fn cataphoric(self) -> UncertainReference
pub fn cataphoric(self) -> UncertainReference
Mark as cataphoric (forward-referencing).
Sourcepub fn at_position(self, position: usize) -> UncertainReference
pub fn at_position(self, position: usize) -> UncertainReference
Set discourse position.
Sourcepub fn add_constraint(
&mut self,
kind: ConstraintKind,
value: impl Into<String>,
is_hard: bool,
)
pub fn add_constraint( &mut self, kind: ConstraintKind, value: impl Into<String>, is_hard: bool, )
Add a constraint.
Sourcepub fn add_candidate(&mut self, candidate: ReferenceCandidate)
pub fn add_candidate(&mut self, candidate: ReferenceCandidate)
Add a candidate referent.
Sourcepub fn update_evidence(&mut self, entity_id: u64, evidence: f64)
pub fn update_evidence(&mut self, entity_id: u64, evidence: f64)
Update evidence for a candidate.
Positive evidence increases weight, negative decreases.
Sourcepub fn prune_violations(&mut self)
pub fn prune_violations(&mut self)
Prune candidates with hard constraint violations.
Sourcepub fn ranked_candidates(&self) -> Vec<&ReferenceCandidate>
pub fn ranked_candidates(&self) -> Vec<&ReferenceCandidate>
Get candidates sorted by weight (highest first).
Sourcepub fn best_candidate(&self) -> Option<&ReferenceCandidate>
pub fn best_candidate(&self) -> Option<&ReferenceCandidate>
Get the best candidate (highest weight).
Sourcepub fn entropy(&self) -> f64
pub fn entropy(&self) -> f64
Compute entropy of the candidate distribution.
Higher entropy = more uncertainty.
Sourcepub fn probabilities(&self) -> HashMap<u64, f64>
pub fn probabilities(&self) -> HashMap<u64, f64>
Convert weights to probabilities (softmax).
Sourcepub fn is_ambiguous(&self, threshold: f64) -> bool
pub fn is_ambiguous(&self, threshold: f64) -> bool
Check if resolution is ambiguous (multiple high-probability candidates).
Sourcepub fn resolve(&mut self) -> Option<ReferenceCandidate>
pub fn resolve(&mut self) -> Option<ReferenceCandidate>
Force resolution to the best candidate.
Returns the resolved candidate.
Sourcepub fn resolve_to(&mut self, entity_id: u64)
pub fn resolve_to(&mut self, entity_id: u64)
Resolve to a specific entity.
Sourcepub fn is_resolved(&self) -> bool
pub fn is_resolved(&self) -> bool
Check if this reference is resolved.
Sourcepub fn candidate_count(&self) -> usize
pub fn candidate_count(&self) -> usize
Get the number of candidates.
Sourcepub fn is_unresolvable(&self) -> bool
pub fn is_unresolvable(&self) -> bool
Check if there are no candidates (unresolvable).
Trait Implementations§
Source§impl Clone for UncertainReference
impl Clone for UncertainReference
Source§fn clone(&self) -> UncertainReference
fn clone(&self) -> UncertainReference
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 UncertainReference
impl Debug for UncertainReference
Source§impl Default for UncertainReference
impl Default for UncertainReference
Source§fn default() -> UncertainReference
fn default() -> UncertainReference
Source§impl<'de> Deserialize<'de> for UncertainReference
impl<'de> Deserialize<'de> for UncertainReference
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<UncertainReference, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<UncertainReference, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for UncertainReference
impl Serialize for UncertainReference
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,
Auto Trait Implementations§
impl Freeze for UncertainReference
impl RefUnwindSafe for UncertainReference
impl Send for UncertainReference
impl Sync for UncertainReference
impl Unpin for UncertainReference
impl UnsafeUnpin for UncertainReference
impl UnwindSafe for UncertainReference
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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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