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) -> Span
pub fn bbox(x: f32, y: f32, width: f32, height: f32) -> Span
Create a bounding box span with normalized coordinates.
Sourcepub fn bbox_on_page(x: f32, y: f32, width: f32, height: f32, page: u32) -> Span
pub fn bbox_on_page(x: f32, y: f32, width: f32, height: f32, page: u32) -> Span
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Span, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Span, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Span
impl Serialize for Span
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 Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnsafeUnpin for Span
impl UnwindSafe for Span
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