pub enum Span {
Text {
start: usize,
end: usize,
},
BoundingBox {
x: f32,
y: f32,
width: f32,
height: f32,
page: Option<u32>,
},
Hybrid {
start: usize,
end: usize,
bbox: Box<Span>,
},
}Expand description
A span locator for text and visual modalities.
Span is a simplified subset of grounded::Location designed for
the detection layer (Entity). It covers the most common cases:
- Text offsets (traditional NER)
- Bounding boxes (visual document understanding)
- Hybrid (OCR with both text and visual location)
§Relationship to Location
Span variant | Location equivalent |
|---|---|
Text | Location::Text |
BoundingBox | Location::BoundingBox |
Hybrid | Location::TextWithBbox |
For modalities not covered by Span (temporal, cuboid, genomic, discontinuous),
use Location directly via the canonical Signal → Track → Identity pipeline.
§Conversion
Span → Location: Always succeeds viaLocation::from(&span)Location → Span: Uselocation.to_span(), returnsNonefor unsupported variants
Variants§
Text
Text span with character offsets (start, end).
Offsets are Unicode scalar value indices (what text.chars() counts),
consistent with Entity.start/end and grounded::Location::Text.
BoundingBox
Visual bounding box (normalized 0.0-1.0 coordinates) For ColPali: image patch locations
Fields
Hybrid
Hybrid: both text and visual location (for OCR-verified extraction)
Implementations§
Source§impl Span
impl Span
Sourcepub fn bbox(x: f32, y: f32, width: f32, height: f32) -> Self
pub fn bbox(x: f32, y: f32, width: f32, height: f32) -> Self
Create a bounding box span with normalized coordinates.
Sourcepub fn bbox_on_page(x: f32, y: f32, width: f32, height: f32, page: u32) -> Self
pub fn bbox_on_page(x: f32, y: f32, width: f32, height: f32, page: u32) -> Self
Create a bounding box with page number.
Sourcepub const fn text_offsets(&self) -> Option<(usize, usize)>
pub const fn text_offsets(&self) -> Option<(usize, usize)>
Get text offsets if available.