Skip to main content

Mention

Struct Mention 

Source
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: String

The mention text (surface form).

§start: usize

Start character offset (inclusive, 0-indexed).

§end: usize

End 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

Source

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.

Source

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 11
Source

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);
Source

pub fn overlaps(&self, other: &Mention) -> bool

True if spans share any characters: [0,5) overlaps [3,8).

Source

pub fn span_matches(&self, other: &Mention) -> bool

True if spans are identical: same start AND end.

Source

pub fn len(&self) -> usize

Span length in characters. Returns 0 if end <= start.

Source

pub fn is_empty(&self) -> bool

True if span has zero length.

Source

pub fn span_id(&self) -> (usize, usize)

(start, end) tuple for use in hash sets and comparisons.

Trait Implementations§

Source§

impl Clone for Mention

Source§

fn clone(&self) -> Mention

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mention

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Mention

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Mention

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&Entity> for Mention

Source§

fn from(entity: &Entity) -> Self

Converts to this type from the input type.
Source§

impl Hash for Mention

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Mention

Source§

fn eq(&self, other: &Mention) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Mention

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Mention

Source§

impl StructuralPartialEq for Mention

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,