#[non_exhaustive]pub struct Block {
pub kind: BlockKind,
pub page: usize,
pub bbox: [f64; 4],
pub text: String,
pub spans: Vec<TextSpan>,
pub index: usize,
pub continues_previous: bool,
pub confidence: Option<f64>,
pub grid: Option<GridDoubt>,
/* private fields */
}Expand description
One block of a document’s structured text: what a caller chunks, cites or embeds.
The fields are the ones the serializers consume (#572): the kind, where it is, what it says, what it was made of, and where it falls in the reading order of the whole document.
#[non_exhaustive], DECIDED AFTER TWO FIELDS HAD ALREADY BROKEN IT (codex on
#1977 and #1989). This is a type callers READ: extract_blocks returns it and
nothing outside this crate has a reason to build one. But it was an exhaustive
public struct in a 1.0.0 crate, so confidence and then grid each made every
downstream literal fail to compile – and the learned work has more of both
coming, one per model that has something to say about a block. Closing it now
means the next field costs nobody anything.
Construct one with Block::new and set the rest, which is what this crate’s
own examples do.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.kind: BlockKindWhat this block is.
page: usize0-based page index the block was drawn on.
bbox: [f64; 4]Bounding box in PDF user space, [x0, y0, x1, y1] with y up and
y0 < y1. The union of the glyph boxes of every span in the block.
text: StringThe block’s text, with the line breaks of the measure removed: lines are joined by a space, and a word the typesetter broke across a line is put back together.
spans: Vec<TextSpan>Every span the block is made of, in the order the page DRAWS them: left to right, line by line.
Visual and not logical, which matters on a line of Arabic or Hebrew: the
spans carry the geometry, and the geometry is visual, so extraction
leaves them where the page put them and reorders only the text
(TextBlock::text, #436). text above is therefore the logical
reading and this is not, and a caller rebuilding the text from the spans
of a right-to-left block has to reorder them itself (codex, round 1).
index: usizePosition of this block in the document’s reading order, counted from the first block of the first page.
The running heads a document repeats are not in that order: they carry
the numbers after the last block of the body, which is where
[crate::reading_order] puts them (#571).
continues_previous: boolWhether the block continues the one before it in the reading order, because the page broke a paragraph in two (#571).
A RELATION AND NOT A MERGE. The two halves are set on two pages, so one
paragraph there has two boxes and two page numbers, and a merged block
could state neither: Self::bbox is one rectangle and Self::page
is one page. The serializers join what this marks – crate::markdown
writes the two as one paragraph – and a caller chunking the document
joins it the same way, with the geometry of both halves still in front
of it.
confidence: Option<f64>How sure the learned model is of Self::kind, between 0 and 1, or
None where no model spoke about this block (#624).
WHAT None MEANS, because it is not “we are unsure”. A block that no
model has an opinion about carries the heuristics’ verdict, and the
heuristics do not produce a probability – they produce a decision. So
None is “nobody measured this”, and a caller that wants to route the
doubtful cases somewhere must treat it as unknown rather than as low.
Today the only model on master that answers is the list-item one of
#599, so a paragraph that model considered carries its probability and a
heading carries None until #599’s heading model lands. The value is the
model’s own probability for the decision it made, not a calibrated
confidence over all kinds: 0.9 on a list item means the item model put
0.9 on “this is an item”, and says nothing about the alternative kinds.
AND IT IS THE PROBABILITY OF THE DECISION THAT PRODUCED THIS BLOCK’S KIND,
which is not always the one the block began with (codex on #1977). A block
the opens model cuts into three items has three pieces whose kinds come
from three different lines’ probabilities, and each piece reports its own.
A block whose kind the heuristics decided carries None even where a model
ran on it and agreed, because a number about a decision nobody acted on
would read as a number about this kind.
grid: Option<GridDoubt>What the heuristic builder had to go on when it found this cell’s table,
or None for a block that is not a table cell (#574).
See GridDoubt: five facts rather than a score, and a property of the
table repeated on each of its cells.
Implementations§
Source§impl Block
impl Block
Sourcepub fn new(
kind: BlockKind,
page: usize,
bbox: [f64; 4],
text: String,
index: usize,
) -> Self
pub fn new( kind: BlockKind, page: usize, bbox: [f64; 4], text: String, index: usize, ) -> Self
A block with the fields every kind has, and the rest left at their defaults: no confidence, no grid evidence, not a continuation.
The way to build one from outside this crate, now that Block is
#[non_exhaustive]. The five arguments are the ones no block can do
without – a kind, a page, a box, its text and its place in the reading
order – and everything else is set afterwards on the returned value.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Block
impl RefUnwindSafe for Block
impl Send for Block
impl Sync for Block
impl Unpin for Block
impl UnsafeUnpin for Block
impl UnwindSafe for Block
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
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
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