Skip to main content

Location

Enum Location 

Source
pub enum Location {
    Text {
        start: usize,
        end: usize,
    },
    BoundingBox {
        x: f32,
        y: f32,
        width: f32,
        height: f32,
        page: Option<u32>,
    },
    Temporal {
        start_sec: f64,
        end_sec: f64,
        frame: Option<u64>,
    },
    Cuboid {
        center: [f32; 3],
        dimensions: [f32; 3],
        rotation: [f32; 4],
    },
    Genomic {
        contig: String,
        start: u64,
        end: u64,
        strand: Option<char>,
    },
    Discontinuous {
        segments: Vec<(usize, usize)>,
    },
    TextWithBbox {
        start: usize,
        end: usize,
        bbox: Box<Location>,
    },
}
Expand description

A location in some source medium.

This is the universal “localization unit” that enables the isomorphism between vision detection and NER. Both tasks answer “where is it?” just in different coordinate systems.

§Relationship to Span

entity::Span is a simplified subset of Location for the detection layer:

Location variantSpan equivalent
TextSpan::Text
BoundingBoxSpan::BoundingBox
TextWithBboxSpan::Hybrid
Temporalnone
Cuboidnone
Genomicnone
Discontinuousnone (use DiscontinuousSpan)

Use to_span() to convert where possible.

§Design Note

We use an enum rather than a trait to enable:

  • Efficient storage in contiguous arrays
  • Easy serialization
  • Exhaustive matching for safety

Variants§

§

Text

Text span: 1D interval [start, end) in character offsets.

Fields

§start: usize

Start character offset (inclusive)

§end: usize

End character offset (exclusive)

§

BoundingBox

Visual bounding box: 2D rectangle in normalized [0,1] coordinates.

Fields

§x: f32

X coordinate of top-left corner

§y: f32

Y coordinate of top-left corner

§width: f32

Width

§height: f32

Height

§page: Option<u32>

Page number for multi-page documents

§

Temporal

Temporal interval: for audio/video signals.

Fields

§start_sec: f64

Start time in seconds

§end_sec: f64

End time in seconds

§frame: Option<u64>

Optional frame number for video

§

Cuboid

3D cuboid: for LiDAR/point cloud signals.

Fields

§center: [f32; 3]

Center position (x, y, z)

§dimensions: [f32; 3]

Dimensions (width, height, depth)

§rotation: [f32; 4]

Rotation (quaternion: w, x, y, z)

§

Genomic

Genomic interval: 1D interval in sequence coordinates.

Fields

§contig: String

Chromosome/contig identifier

§start: u64

Start position (0-based, inclusive)

§end: u64

End position (0-based, exclusive)

§strand: Option<char>

Strand (+/-)

§

Discontinuous

Discontinuous text span: non-contiguous regions.

Fields

§segments: Vec<(usize, usize)>

Multiple text intervals

§

TextWithBbox

Hybrid: text with visual location (OCR).

Fields

§start: usize

Text start offset

§end: usize

Text end offset

§bbox: Box<Location>

Visual bounding box

Implementations§

Source§

impl Location

Source

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

Create a text location.

Source

pub fn bbox(x: f32, y: f32, width: f32, height: f32) -> Self

Create a bounding box location.

Source

pub const fn modality(&self) -> Modality

Get the modality of this location.

Source

pub fn text_offsets(&self) -> Option<(usize, usize)>

Get text offsets if this is a text location.

Source

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

Check if two locations overlap.

Source

pub fn iou(&self, other: &Self) -> Option<f64>

Calculate IoU (Intersection over Union) for compatible location types.

Returns None if the locations are incompatible (e.g., text vs bbox).

Source§

impl Location

Convert Location to Span where possible.

Not all Location variants have a corresponding Span:

  • Location::TextSpan::Text
  • Location::BoundingBoxSpan::BoundingBox
  • Location::TextWithBboxSpan::Hybrid
  • Location::DiscontinuousNone (use DiscontinuousSpan instead)
  • Location::Temporal, Location::Cuboid, Location::GenomicNone
Source

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

Try to convert this Location to a Span.

Returns None for Location variants that don’t map to Span (Temporal, Cuboid, Genomic, Discontinuous).

Trait Implementations§

Source§

impl Clone for Location

Source§

fn clone(&self) -> Location

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 Location

Source§

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

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

impl Default for Location

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Location

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<&Span> for Location

Source§

fn from(span: &Span) -> Self

Converts to this type from the input type.
Source§

impl From<Span> for Location

Source§

fn from(span: Span) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Location

Source§

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

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 StructuralPartialEq for Location

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