zettelkasten.tables_schema_matrix¶
zettelkasten.tables_schema_matrix ¶
Schema fingerprinting + schema-grouped comparison matrix construction.
Mechanically split out of tables.py: column_key_fingerprint (+ the
deprecated spine_schema_fingerprint alias), spine-schema grouping, the
spine_group_matrix producer, and schema/dimension derivation + column
suggestion helpers.
column_key_fingerprint ¶
A spine org's SCHEMA identity: its sorted set of column keys.
Two spines belong to the same schema iff they expose the same dimension-tag set — regardless of per-spine labels or synthesis-graph names. This is the alignment key for grouping independent strands into a matrix.
Source code in zettelkasten/tables_schema_matrix.py
group_spines_by_spine_schema ¶
Group state == 'spine' orgs by schema fingerprint into matrix entries.
Only a fingerprint shared by >= 2 spines becomes a group (a matrix); a
singleton schema stays an individual spine and is NOT grouped. Each group:
{id, fingerprint, label, dimensions, members: [org_id], count}. id is a
deterministic "schema:<hash>" (so the frontend can round-trip it); label
is the members' common apex-title suffix, else a dimension-count fallback.
Source code in zettelkasten/tables_schema_matrix.py
spine_group_matrix ¶
spine_group_matrix(get_graph: GetGraph, localize: 'Callable[[str], str] | None' = None, *, members: list[dict[str, Any]], dim_keys: list[str], title: str = '', with_node_refs: bool = False) -> dict[str, Any]
Build the EPHEMERAL comparison matrix that unites same-schema spines.
Rows = the member spines' apexes (topics); columns = the shared schema
dimensions (dim_keys); each cell carries the topic's dimension-node
synthesized content as value (falling back to the joined evidence titles
when the node has no body yet) plus its rolled-up evidence members for the
drill-down. PURE read, no writes; the output mirrors :func:build_matrix so the
frontend renders it unchanged. Each row also carries spine_ref/org_id so
a click can drill into that topic's own spine.
Source code in zettelkasten/tables_schema_matrix.py
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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
suggest_columns ¶
Propose typed, backed columns, deterministic sources first.
Returns grouped candidates the UI renders as pickable column presets
schemas— each extraction-schema rubric's dimensions becomeschema_tagcolumns (deterministic; e.g. thelit-review-matrixrubric). This is the primary, "free" source.templates/spines—schemassplit by whether the schema declares asynthesisblock: templates are flat column sets, spines also materialize a persistent graph (apex + dimension nodes).note_types— the canonical note-type vocabulary (deterministic).ccc— the CCC slot columns (deterministic).
Every candidate carries a deterministic flag so the UI can show what fills
without an LLM.
Source code in zettelkasten/tables_schema_matrix.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
derive_dimension_tags ¶
Ordered (column, dimension_tag) pairs for the MATERIALIZABLE columns.
THE single source of truth for a spine dimension's tag, shared by BOTH the
spine materializer (organizations._promote_locked stamps this tag on the
materialized dimension NODE) and :func:schema_from_columns (which embeds the
same tag in the org's extraction rubric). Deriving them from one function is
what guarantees the embedded-schema tags are IDENTICAL to the materialized
dimension-node tags — otherwise a promoted spine's schema silently disagrees
with its own graph (the phase-3 silent-loss trap).
Rule: tag = (ref or key).strip() — the column's ref (the dimension tag
it already reads) when present, else its durable key (matching what
build_spine_skeleton keys the node on). Tags are then de-duplicated with a
-2/-3 suffix: two columns sharing a ref would otherwise emit the
same tag, which extraction_schemas.expand_spec rejects (tags must be unique
within a schema — they become note tags). Because the SAME dedup is applied to
the spine nodes (they consume these pairs too), the node tag and the schema tag
move together and can never diverge. The materializable filter mirrors
promotion's: identity/metadata columns and any materialize: false opt-out
are skipped.
EMPTY-TAG RULE: a materializable column whose derived base tag is empty or
whitespace-only (blank ref AND blank key) is SKIPPED entirely. Such a
tag is rejected by extraction_schemas.expand_spec (so the embedded schema
would silently drop it), while the spine materializer would still stamp a
tag='' node — leaving the node and its own embedded schema in disagreement
(the phase-3 silent-loss trap). Skipping here is the shared truth both
consumers see, so the dimension is omitted from BOTH the materialized node set
and the generated schema consistently, rather than half-dropped. On the normal
promote path this skip is now BELT-AND-SUSPENDERS: normalize_columns
guarantees a non-empty key (it strips an explicit key and falls back to the
label slug for a blank/whitespace one), so a normalized column can only reach
the skip via a genuinely blank ref AND key — i.e. an un-normalized /
hand-built column list — which this guard still handles correctly.
Source code in zettelkasten/tables_schema_matrix.py
schema_from_columns ¶
schema_from_columns(columns: list[dict[str, Any]], *, title: str, synthesis_graph: str, attach_relation: str, apex_relation: str, apex_type: str, apex_title: str, row_axis: 'dict[str, Any] | None' = None) -> dict[str, Any]
Generate a RAW extraction-schema spec from a matrix lens's columns.
The inverse of :func:suggest_columns (which derives matrix columns from a
schema's dimensions): this turns the interactive matrix builder's column set
back into a real extraction schema so a promoted spine can embed its own
rubric (design §5 — "the builder's output is reified into a real schema").
Each materializable column becomes one schema dimension. The tag is the
SHARED dimension tag from :func:derive_dimension_tags ((ref or key) with
-2/-3 dedup) — the EXACT tag the spine materializer stamps on the
matching dimension node — so the embedded schema can never diverge from the
materialized graph. Only the ancillary fields differ by backing:
schema_tag—desc= the column'sprompt.note_type—note_type=ref(the note type the scribe writes),desc= the columnlabel.ccc_slot—desc=label or ref.prompt—desc= the columnprompt.
TAG CONTRACT: the tag is (ref or key).strip(), NOT a slug of the human
label. A prompt column (no ref) therefore tags on its durable
key — identical to the spine node's tag — rather than a lossy label slug,
so a relabel never re-keys the dimension. The original label/prompt still
survives as desc. See :func:derive_dimension_tags for the dedup rule.
identity/metadata columns are SKIPPED (they are display fields, not
extraction dimensions) — mirroring promotion's materializable filter; a column
explicitly opting out with materialize: false is skipped too.
The synthesis block makes the schema spine-backed: graph =
synthesis_graph (the apex graph the spine materializes into), the apex
node carries apex_type/apex_title, and dimension_node records
the spine's ACTUAL attach_relation (how member notes wire to a dimension
node) and apex_relation (how a dimension rolls up to the apex). row_axis
is accepted for signature symmetry with the builder's config but is not part
of the generated rubric (the dimension/apex relations come from the spine, not
the row grouping).
Returns a RAW spec ready for :func:extraction_schemas.expand_spec; validates
by expanding it (raising ValueError on a malformed result) — expand_spec
is imported lazily to avoid the tables ↔ extraction_schemas import cycle.
Source code in zettelkasten/tables_schema_matrix.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | |