pub struct Mention {
pub text: String,
pub start: usize,
pub end: usize,
pub head_start: Option<usize>,
pub head_end: Option<usize>,
pub entity_type: Option<String>,
pub mention_type: Option<MentionType>,
}Expand description
A single mention (text span) that may corefer with other mentions.
Mentions are comparable by span position, not by text content. Two mentions with identical text at different positions are distinct.
§Character vs Byte Offsets
start and end are character offsets, not byte offsets.
For “北京 Beijing”, the character offsets are:
- “北” = 0..1 (but 3 bytes in UTF-8)
- “京” = 1..2 (but 3 bytes)
- “ “ = 2..3
- “Beijing” = 3..10
Use text.chars().skip(start).take(end - start).collect() to extract.
§Head Span
The head_start/head_end fields mark the syntactic head for head-match
evaluation (used in CEAF-e, LEA metrics). In “the former president of France”,
the head is “president” - the noun that determines agreement.
Fields§
§text: StringThe mention text (surface form).
start: usizeStart character offset (inclusive, 0-indexed).
end: usizeEnd character offset (exclusive).
head_start: Option<usize>Head word start (for head-match metrics like CEAF).
head_end: Option<usize>Head word end.
entity_type: Option<String>Entity type if known (e.g., “PER”, “ORG”).
mention_type: Option<MentionType>Mention category: Pronominal, Proper, Nominal, Zero.
Implementations§
Source§impl Mention
impl Mention
Sourcepub fn new(text: impl Into<String>, start: usize, end: usize) -> Mention
pub fn new(text: impl Into<String>, start: usize, end: usize) -> Mention
Mention::new("John", 0, 4) creates a mention for “John” at characters 0..4.
Offsets are character positions, not byte positions.
Sourcepub fn with_head(
text: impl Into<String>,
start: usize,
end: usize,
head_start: usize,
head_end: usize,
) -> Mention
pub fn with_head( text: impl Into<String>, start: usize, end: usize, head_start: usize, head_end: usize, ) -> Mention
Mention with head span for head-match evaluation.
The head is the syntactic nucleus: in “the former president”, head is “president”.
let m = Mention::with_head("the former president", 0, 20, 11, 20);
assert_eq!(m.head_start, Some(11)); // "president" starts at 11Sourcepub fn with_type(
text: impl Into<String>,
start: usize,
end: usize,
mention_type: MentionType,
) -> Mention
pub fn with_type( text: impl Into<String>, start: usize, end: usize, mention_type: MentionType, ) -> Mention
Mention with type annotation for type-aware evaluation.
let pronoun = Mention::with_type("he", 25, 27, MentionType::Pronominal);
let proper = Mention::with_type("John Smith", 0, 10, MentionType::Proper);Sourcepub fn overlaps(&self, other: &Mention) -> bool
pub fn overlaps(&self, other: &Mention) -> bool
True if spans share any characters: [0,5) overlaps [3,8).
Sourcepub fn span_matches(&self, other: &Mention) -> bool
pub fn span_matches(&self, other: &Mention) -> bool
True if spans are identical: same start AND end.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Mention
impl<'de> Deserialize<'de> for Mention
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Mention, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Mention, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<&RankedMention> for Mention
Convert RankedMention to eval::coref::Mention for evaluation.
impl From<&RankedMention> for Mention
Convert RankedMention to eval::coref::Mention for evaluation.
This enables using mention-ranking output directly in coreference evaluation.
Source§fn from(mention: &RankedMention) -> Self
fn from(mention: &RankedMention) -> Self
Source§impl From<RankedMention> for Mention
impl From<RankedMention> for Mention
Source§fn from(mention: RankedMention) -> Self
fn from(mention: RankedMention) -> Self
Source§impl Serialize for Mention
impl Serialize for Mention
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,
impl Eq for Mention
impl StructuralPartialEq for Mention
Auto Trait Implementations§
impl Freeze for Mention
impl RefUnwindSafe for Mention
impl Send for Mention
impl Sync for Mention
impl Unpin for Mention
impl UnsafeUnpin for Mention
impl UnwindSafe for Mention
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.