pub struct CenteringState {
pub utterance_idx: usize,
pub cf: Vec<ForwardCenter>,
pub cb: Option<u64>,
pub cp: Option<u64>,
pub transition: CenteringTransition,
pub recency_scores: HashMap<u64, f64>,
}Expand description
Centering state for a single utterance.
Captures the centering configuration at one point in the discourse:
- Cf: Forward-looking centers (entities mentioned, ranked by salience)
- Cb: Backward-looking center (what the utterance is “about”)
- Cp: Preferred center (predicted focus for next utterance)
§Example
use anno::discourse::centering::{CenteringState, ForwardCenter};
let state = CenteringState::new(0)
.with_cf(vec![
ForwardCenter::new(1, "John", 1.0),
ForwardCenter::new(2, "Mary", 0.8),
]);
// Cp is automatically set to the highest-ranked Cf
assert_eq!(state.cp, Some(1));
// Check if an entity is mentioned
assert!(state.mentions(1));
assert!(!state.mentions(99));Fields§
§utterance_idx: usizeIndex of this utterance in the discourse (0-based).
cf: Vec<ForwardCenter>Forward-looking centers, ranked by effective salience (highest first). These are the entities mentioned in this utterance that could become the Cb of the next utterance.
cb: Option<u64>Backward-looking center — the most salient entity from the previous
utterance that is realized in this utterance. None for discourse-initial
utterances or when no entity carries over.
cp: Option<u64>Preferred center — the highest-ranked member of Cf. This predicts what the next utterance is likely to be about.
transition: CenteringTransitionTransition from previous utterance
recency_scores: HashMap<u64, f64>Recency-weighted salience scores (entity_id -> score) This implements CT+recency from Jiang et al. (2022)
Implementations§
Source§impl CenteringState
impl CenteringState
Sourcepub fn new(utterance_idx: usize) -> CenteringState
pub fn new(utterance_idx: usize) -> CenteringState
Create a new centering state.
Sourcepub fn with_cf(self, cf: Vec<ForwardCenter>) -> CenteringState
pub fn with_cf(self, cf: Vec<ForwardCenter>) -> CenteringState
Set forward-looking centers.
Sourcepub fn mentioned_entities(&self) -> Vec<u64>
pub fn mentioned_entities(&self) -> Vec<u64>
Get entity IDs mentioned in this utterance.
Sourcepub fn mentions(&self, entity_id: u64) -> bool
pub fn mentions(&self, entity_id: u64) -> bool
Check if an entity is mentioned in this utterance.
Sourcepub fn get_fc(&self, entity_id: u64) -> Option<&ForwardCenter>
pub fn get_fc(&self, entity_id: u64) -> Option<&ForwardCenter>
Get the forward center for an entity.
Sourcepub fn coherence_score(&self) -> f64
pub fn coherence_score(&self) -> f64
Get coherence score for this state.
Trait Implementations§
Source§impl Clone for CenteringState
impl Clone for CenteringState
Source§fn clone(&self) -> CenteringState
fn clone(&self) -> CenteringState
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 CenteringState
impl Debug for CenteringState
Source§impl Default for CenteringState
impl Default for CenteringState
Source§fn default() -> CenteringState
fn default() -> CenteringState
Source§impl<'de> Deserialize<'de> for CenteringState
impl<'de> Deserialize<'de> for CenteringState
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CenteringState, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CenteringState, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for CenteringState
impl Serialize for CenteringState
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 CenteringState
impl RefUnwindSafe for CenteringState
impl Send for CenteringState
impl Sync for CenteringState
impl Unpin for CenteringState
impl UnsafeUnpin for CenteringState
impl UnwindSafe for CenteringState
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