zettelkasten.tables_common¶
zettelkasten.tables_common ¶
Shared foundation for the synthesis-matrix engine (see :mod:zettelkasten.tables).
Mechanically split out of tables.py: constants, the _RowScope dataclass,
column/cell/member builders, normalizers and other leaf helpers used across the
other tables_* submodules. Import surface is preserved by re-export from
zettelkasten.tables.
normalize_row_axis ¶
Validate + normalize a table's row-axis descriptor to a canonical dict.
Shape: {"kind": "source"|"note"|"tag"|"note_type"|"group", "ref": str,
"include": [str]}. A missing / malformed descriptor falls back to the
historical source axis, so every legacy table (which has no row_axis)
keeps its one-row-per-source behavior unchanged. include curates which
auto-listed values become rows (empty = all).
A group axis additionally carries the aggregation controls
(strategy/relation/direction/apex/instruction). These keys
are emitted ONLY for group so every other axis keeps its exact historical
three-key shape (callers and stored tables compare on it).
Source code in zettelkasten/tables_common.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
normalize_matrix_view ¶
Validate + normalize a spine's MATRIX view config (the tree → grid flatten).
A spine is a structure TREE (§11.3); the matrix is one 2-axis rendering of it — a small config picks which tree cut is the COLUMNS axis and whether a column's cell rolls up its subtree:
cols_level(int | None) — thecomponent-ofdepth whose structure nodes become columns (apex = 0, top-level dimensions = 1, …).None(the default) means "every materialized dimension is its own column", which reproduces the historical flat depth-1 grid exactly — so an org with nomatrix_viewbehaves identically to before V2b.rollup(bool, default True) — when set, a column node's cell AGGREGATES its descendants' members (the confirmed §11.3 rollup). A flat spine has no descendants, so this is a no-op there.
The grid is a VIEW CONFIG over the tree, not the storage; the tree itself
(nodes + component-of edges + spine-member edges) is the source of
truth. It is applied by :func:build_matrix (the column-axis pivot via
:func:_pivot_columns_for_matrix_view + the rolled-up cell membership in
:func:gather_rows) and also read back directly via :func:spine_readback_matrix.
Source code in zettelkasten/tables_common.py
normalize_columns ¶
Validate + normalize a table's column list to canonical dicts.
Each column carries key (unique), label, type (render/summary
semantics), backing (how it fills), ref (the schema tag / note type /
CCC slot it reads), and prompt (the extraction instruction for a
prompt backing). Unknown values fall back to safe defaults so a slightly
malformed client payload still produces a usable table.
RELABEL-KEY CONTRACT (§11.4): a column's key is its DURABLE identity — a
promoted spine keys the dimension node's source['node_id'] on it, so the
key must survive a relabel for the node (and its spine-member edges +
overlay corrections) to survive. This function PRESERVES an explicitly-supplied
key and only slugs one from the label as a last resort when none is
given; callers relabeling a column MUST send its existing key back so a
label change never silently re-mints the key (and thus the durable node).
Source code in zettelkasten/tables_common.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
compute_synthesis ¶
Per-column mechanical summary (counts / ranges / coverage) — no LLM.
For categorical columns: value counts. For numeric: count/min/max/mean. For
everything else: fill coverage (how many rows are non-[GAP]). The optional
AI narrative is layered on top via :func:generate_column_synthesis.