Skip to main content
Version: latest

agrag.common.data_models.document.Unit

Bases: BaseModel

One piece of content in a section, such as a paragraph or a table.

Attributes:

  • kind (UnitKind) – The kind of content.
  • text (str) – The text of the unit. For a table or figure, the caption, or an empty string when it has none.
  • char_start (int | None) – The start character offset of the unit in the document text. A text source sets this field. A source that has no text offsets leaves it empty.
  • char_end (int | None) – The end character offset of the unit, exclusive. Set together with char_start.
  • pages (list[PageSpan]) – The pages and boxes the unit covers. A source with page layout sets this field.
  • caption (str | None) – The caption of a table or figure.
  • rows (list[list[str]]) – The cell text of a table, row by row. A spanned cell repeats its text in every slot it covers. Empty for other kinds.
  • header_rows (int) – The number of leading rows of a table that are headers. Zero when the source does not mark them; see header_row_count.

caption​

caption: str | None = None

char_end​

char_end: int | None = None

char_start​

char_start: int | None = None

header​

header: list[str]

Return the column names of a table, one for each column.

The names come from the first header_row_count rows, so the first row supplies them for every table format when the source marks no header rows. Chunk rendering uses these names, and ingestion stores them as the Table node columns. Empty when the table has no rows. A spanned header cell repeats its text in every slot it covers, so each column keeps each text once.

header_row_count​

header_row_count: int

Return how many leading rows of a table form its header.

The count is header_rows. When the source marks no header rows, the first row is the header for every table format, so the count is at least 1.

header_rows​

header_rows: int = Field(default=0, ge=0)

kind​

kind: UnitKind

pages​

pages: list[PageSpan] = Field(default_factory=list)

rows​

rows: list[list[str]] = Field(default_factory=list)

text​

text: str