[WIP] Proposal: Dynaword bundle layout (data.parquet + metadata.parquet)

#129

Work in progress — a proposal for discussion, not for merge yet. Commit 2 (Hub config cutover) must only be applied together with the migration of all sources; until then, review commit 1 on its own.

Proposal: Dynaword bundle layout for the next version of Polish Dynaword

Base: main at ca786ff. Commits: 3b4476f (accept the bundle layout alongside the legacy shards), 85bce52 (Hub config cutover).

1. Goal

Every source in Polish Dynaword should have the same layout as in Danish Dynaword: a separate file with the text, a separate file with the provenance of every record, and a datasheet with a YAML header. Record provenance (address, license, author) should be part of the dataset, not a side JSONL file that cannot be loaded together with the data. The upload recipe in dynaword-pipeline already produces this layout, so sources contributed through Fabryka Track would land in the repository without conversion.

2. Current contract (main)

  • data/<key>/<key>.parquet: 8 columns id, text, source, added, created, token_count, license, author (src/normalize_schema.py, SCHEMA), enforced by src/test_uniform_schema.py for every data/*/*.parquet.
  • data/<key>/<key>.attribution.jsonl (LFS, optional): record provenance in a free per-source shape, e.g. id, url, license, license_evidence, text_sha256, transformations.
  • data/<key>/<key>.stats.json: document, token and character counts; the source of all totals.
  • data/<key>/<key>.md: datasheet without a YAML header; the date added is on a - **Added:** YYYY-MM-DD line.
  • created: free text, e.g. 2002-2026, 2011-12-24, 2026-05-25, unknown.
  • README: one Hub config, data/*/*.parquet.

3. Proposed layout

data/<key>/
├── data.parquet        id, text, source, added, created, token_count
├── metadata.parquet    id, license, author, source_ref, attribution, quality_warnings
├── <key>.md            datasheet with a YAML header
├── <key>.stats.json    unchanged
└── <key>.license-evidence.json   unchanged
  • data.parquet has exactly the Danish SampleSchema (6 columns).
  • metadata.parquet has one row for every row of data.parquet, in the same order, joined on id. source_ref is the record's address (URI), attribution holds the remaining provenance evidence as JSON text, and quality_warnings holds sorted, comma-separated labels.
  • created is a date pair YYYY-MM-DD, YYYY-MM-DD; an unknown start is 0001-01-01.
  • The datasheet has a YAML header (pretty_name, language: [pl], license, domains) and the sections of the Danish template.
  • README has two Hub configs: default over data/*/data.parquet and metadata over data/*/metadata.parquet.

A synthetic 40-record example produced by the recipe was used for the checks below; it is not part of this PR.

4. Differences

Area Now Proposal Consequence
Data files one <key>.parquet data.parquet + metadata.parquet the Hub shows two tables instead of one
license, author columns in the data columns in metadata.parquet filtering by license needs a join on id
Record provenance <key>.attribution.jsonl, per-source shape source_ref + attribution in metadata.parquet one shape for all sources, readable by datasets
created free text date pair descriptive values must be translated by hand
Datasheet no YAML, Added line Danish-style YAML header test_added_dates accepts both, because a card without an Added line passes
quality_warnings none labels from the recipe new field, empty for existing sources
Hub config data/*/*.parquet default and metadata change only in the release that migrates all sources

5. Changes in this PR

  1. 3b4476f accepts the new layout alongside the old one:
    • src/normalize_schema.py: DATA_SCHEMA, METADATA_SCHEMA, shard_path();
    • src/test_uniform_schema.py: checks both bundle schemas and row-by-row id alignment, and rejects a corpus that mixes both layouts;
    • src/test_added_dates.py: reads data.parquet or <key>.parquet;
    • src/migrate_to_bundle.py with tests: converts an existing source without touching its files;
    • AGENTS.md: describes the layout and the single-release cutover.
  2. 85bce52 switches the Hub config in README and in the src/make_docs.py template, which would otherwise restore the old one on regeneration. Apply this commit only together with the migration of all sources.

Tests (python3 -m pytest src/, Python 3.12, requirements-dev.txt, with the LFS data checked out):

  • main (ca786ff): 1022 passed, 0 failed.
  • This branch: 1034 passed, 0 failed (12 new tests).
  • A copy of the repo whose data/ holds only the synthetic example bundle: all generic (non-per-source) tests pass except test_stale_shards_are_registered_shards, which fails only because the copy lacks the other sources.
  • The same copy with one legacy source added fails test_a_source_ships_one_layout_and_the_corpus_does_not_mix_them, as intended.

6. Migrating existing sources

src/migrate_to_bundle.py data/<key> --out <dir> for each source:

  • writes the 6 columns to data.parquet, and license and author to metadata.parquet;
  • takes source_ref from the record's url field (or source_ref, canonical_url, source_url) in <key>.attribution.jsonl, and writes the rest of the record as JSON into attribution;
  • converts created: a year, a year range and a single date become a date pair; unknown and empty become 0001-01-01, <added>. Any other value is rejected instead of guessed.

What this does not cover:

  • The converter has not been run on the real sources yet.
  • Some sources have a descriptive created in the registry, e.g. 2018-2024 (book publication metadata proxy). If such values also appear in the rows, the converter rejects them and they need a per-source decision.
  • The repo has 28 per-source contract tests (src/test_<key>_contract.py); 25 of them read parquet and 27 refer to the license. They must be rewritten for the new layout in the migration release, ideally through a shared helper that joins both files.
  • src/build_dynaword.py writes <key>.parquet (it must be switched over, or the converter run after the build). src/pattern_frequency_report.py reads data/*/*.parquet, so after migration it would also pick up metadata.parquet, which has no text column. src/render_sample.py would show only the 6 columns of data.parquet, without the license and author that AGENTS.md requires in a PR sample.
  • Hand-written datasheets need a YAML header added.
  • <key>.attribution.jsonl files become redundant after migration. Removing them from the repository is a separate decision, because the LFS history remains.

7. Open questions

  1. Should license and author also stay in data.parquet (8 columns as today), so filtering by license does not need a join? This departs from the Danish SampleSchema.
  2. Is 0001-01-01 acceptable as the unknown start of created, or is an empty field better?
  3. Should attribution remain JSON text, or get a fixed, typed shape shared by all sources?
  4. Should the migration ship in a single release (the mixed-layout test enforces this), or should the repository keep both layouts for a while in separate Hub configs?
  5. Who rewrites the 28 contract tests and the tools listed in section 6?

🤖 Generated with Claude Code

Publish this branch
This branch is in draft mode, publish it to be able to merge.

Sign up or log in to comment