Skip to main content

DiscontinuousSpan

Struct DiscontinuousSpan 

Source
pub struct DiscontinuousSpan { /* private fields */ }
Expand description

A discontinuous span representing non-contiguous entity mentions.

Some entities span multiple non-adjacent text regions:

  • “severe [pain] in the [abdomen]” → “severe abdominal pain”
  • “the [president] … [Obama]” → coreference

This is required for:

  • Medical NER: Anatomical modifiers separated from findings
  • Legal NER: Parties referenced across clauses
  • W2NER: Word-word relation grids that detect discontinuous entities

§Offset Unit (CRITICAL)

DiscontinuousSpan uses character offsets (Unicode scalar value indices), consistent with Entity::start / Entity::end and anno::core::grounded::Location.

This is intentionally not byte offsets. If you have byte offsets (from regex, str::find, tokenizers, etc.), convert them to character offsets first (see anno::offset::SpanConverter in the anno crate).

§Example

use anno_core::DiscontinuousSpan;

// "severe pain in the abdomen" where "severe" modifies "pain"
// but they're separated by other words
let span = DiscontinuousSpan::new(vec![
    0..6,   // "severe"
    12..16, // "pain"
]);

assert_eq!(span.num_segments(), 2);
assert!(span.is_discontinuous());

Implementations§

Source§

impl DiscontinuousSpan

Source

pub fn new(segments: Vec<Range<usize>>) -> Self

Create a new discontinuous span from segments.

Segments are sorted and validated (no overlaps).

Source

pub fn contiguous(start: usize, end: usize) -> Self

Create from a single contiguous span.

Source

pub fn num_segments(&self) -> usize

Number of segments.

Source

pub fn is_discontinuous(&self) -> bool

True if this spans multiple non-adjacent regions.

Source

pub fn is_contiguous(&self) -> bool

True if this is a single contiguous span.

Source

pub fn segments(&self) -> &[Range<usize>]

Get the segments.

Source

pub fn bounding_range(&self) -> Option<Range<usize>>

Get the overall bounding range (start of first to end of last).

Source

pub fn total_len(&self) -> usize

Total character length (sum of all segments).

Source

pub fn extract_text(&self, text: &str, separator: &str) -> String

Extract text from each segment and join with separator.

Source

pub fn contains(&self, pos: usize) -> bool

Check if a character position falls within any segment.

§Arguments
  • pos - Character offset to check (Unicode scalar value index)
§Returns

true if the character position falls within any segment of this span.

Source

pub fn to_span(&self) -> Option<Span>

Convert to a regular Span (uses bounding range, loses discontinuity info).

Trait Implementations§

Source§

impl Clone for DiscontinuousSpan

Source§

fn clone(&self) -> DiscontinuousSpan

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 DiscontinuousSpan

Source§

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

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

impl<'de> Deserialize<'de> for DiscontinuousSpan

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 From<Range<usize>> for DiscontinuousSpan

Source§

fn from(range: Range<usize>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for DiscontinuousSpan

Source§

fn eq(&self, other: &DiscontinuousSpan) -> 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 DiscontinuousSpan

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 DiscontinuousSpan

Source§

impl StructuralPartialEq for DiscontinuousSpan

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, 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>,