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
Sourcepub fn text_offsets(&self) -> Option<(usize, usize)>
pub fn text_offsets(&self) -> Option<(usize, usize)>
Get text offsets if this is a text 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