Datasets:
Separate source PRs from releases; add render_sample.py (#42)
Browse files- Separate source PRs from releases; add render_sample.py (1a89e023850ce2b269ebcd50310d4870eca85972)
.gitattributes
CHANGED
|
@@ -59,6 +59,6 @@ data/samorzad_gov_pl/*.jsonl filter=lfs diff=lfs merge=lfs -text
|
|
| 59 |
# Video files - compressed
|
| 60 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 61 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 62 |
-
|
| 63 |
-
data/
|
| 64 |
-
data/
|
|
|
|
| 59 |
# Video files - compressed
|
| 60 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 61 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
# Per-source audit trails: one rule for all sources, so source PRs don't edit this file
|
| 63 |
+
data/*/*.attribution.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
data/*/*.decisions.jsonl filter=lfs diff=lfs merge=lfs -text
|
AGENTS.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
# AGENTS.md
|
| 2 |
|
| 3 |
Guidance for agents and contributors adding a source and cutting a release.
|
| 4 |
-
Read this before opening a PR
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
## How the docs are actually maintained
|
| 8 |
|
|
@@ -54,6 +55,24 @@ answer was yes or no.
|
|
| 54 |
text, positive token counts, uniform source/license, stats-file consistency).
|
| 55 |
Run `python3 -m pytest src/` before committing.
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
## What the PR must show
|
| 58 |
|
| 59 |
These two are not optional — they are the difference between a source a reviewer
|
|
@@ -64,7 +83,31 @@ example other contributors will copy.
|
|
| 64 |
(or truncated ones), verbatim, so a reviewer can see at a glance what kind of
|
| 65 |
text this actually is — prose, transcripts, boilerplate, OCR noise, HTML
|
| 66 |
leftovers. Include the metadata columns too, not just `text`. Don't make the
|
| 67 |
-
reviewer download a parquet to find out.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
2. **Provenance and licensing, written out in the datasheet (`data/<key>/<key>.md`)
|
| 70 |
and summarized in the PR description:**
|
|
@@ -119,6 +162,10 @@ What a fetcher should do to `text` before writing the `.jsonl.zst`:
|
|
| 119 |
parquet is written (frozen regex ∪ model; placeholders `[PII]` / `[Telefon]`).
|
| 120 |
Names of public officials acting in an official capacity are not PII and
|
| 121 |
should stay — removing them would gut parliamentary and judicial sources.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
Two rules about all of the above:
|
| 124 |
|
|
@@ -129,11 +176,13 @@ Two rules about all of the above:
|
|
| 129 |
Include a handful of before/after excerpts in the PR — this is the fastest way
|
| 130 |
for a reviewer to see whether normalization ate real content.
|
| 131 |
|
| 132 |
-
## Cut the release (
|
| 133 |
|
|
|
|
|
|
|
| 134 |
1. In `src/make_docs.py`: bump `VERSION` and `RELEASE_DATE`. Add a row for the new
|
| 135 |
-
version to the version table and a row for
|
| 136 |
-
(both are literal rows in the template).
|
| 137 |
2. Regenerate the phrase-frequency report and charts (registry-independent — it
|
| 138 |
globs `data/*/*.parquet`):
|
| 139 |
```bash
|
|
|
|
| 1 |
# AGENTS.md
|
| 2 |
|
| 3 |
Guidance for agents and contributors adding a source and cutting a release.
|
| 4 |
+
Read this before opening a PR. Source PRs and releases are separate: a source PR
|
| 5 |
+
adds one source with `release: None`; the maintainer later cuts one release that
|
| 6 |
+
bumps the version and docs for every source merged since the last one.
|
| 7 |
|
| 8 |
## How the docs are actually maintained
|
| 9 |
|
|
|
|
| 55 |
text, positive token counts, uniform source/license, stats-file consistency).
|
| 56 |
Run `python3 -m pytest src/` before committing.
|
| 57 |
|
| 58 |
+
### Keep the PR to your source
|
| 59 |
+
|
| 60 |
+
Many source PRs are open at once, and each one that touches shared files
|
| 61 |
+
conflicts with the others. A source PR changes only:
|
| 62 |
+
|
| 63 |
+
- `data/<key>/*`, `src/fetch_<key>.py` / `src/clean_<key>.py`,
|
| 64 |
+
`src/test_<key>_contract.py`;
|
| 65 |
+
- **one** new entry in `src/sources.py`, with `release: None`;
|
| 66 |
+
- your entry appended to `artifacts/source_findings.md`.
|
| 67 |
+
|
| 68 |
+
It does **not** touch `README.md`, `CHANGELOG.md`, `VERSION`/`RELEASE_DATE` in
|
| 69 |
+
`src/make_docs.py`, the phrase-frequency report, `AGENTS.md`, or other sources'
|
| 70 |
+
fetchers — those change in the release commit (below) or in their own PR.
|
| 71 |
+
`.gitattributes` already LFS-tracks `data/*/*.attribution.jsonl` and
|
| 72 |
+
`*.decisions.jsonl`; do not add per-file lines.
|
| 73 |
+
Commit with LF line endings — a CRLF `sources.py` shows as a whole-file rewrite
|
| 74 |
+
and conflicts with every other PR. Rebase onto `main` before asking for review.
|
| 75 |
+
|
| 76 |
## What the PR must show
|
| 77 |
|
| 78 |
These two are not optional — they are the difference between a source a reviewer
|
|
|
|
| 83 |
(or truncated ones), verbatim, so a reviewer can see at a glance what kind of
|
| 84 |
text this actually is — prose, transcripts, boilerplate, OCR noise, HTML
|
| 85 |
leftovers. Include the metadata columns too, not just `text`. Don't make the
|
| 86 |
+
reviewer download a parquet to find out — and a linked `.sample.jsonl` is not
|
| 87 |
+
a substitute: on the Hub it renders as one escaped line per document.
|
| 88 |
+
|
| 89 |
+
Generate it from the built shard and paste the output into the PR description:
|
| 90 |
+
```bash
|
| 91 |
+
python3 src/render_sample.py data/<key>/<key>.parquet -n 3
|
| 92 |
+
```
|
| 93 |
+
Each document is a fenced block — metadata as `key: value` lines, a blank
|
| 94 |
+
line, then the text with its real line breaks, truncated with `[…]`:
|
| 95 |
+
````
|
| 96 |
+
```
|
| 97 |
+
id: sejm_interpellations_2388
|
| 98 |
+
source: sejm_interpellations
|
| 99 |
+
added: 2026-07-19
|
| 100 |
+
token_count: 415
|
| 101 |
+
license: public-domain (official documents)
|
| 102 |
+
author: Daniel Milewski
|
| 103 |
+
|
| 104 |
+
Szanowny Panie Ministrze,
|
| 105 |
+
|
| 106 |
+
latem 2022 roku na podlaskiej części granicy z Białorusią ukończono […]
|
| 107 |
+
```
|
| 108 |
+
````
|
| 109 |
+
Pick rows that show the typical document; if the source has distinct
|
| 110 |
+
document types (question vs reply, article vs talk page), show one of each.
|
| 111 |
|
| 112 |
2. **Provenance and licensing, written out in the datasheet (`data/<key>/<key>.md`)
|
| 113 |
and summarized in the PR description:**
|
|
|
|
| 162 |
parquet is written (frozen regex ∪ model; placeholders `[PII]` / `[Telefon]`).
|
| 163 |
Names of public officials acting in an official capacity are not PII and
|
| 164 |
should stay — removing them would gut parliamentary and judicial sources.
|
| 165 |
+
A source scrubbed some other way may still merge with `release: None`, but it
|
| 166 |
+
is not admitted to a release until its shard has been re-run through NERGAL.
|
| 167 |
+
Say in the datasheet which scrubber ran. Note that `main` is public on the Hub
|
| 168 |
+
whether or not a source is released.
|
| 169 |
|
| 170 |
Two rules about all of the above:
|
| 171 |
|
|
|
|
| 176 |
Include a handful of before/after excerpts in the PR — this is the fastest way
|
| 177 |
for a reviewer to see whether normalization ate real content.
|
| 178 |
|
| 179 |
+
## Cut the release (maintainer, one commit after the source PRs merge)
|
| 180 |
|
| 181 |
+
0. In `src/sources.py`, set `release` on each merged source this release ships
|
| 182 |
+
(check its shard went through NERGAL first).
|
| 183 |
1. In `src/make_docs.py`: bump `VERSION` and `RELEASE_DATE`. Add a row for the new
|
| 184 |
+
version to the version table and a row for each new contributor to the
|
| 185 |
+
Contributors table (both are literal rows in the template).
|
| 186 |
2. Regenerate the phrase-frequency report and charts (registry-independent — it
|
| 187 |
globs `data/*/*.parquet`):
|
| 188 |
```bash
|
data/global_voices/global_voices.attribution.jsonl
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/rock_pollub_pl/rock_pollub_pl.attribution.jsonl
CHANGED
|
@@ -1,8 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
{"author": "Weinper, Katarzyna", "authors": [], "editors": ["Weinper, Katarzyna"], "eisbn": ["978-83-7947-652-7"], "extracted_text": {"bytes": 749850, "extractor": "pdfplumber", "page_count": 324, "page_failures": [], "sha256": "ea82e63ee099d5c4f3fee69434d835da9b3ee5cb0cb50eda15b06309dfa9131a"}, "handle": "20.500.14629/18743", "id": "rock_pollub_pl_903f22e1-a2ab-4231-a402-2bc9535c12f2", "isbn": ["978-83-7947-651-0"], "issued": ["2025"], "landing_url": "https://rock.pollub.pl/entities/publication/903f22e1-a2ab-4231-a402-2bc9535c12f2", "license": "CC-BY-SA-4.0", "license_evidence": {"item": ["CC-BY-SA-4.0"], "pdf_bitstream": ["CC-BY-SA 4.0"]}, "license_policy_url": "https://wpl.pollub.pl/pl/i/Polityka-publikacyjna/20", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "pdf": {"bytes": 11242006, "checksum": {"checkSumAlgorithm": "MD5", "value": "df8dc6047586f20b0a7e5aef3f2ef09a"}, "content_url": "https://rock.pollub.pl/server/api/core/bitstreams/028ebc18-0b71-4cfd-8799-58ca0c40b941/content", "id": "028ebc18-0b71-4cfd-8799-58ca0c40b941", "name": "Wyzwania_Wspolczesnego_9788379476527.pdf", "rights": ["CC-BY-SA 4.0"], "sha256": "899458fc20d68bb3e146cc9d6eef32229c17b1cde5e4629e90a1760bf949e412"}, "publisher": "Politechnika Lubelska", "subtype": ["Monograph"], "text_sha256": "28a7eb8b790116c641427e8ad681942cc058b9f0fac83658e720b875eca33983", "title": "Wyzwania współczesnego publikowania", "transformations": ["pdfplumber page extraction", "Unicode/whitespace normalization", "page-number-only removal", "line-wrap repair", "limited email/labelled-phone redaction"]}
|
| 5 |
-
{"author": "Wlaź, Paweł", "authors": ["Wlaź, Paweł"], "editors": [], "eisbn": ["978-83-7947-640-4"], "extracted_text": {"bytes": 179984, "extractor": "pdfplumber", "page_count": 124, "page_failures": [], "sha256": "bf16f790920e72199c9eddbe70922d941e89b8defd35e6c35e5401c304e5b9db"}, "handle": "20.500.14629/18557", "id": "rock_pollub_pl_0e26bff5-e51a-4d36-9524-fdef6e3e6ab7", "isbn": ["978-83-7947-639-8"], "issued": ["2025"], "landing_url": "https://rock.pollub.pl/entities/publication/0e26bff5-e51a-4d36-9524-fdef6e3e6ab7", "license": "CC-BY-SA-4.0", "license_evidence": {"item": ["CC-BY-SA-4.0"], "pdf_bitstream": ["CC-BY-SA 4.0"]}, "license_policy_url": "https://wpl.pollub.pl/pl/i/Polityka-publikacyjna/20", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "pdf": {"bytes": 3165127, "checksum": {"checkSumAlgorithm": "MD5", "value": "afb17dc3ebbcbed87c25aebc7c007ff7"}, "content_url": "https://rock.pollub.pl/server/api/core/bitstreams/a8f29876-c98e-4feb-be00-cd21541930ca/content", "id": "a8f29876-c98e-4feb-be00-cd21541930ca", "name": "Symulacje_MC_9788379476404.pdf", "rights": ["CC-BY-SA 4.0"], "sha256": "64d4df1dc99517c83a4a6d99ec1d613d8debc9a17e08e944fb564c26e172e454"}, "publisher": "Politechnika Lubelska", "subtype": ["Handbook"], "text_sha256": "aee9a79540fd25dd17e81c4f9eda021b45630fb722c3c1a293582384d8c72db5", "title": "Symulacje Monte Carlo. Teoria i zastosowania", "transformations": ["pdfplumber page extraction", "Unicode/whitespace normalization", "page-number-only removal", "line-wrap repair", "limited email/labelled-phone redaction"]}
|
| 6 |
-
{"author": "Kłosowski, Grzegorz", "authors": ["Kłosowski, Grzegorz"], "editors": [], "eisbn": ["978-83-7947-628-2"], "extracted_text": {"bytes": 420051, "extractor": "pdfplumber", "page_count": 223, "page_failures": [], "sha256": "6c036af4551875a4db4a2b97d765ca2279e6cf55654f5822d79d13656fa4b921"}, "handle": "20.500.14629/18428", "id": "rock_pollub_pl_032a14e5-5c8e-4153-9cf7-2dfd9e361e6d", "isbn": ["978-83-7947-627-5"], "issued": ["2025"], "landing_url": "https://rock.pollub.pl/entities/publication/032a14e5-5c8e-4153-9cf7-2dfd9e361e6d", "license": "CC-BY-SA-4.0", "license_evidence": {"item": ["CC-BY-SA-4.0"], "pdf_bitstream": ["CC-BY-SA 4.0"]}, "license_policy_url": "https://wpl.pollub.pl/pl/i/Polityka-publikacyjna/20", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "pdf": {"bytes": 44067073, "checksum": {"checkSumAlgorithm": "MD5", "value": "549565d7f323947cc6630a8db3fc97a2"}, "content_url": "https://rock.pollub.pl/server/api/core/bitstreams/99e482b2-ba18-42f0-82aa-4c47a831d550/content", "id": "99e482b2-ba18-42f0-82aa-4c47a831d550", "name": "Zastosowanie_uczenia_9788379476282.pdf", "rights": ["CC-BY-SA 4.0"], "sha256": "7879b3aaf589868bea40ec5af397e0a459785de150bd66ba51b3b63283111bc5"}, "publisher": "Politechnika Lubelska", "subtype": ["Monograph"], "text_sha256": "ed64bc684dd91eb110bcfe32b242560a33310a127c4c6eca060cc53c6adc2060", "title": "Zastosowanie uczenia maszynowego do obrazowania stanu zawilgocenia murów z wykorzystaniem tomografii impedancyjnej", "transformations": ["pdfplumber page extraction", "Unicode/whitespace normalization", "page-number-only removal", "line-wrap repair", "limited email/labelled-phone redaction"]}
|
| 7 |
-
{"author": "Zienkiewicz, Tadeusz; Zienkiewicz, Konrad", "authors": ["Zienkiewicz, Tadeusz", "Zienkiewicz, Konrad"], "editors": ["Zienkiewicz, Tadeusz"], "eisbn": ["978-83-7947-662-6"], "extracted_text": {"bytes": 1022411, "extractor": "pdfplumber", "page_count": 393, "page_failures": [], "sha256": "a9df4a08b74e654091b368e7ba1b9d4732bcaa2448301a2a65105b3655e636ef"}, "handle": "20.500.14629/18744", "id": "rock_pollub_pl_da87b1d3-7018-46fa-81bd-380f0780a1b3", "isbn": [], "issued": ["2025"], "landing_url": "https://rock.pollub.pl/entities/publication/da87b1d3-7018-46fa-81bd-380f0780a1b3", "license": "CC-BY-SA-4.0", "license_evidence": {"item": ["CC-BY-SA-4.0"], "pdf_bitstream": ["CC-BY-SA 4.0"]}, "license_policy_url": "https://wpl.pollub.pl/pl/i/Polityka-publikacyjna/20", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "pdf": {"bytes": 3569880, "checksum": {"checkSumAlgorithm": "MD5", "value": "bf6b100ecbc6a12ae37dbfe4be44d09d"}, "content_url": "https://rock.pollub.pl/server/api/core/bitstreams/8086c994-dd9a-449f-aeb9-e4edd06cbd95/content", "id": "8086c994-dd9a-449f-aeb9-e4edd06cbd95", "name": "Zarzadzanie_Wspolpraca_Instytucji__9788379476626.pdf", "rights": ["CC-BY-SA 4.0"], "sha256": "c75ae222fb9362de9ed22e9f45550c3443d0617d31bb0befbee0c891347aa803"}, "publisher": "Politechnika Lubelska", "subtype": ["Monograph"], "text_sha256": "30863bfbfde1222ee44de8c1a8815a72ff9febec8a8b62ef85a6075d78358529", "title": "Zarządzanie współpracą instytucji państwa z diasporą. Przegląd teorii, analiza porównawcza wybranych państw", "transformations": ["pdfplumber page extraction", "Unicode/whitespace normalization", "page-number-only removal", "line-wrap repair", "limited email/labelled-phone redaction"]}
|
| 8 |
-
{"author": "Montusiewicz, Jerzy; Dziedzic, Krzysztof; Barszcz, Marcin; Urzędowski, Arkadiusz", "authors": ["Montusiewicz, Jerzy", "Dziedzic, Krzysztof", "Barszcz, Marcin", "Urzędowski, Arkadiusz"], "editors": [], "eisbn": [], "extracted_text": {"bytes": 182501, "extractor": "pdfplumber", "page_count": 153, "page_failures": [], "sha256": "09794f0d77aa5ec1fa00b027703d4e0d620778b5d53bcac2799da6963cb29b3b"}, "handle": "20.500.14629/211", "id": "rock_pollub_pl_a257b1ce-1af7-4dfc-ae38-ec67ef877689", "isbn": ["978–83–7947–568–1"], "issued": ["2023"], "landing_url": "https://rock.pollub.pl/entities/publication/a257b1ce-1af7-4dfc-ae38-ec67ef877689", "license": "CC-BY-SA-4.0", "license_evidence": {"item": ["CC-BY-SA-4.0"], "pdf_bitstream": ["CC-BY-SA 4.0"]}, "license_policy_url": "https://wpl.pollub.pl/pl/i/Polityka-publikacyjna/20", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "pdf": {"bytes": 12577248, "checksum": {"checkSumAlgorithm": "MD5", "value": "55c99ba8c2962c763c847386deabd2ca"}, "content_url": "https://rock.pollub.pl/server/api/core/bitstreams/75143e05-fdbc-4af3-ad39-07ad2cfa0c15/content", "id": "75143e05-fdbc-4af3-ad39-07ad2cfa0c15", "name": "AutoCAD2023.pdf", "rights": ["CC-BY-SA 4.0"], "sha256": "e6831f3e9c05555815d61e97a146b878fc49bf992374411fda4ded824f31d8ee"}, "publisher": "Politechnika Lubelska", "subtype": ["Handbook"], "text_sha256": "bebc8b603695bdbfebc2a136c26f4f1aab5428cee5243fe6781102d2c3821514", "title": "Komputerowa grafika inżynierska. Ćwiczenia do programu AutoCAD 2023", "transformations": ["pdfplumber page extraction", "Unicode/whitespace normalization", "page-number-only removal", "line-wrap repair", "limited email/labelled-phone redaction"]}
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f402aa851f338dd7661310e886a140f551ce58d8cd42a04034104204c7b9ea9
|
| 3 |
+
size 13279
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/rock_pollub_pl/rock_pollub_pl.decisions.jsonl
CHANGED
|
@@ -1,8 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
{"characters": 716909, "id": "rock_pollub_pl_903f22e1-a2ab-4231-a402-2bc9535c12f2", "language": "pl", "language_confidence": 1.0, "letter_ratio": 0.8020348468215631, "reason": "include", "replacement_characters": 0, "selected": true}
|
| 5 |
-
{"characters": 152666, "id": "rock_pollub_pl_0e26bff5-e51a-4d36-9524-fdef6e3e6ab7", "language": "pl", "language_confidence": 1.0, "letter_ratio": 0.7383372853156565, "reason": "include", "replacement_characters": 0, "selected": true}
|
| 6 |
-
{"characters": 391855, "id": "rock_pollub_pl_032a14e5-5c8e-4153-9cf7-2dfd9e361e6d", "language": "pl", "language_confidence": 1.0, "letter_ratio": 0.8003240994755714, "reason": "include", "replacement_characters": 1, "selected": true}
|
| 7 |
-
{"characters": 959348, "id": "rock_pollub_pl_da87b1d3-7018-46fa-81bd-380f0780a1b3", "language": "pl", "language_confidence": 1.0, "letter_ratio": 0.8103201340910702, "reason": "include", "replacement_characters": 0, "selected": true}
|
| 8 |
-
{"characters": 168819, "id": "rock_pollub_pl_a257b1ce-1af7-4dfc-ae38-ec67ef877689", "language": "pl", "language_confidence": 1.0, "letter_ratio": 0.7856935534507372, "reason": "include", "replacement_characters": 0, "selected": true}
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e60fe6b5610cf9453b432ffb4e5cb3630bf3b313a15e5042ea0a176feb1ea6d7
|
| 3 |
+
size 1880
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/render_sample.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Render a few parquet rows as readable markdown for a PR description.
|
| 2 |
+
|
| 3 |
+
Usage: python3 src/render_sample.py data/<key>/<key>.parquet [-n 3] [--max-chars 800]
|
| 4 |
+
|
| 5 |
+
Each document becomes a fenced block: metadata as `key: value` lines, a blank
|
| 6 |
+
line, then the text with real newlines, truncated with `[…]`.
|
| 7 |
+
"""
|
| 8 |
+
import argparse
|
| 9 |
+
import random
|
| 10 |
+
import re
|
| 11 |
+
|
| 12 |
+
import pyarrow.parquet as pq
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def sample_rows(path, n, seed=0):
|
| 16 |
+
"""n rows from distinct random row groups (seeded), so a 2B-token shard isn't read whole."""
|
| 17 |
+
pf = pq.ParquetFile(path)
|
| 18 |
+
if pf.num_row_groups == 0 or n <= 0:
|
| 19 |
+
return []
|
| 20 |
+
rng = random.Random(seed)
|
| 21 |
+
groups = rng.sample(range(pf.num_row_groups), min(n, pf.num_row_groups))
|
| 22 |
+
per_group = -(-n // len(groups)) # ceil: few row groups -> several rows each
|
| 23 |
+
rows = []
|
| 24 |
+
for g in sorted(groups):
|
| 25 |
+
batch = pf.read_row_group(g).to_pylist()
|
| 26 |
+
rows += rng.sample(batch, min(per_group, len(batch)))
|
| 27 |
+
return rows[:n]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def truncate(text, max_chars):
|
| 31 |
+
text = text.strip()
|
| 32 |
+
if len(text) <= max_chars:
|
| 33 |
+
return text
|
| 34 |
+
cut = text[:max_chars]
|
| 35 |
+
space = max(cut.rfind(" "), cut.rfind("\n"))
|
| 36 |
+
return (cut[:space] if space > 0 else cut).rstrip() + " […]"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def fmt_value(v):
|
| 40 |
+
if isinstance(v, (list, tuple)):
|
| 41 |
+
return ", ".join(fmt_value(x) for x in v)
|
| 42 |
+
if hasattr(v, "isoformat"):
|
| 43 |
+
return v.isoformat()
|
| 44 |
+
return str(v)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def render_doc(row, max_chars):
|
| 48 |
+
meta = [f"{k}: {fmt_value(v)}" for k, v in row.items() if k != "text"]
|
| 49 |
+
body = "\n".join(meta) + "\n\n" + truncate(row.get("text") or "", max_chars)
|
| 50 |
+
longest = max((len(m) for m in re.findall(r"`+", body)), default=0)
|
| 51 |
+
fence = "`" * max(3, longest + 1)
|
| 52 |
+
return f"{fence}\n{body}\n{fence}"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def render(path, n=3, max_chars=800, seed=0):
|
| 56 |
+
return "\n\n".join(render_doc(r, max_chars) for r in sample_rows(path, n, seed))
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 61 |
+
ap.add_argument("parquet")
|
| 62 |
+
ap.add_argument("-n", type=int, default=3)
|
| 63 |
+
ap.add_argument("--max-chars", type=int, default=800)
|
| 64 |
+
ap.add_argument("--seed", type=int, default=0)
|
| 65 |
+
a = ap.parse_args()
|
| 66 |
+
print(render(a.parquet, a.n, a.max_chars, a.seed))
|
src/test_render_sample.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contract for render_sample: readable, deterministic PR-description samples."""
|
| 2 |
+
import datetime
|
| 3 |
+
import sys
|
| 4 |
+
import tempfile
|
| 5 |
+
import unittest
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import pyarrow as pa
|
| 9 |
+
import pyarrow.parquet as pq
|
| 10 |
+
|
| 11 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 12 |
+
|
| 13 |
+
from render_sample import render, render_doc, sample_rows, truncate
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def write_parquet(path, n, row_group_size):
|
| 17 |
+
table = pa.table({
|
| 18 |
+
"id": [f"src_{i}" for i in range(n)],
|
| 19 |
+
"text": [f"Akapit pierwszy {i}.\n\nAkapit drugi." for i in range(n)],
|
| 20 |
+
"source": ["src"] * n,
|
| 21 |
+
"added": [datetime.date(2026, 7, 19)] * n,
|
| 22 |
+
"created": [["2023-11-15", "2026-09-03"]] * n,
|
| 23 |
+
"token_count": list(range(n)),
|
| 24 |
+
})
|
| 25 |
+
pq.write_table(table, path, row_group_size=row_group_size)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class RenderSampleTest(unittest.TestCase):
|
| 29 |
+
def setUp(self):
|
| 30 |
+
self.tmp = tempfile.TemporaryDirectory()
|
| 31 |
+
self.path = Path(self.tmp.name) / "src.parquet"
|
| 32 |
+
|
| 33 |
+
def tearDown(self):
|
| 34 |
+
self.tmp.cleanup()
|
| 35 |
+
|
| 36 |
+
def test_block_layout_matches_pr24_format(self):
|
| 37 |
+
row = {"id": "x", "text": "Line one.\n\nLine two.", "added": datetime.date(2026, 7, 19),
|
| 38 |
+
"created": ["2023-11-15", "2026-09-03"], "token_count": 5}
|
| 39 |
+
self.assertEqual(
|
| 40 |
+
render_doc(row, 800),
|
| 41 |
+
"```\nid: x\nadded: 2026-07-19\ncreated: 2023-11-15, 2026-09-03\ntoken_count: 5\n\n"
|
| 42 |
+
"Line one.\n\nLine two.\n```",
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
def test_real_newlines_not_escaped(self):
|
| 46 |
+
write_parquet(self.path, 5, 2)
|
| 47 |
+
out = render(self.path, n=1)
|
| 48 |
+
self.assertIn("\n\nAkapit drugi.", out)
|
| 49 |
+
self.assertNotIn("\\n", out)
|
| 50 |
+
|
| 51 |
+
def test_truncates_on_word_boundary(self):
|
| 52 |
+
self.assertEqual(truncate("alpha beta gamma", 12), "alpha beta […]")
|
| 53 |
+
self.assertEqual(truncate("short", 12), "short")
|
| 54 |
+
self.assertEqual(truncate("x" * 20, 5), "xxxxx […]")
|
| 55 |
+
|
| 56 |
+
def test_fence_outgrows_backticks_in_text(self):
|
| 57 |
+
out = render_doc({"text": "code: ```py\nx```"}, 800)
|
| 58 |
+
self.assertTrue(out.startswith("````\n") and out.endswith("\n````"))
|
| 59 |
+
|
| 60 |
+
def test_deterministic_and_bounded(self):
|
| 61 |
+
write_parquet(self.path, 50, 10)
|
| 62 |
+
self.assertEqual(render(self.path, n=3, seed=1), render(self.path, n=3, seed=1))
|
| 63 |
+
self.assertEqual(len(sample_rows(self.path, 3)), 3)
|
| 64 |
+
ids = [r["id"] for r in sample_rows(self.path, 3)]
|
| 65 |
+
self.assertEqual(len(set(ids)), 3)
|
| 66 |
+
|
| 67 |
+
def test_fewer_row_groups_than_n(self):
|
| 68 |
+
write_parquet(self.path, 6, 6) # one row group
|
| 69 |
+
self.assertEqual(len(sample_rows(self.path, 4)), 4)
|
| 70 |
+
|
| 71 |
+
def test_n_larger_than_table(self):
|
| 72 |
+
write_parquet(self.path, 2, 1)
|
| 73 |
+
self.assertEqual(len(sample_rows(self.path, 10)), 2)
|
| 74 |
+
|
| 75 |
+
def test_empty_parquet(self):
|
| 76 |
+
pq.write_table(pa.table({"id": pa.array([], pa.string()), "text": pa.array([], pa.string())}), self.path)
|
| 77 |
+
self.assertEqual(render(self.path), "")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
unittest.main()
|