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 variant | Span equivalent |
|---|---|
Text | Span::Text |
BoundingBox | Span::BoundingBox |
TextWithBbox | Span::Hybrid |
Temporal | none |
Cuboid | none |
Genomic | none |
Discontinuous | none (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.
BoundingBox
Visual bounding box: 2D rectangle in normalized [0,1] coordinates.
Fields
Temporal
Temporal interval: for audio/video signals.
Fields
Cuboid
3D cuboid: for LiDAR/point cloud signals.
Fields
Genomic
Genomic interval: 1D interval in sequence coordinates.
Fields
Discontinuous
Discontinuous text span: non-contiguous regions.
TextWithBbox
Hybrid: text with visual location (OCR).
Implementations§
Source§impl Location
impl Location
Source§impl Location
Convert Location to Span where possible.
impl Location
Convert Location to Span where possible.
Not all Location variants have a corresponding Span:
Location::Text→Span::TextLocation::BoundingBox→Span::BoundingBoxLocation::TextWithBbox→Span::HybridLocation::Discontinuous→None(useDiscontinuousSpaninstead)Location::Temporal,Location::Cuboid,Location::Genomic→None
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Location
impl<'de> Deserialize<'de> for Location
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Location, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Location, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Location
impl Serialize for Location
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 StructuralPartialEq for Location
Auto Trait Implementations§
impl Freeze for Location
impl RefUnwindSafe for Location
impl Send for Location
impl Sync for Location
impl Unpin for Location
impl UnsafeUnpin for Location
impl UnwindSafe for Location
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<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 more