Skip to main content

Block

Struct Block 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§kind: BlockKind

What this block is.

§page: usize

0-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: String

The 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: usize

Position 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: bool

Whether 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

Source

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§

Source§

impl Clone for Block

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Block

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more