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) -> Self
pub fn new(text: impl Into<String>, start: usize, end: usize) -> Self
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,
) -> Self
pub fn with_head( text: impl Into<String>, start: usize, end: usize, head_start: usize, head_end: usize, ) -> Self
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,
) -> Self
pub fn with_type( text: impl Into<String>, start: usize, end: usize, mention_type: MentionType, ) -> Self
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.