| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- Pipe Result
- ==============
- .. admonition:: Tip
- :class: tip
- Please first navigate to :doc:`tutorial/pipeline` to get an initial understanding of how the pipeline works; this will help in understanding the content of this section.
- The **PipeResult** class is a container for storing pipeline processing results and implements a series of methods related to these results, such as draw_layout, draw_span.
- Checkout :doc:`../api/pipe_operators` for more details about **PipeResult**
- Structure Definitions
- -------------------------------
- **some_pdf_middle.json**
- +----------------+--------------------------------------------------------------+
- | Field Name | Description |
- | | |
- +================+==============================================================+
- | pdf_info | list, each element is a dict representing the parsing result |
- | | of each PDF page, see the table below for details |
- +----------------+--------------------------------------------------------------+
- | \_ | ocr \| txt, used to indicate the mode used in this |
- | parse_type | intermediate parsing state |
- | | |
- +----------------+--------------------------------------------------------------+
- | \_version_name | string, indicates the version of magic-pdf used in this |
- | | parsing |
- | | |
- +----------------+--------------------------------------------------------------+
- **pdf_info**
- Field structure description
- +-------------------------+------------------------------------------------------------+
- | Field | Description |
- | Name | |
- +=========================+============================================================+
- | preproc_blocks | Intermediate result after PDF preprocessing, not yet |
- | | segmented |
- +-------------------------+------------------------------------------------------------+
- | layout_bboxes | Layout segmentation results, containing layout direction |
- | | (vertical, horizontal), and bbox, sorted by reading order |
- +-------------------------+------------------------------------------------------------+
- | page_idx | Page number, starting from 0 |
- | | |
- +-------------------------+------------------------------------------------------------+
- | page_size | Page width and height |
- | | |
- +-------------------------+------------------------------------------------------------+
- | \_layout_tree | Layout tree structure |
- | | |
- +-------------------------+------------------------------------------------------------+
- | images | list, each element is a dict representing an img_block |
- +-------------------------+------------------------------------------------------------+
- | tables | list, each element is a dict representing a table_block |
- +-------------------------+------------------------------------------------------------+
- | interline_equation | list, each element is a dict representing an |
- | | interline_equation_block |
- | | |
- +-------------------------+------------------------------------------------------------+
- | discarded_blocks | List, block information returned by the model that needs |
- | | to be dropped |
- | | |
- +-------------------------+------------------------------------------------------------+
- | para_blocks | Result after segmenting preproc_blocks |
- | | |
- +-------------------------+------------------------------------------------------------+
- In the above table, ``para_blocks`` is an array of dicts, each dict
- representing a block structure. A block can support up to one level of
- nesting.
- **block**
- The outer block is referred to as a first-level block, and the fields in
- the first-level block include:
- +------------------------+-------------------------------------------------------------+
- | Field | Description |
- | Name | |
- +========================+=============================================================+
- | type | Block type (table|image) |
- +------------------------+-------------------------------------------------------------+
- | bbox | Block bounding box coordinates |
- +------------------------+-------------------------------------------------------------+
- | blocks | list, each element is a dict representing a second-level |
- | | block |
- +------------------------+-------------------------------------------------------------+
- There are only two types of first-level blocks: “table” and “image”. All
- other blocks are second-level blocks.
- The fields in a second-level block include:
- +----------------------+----------------------------------------------------------------+
- | Field | Description |
- | Name | |
- +======================+================================================================+
- | | Block type |
- | type | |
- +----------------------+----------------------------------------------------------------+
- | | Block bounding box coordinates |
- | bbox | |
- +----------------------+----------------------------------------------------------------+
- | | list, each element is a dict representing a line, used to |
- | lines | describe the composition of a line of information |
- +----------------------+----------------------------------------------------------------+
- Detailed explanation of second-level block types
- ================== ======================
- type Description
- ================== ======================
- image_body Main body of the image
- image_caption Image description text
- table_body Main body of the table
- table_caption Table description text
- table_footnote Table footnote
- text Text block
- title Title block
- interline_equation Block formula
- ================== ======================
- **line**
- The field format of a line is as follows:
- +---------------------+----------------------------------------------------------------+
- | Field | Description |
- | Name | |
- +=====================+================================================================+
- | | Bounding box coordinates of the line |
- | bbox | |
- +---------------------+----------------------------------------------------------------+
- | spans | list, each element is a dict representing a span, used to |
- | | describe the composition of the smallest unit |
- +---------------------+----------------------------------------------------------------+
- **span**
- +---------------------+-----------------------------------------------------------+
- | Field | Description |
- | Name | |
- +=====================+===========================================================+
- | bbox | Bounding box coordinates of the span |
- +---------------------+-----------------------------------------------------------+
- | type | Type of the span |
- +---------------------+-----------------------------------------------------------+
- | content | Text spans use content, chart spans use img_path to store |
- | \| | the actual text or screenshot path information |
- | img_path | |
- +---------------------+-----------------------------------------------------------+
- The types of spans are as follows:
- ================== ==============
- type Description
- ================== ==============
- image Image
- table Table
- text Text
- inline_equation Inline formula
- interline_equation Block formula
- ================== ==============
- **Summary**
- A span is the smallest storage unit for all elements.
- The elements stored within para_blocks are block information.
- The block structure is as follows:
- First-level block (if any) -> Second-level block -> Line -> Span
- .. _example-1:
- example
- ^^^^^^^
- .. code:: json
- {
- "pdf_info": [
- {
- "preproc_blocks": [
- {
- "type": "text",
- "bbox": [
- 52,
- 61.956024169921875,
- 294,
- 82.99800872802734
- ],
- "lines": [
- {
- "bbox": [
- 52,
- 61.956024169921875,
- 294,
- 72.0000228881836
- ],
- "spans": [
- {
- "bbox": [
- 54.0,
- 61.956024169921875,
- 296.2261657714844,
- 72.0000228881836
- ],
- "content": "dependent on the service headway and the reliability of the departure ",
- "type": "text",
- "score": 1.0
- }
- ]
- }
- ]
- }
- ],
- "layout_bboxes": [
- {
- "layout_bbox": [
- 52,
- 61,
- 294,
- 731
- ],
- "layout_label": "V",
- "sub_layout": []
- }
- ],
- "page_idx": 0,
- "page_size": [
- 612.0,
- 792.0
- ],
- "_layout_tree": [],
- "images": [],
- "tables": [],
- "interline_equations": [],
- "discarded_blocks": [],
- "para_blocks": [
- {
- "type": "text",
- "bbox": [
- 52,
- 61.956024169921875,
- 294,
- 82.99800872802734
- ],
- "lines": [
- {
- "bbox": [
- 52,
- 61.956024169921875,
- 294,
- 72.0000228881836
- ],
- "spans": [
- {
- "bbox": [
- 54.0,
- 61.956024169921875,
- 296.2261657714844,
- 72.0000228881836
- ],
- "content": "dependent on the service headway and the reliability of the departure ",
- "type": "text",
- "score": 1.0
- }
- ]
- }
- ]
- }
- ]
- }
- ],
- "_parse_type": "txt",
- "_version_name": "0.6.1"
- }
- Pipeline Result
- ------------------
- .. code:: python
- from magic_pdf.pdf_parse_union_core_v2 import pdf_parse_union
- from magic_pdf.operators.pipes import PipeResult
- from magic_pdf.data.dataset import Dataset
- res = pdf_parse_union(*args, **kwargs)
- res['_parse_type'] = PARSE_TYPE_OCR
- res['_version_name'] = __version__
- if 'lang' in kwargs and kwargs['lang'] is not None:
- res['lang'] = kwargs['lang']
- dataset : Dataset = some_dataset # not real dataset
- pipeResult = PipeResult(res, dataset)
- some_pdf_layout.pdf
- ~~~~~~~~~~~~~~~~~~~
- Each page layout consists of one or more boxes. The number at the top
- left of each box indicates its sequence number. Additionally, in
- ``layout.pdf``, different content blocks are highlighted with different
- background colors.
- .. figure:: ../_static/image/layout_example.png
- :alt: layout example
- layout example
- some_pdf_spans.pdf
- ~~~~~~~~~~~~~~~~~~
- All spans on the page are drawn with different colored line frames
- according to the span type. This file can be used for quality control,
- allowing for quick identification of issues such as missing text or
- unrecognized inline formulas.
- .. figure:: ../_static/image/spans_example.png
- :alt: spans example
- spans example
|