Kreuzberg.Table (kreuzberg v4.0.4)

View Source

Structure representing an extracted table from a document.

Contains table structure information including cells, rows, columns, and optional metadata like markdown representation or cell properties.

Fields

  • :cells - Two-dimensional list of table cells [[cell1, cell2], ...]
  • :rows - Alternative representation: list of row structures
  • :columns - Optional list of column metadata
  • :headers - Optional list of header cell values
  • :markdown - Optional markdown representation of the table
  • :html - Optional HTML representation of the table
  • :page_number - Page number where table appears (if available)
  • :bounds - Optional bounding box coordinates [x1, y1, x2, y2]

Examples

iex> table = %Kreuzberg.Table{
...>   cells: [["Name", "Age"], ["Alice", "30"], ["Bob", "25"]],
...>   headers: ["Name", "Age"],
...>   markdown: "| Name | Age |\n|------|-----|\n| Alice | 30 |"
...> }
iex> table.headers
["Name", "Age"]

Summary

Functions

Returns the number of columns in the table.

Creates a new Table struct from a map.

Returns the number of rows in the table.

Converts a Table struct to a map.

Types

cell_value()

@type cell_value() :: String.t() | number() | map() | list() | nil

t()

@type t() :: %Kreuzberg.Table{
  bounds: [number()] | nil,
  cells: [[cell_value()]] | nil,
  columns: [map()] | nil,
  headers: [String.t()] | nil,
  html: String.t() | nil,
  markdown: String.t() | nil,
  page_number: integer() | nil,
  rows: [map()] | nil
}

Functions

column_count(table)

@spec column_count(t()) :: integer()

Returns the number of columns in the table.

Parameters

  • table - A Table struct

Returns

The number of columns, or 0 if cells are not available.

Examples

iex> table = %Kreuzberg.Table{cells: [["A", "B"], ["1", "2"]]}
iex> Kreuzberg.Table.column_count(table)
2

from_map(data)

@spec from_map(map()) :: t()

Creates a new Table struct from a map.

Converts a plain map (typically from NIF/Rust) into a proper struct.

Parameters

  • data - A map containing table fields

Returns

A Table struct with matching fields populated.

Examples

iex> table_map = %{
...>   "cells" => [["A", "B"], ["1", "2"]],
...>   "headers" => ["A", "B"]
...> }
iex> Kreuzberg.Table.from_map(table_map)
%Kreuzberg.Table{
  cells: [["A", "B"], ["1", "2"]],
  headers: ["A", "B"]
}

row_count(table)

@spec row_count(t()) :: integer()

Returns the number of rows in the table.

Parameters

  • table - A Table struct

Returns

The number of rows, or 0 if cells are not available.

Examples

iex> table = %Kreuzberg.Table{cells: [["A", "B"], ["1", "2"]]}
iex> Kreuzberg.Table.row_count(table)
2

to_map(table)

@spec to_map(t()) :: map()

Converts a Table struct to a map.

Useful for serialization and passing to external systems.

Parameters

  • table - A Table struct

Returns

A map with string keys representing all fields.

Examples

iex> table = %Kreuzberg.Table{
...>   cells: [["A", "B"]],
...>   headers: ["A", "B"]
...> }
iex> Kreuzberg.Table.to_map(table)
%{
  "cells" => [["A", "B"]],
  "headers" => ["A", "B"],
  "rows" => nil,
  ...
}