
Get a table's contents from a Grobid <table> node
Source: R/import-grobid.R
dot-tei_table_contents.RdGrobid renders a table as <row>/<cell> elements, with a cols attribute
on a cell that spans several columns (GroBid's own equivalent of an HTML
colspan). Reads the header as one or more leading rows and every
following row as data (see below), expanding a spanning cell's text across
the columns it covers (the same grid-alignment approach .stat_table_parse () uses for JASP/jamovi colspans in R/stat-tables.R), so a header cell
that spans two data columns still lines up with both of them rather than
shifting everything after it.
Value
a list of character vectors, list(headers_row, ...data_rows) (the
shape inst/schema/paper.json's table.contents declares), or NULL
when the node is absent or has no rows
Details
Grobid's <row>/<cell> structure makes no header/data distinction at all
(unlike HTML's <th>/<td>) — but a real table's header can genuinely
span SEVERAL leading rows (a super-header naming a group of columns, a
sub-header, then the actual column names — confirmed against a real corpus
paper's regression table: "Association with mean reappraisal" / "" /
"\(\beta\)01 (SE)", three leading rows before any data). Treating only the first
<row> as the header (as an earlier version of this function did) reads
the REAL column names as if they were a data row, and scans genuine data as
if it were headers. The leading rows are instead scanned from the top:
every row whose cells are MOSTLY non-numeric (prose/blank, the shape a
header or super-header row has) is folded into the header, stopping at the
first row that looks like real data (mostly numeric/bracket/dash cells) —
mirroring .stat_table_parse()'s own "last distinct-label row is the real
header" heuristic, adapted for Grobid's lack of <th>. Folded header rows
are joined per column with " / " (so "Association with" / "mean
reappraisal" / "\(\beta\)01 (SE)" becomes one combined column name), which keeps
the super-header's grouping information rather than discarding it.
Ragged rows (a row with fewer/more cells than the header — GroBid's PDF-layout table detection is imperfect) are padded/truncated to the header's width rather than erroring, so one malformed row does not lose the rest of the table.