Datasets:
Add source: sejm_committee_transcripts - full Sejm committee zapis coverage (terms 9-10) (#37)
Browse files- Add source: sejm_committee_transcripts (terms 9-10 committee zapis) (667d9e7f1a64b9cc452c233ef838c1e36df03071)
- artifacts/source_findings.md +31 -0
- data/sejm_committee_transcripts/NOTICE.md +21 -0
- data/sejm_committee_transcripts/sejm_committee_transcripts.attribution.jsonl +3 -0
- data/sejm_committee_transcripts/sejm_committee_transcripts.license-evidence.json +27 -0
- data/sejm_committee_transcripts/sejm_committee_transcripts.md +88 -0
- data/sejm_committee_transcripts/sejm_committee_transcripts.parquet +3 -0
- data/sejm_committee_transcripts/sejm_committee_transcripts.stats.json +19 -0
- src/fetch_sejm_committee_transcripts.py +464 -0
- src/sources.py +25 -0
- src/test_sejm_committee_transcripts_contract.py +131 -0
artifacts/source_findings.md
CHANGED
|
@@ -880,3 +880,34 @@ dedup (the 13 exclusions were metadata-level title/DOI matches only).
|
|
| 880 |
**Lesson** — the per-article license line kept verbatim in the record text makes
|
| 881 |
the grant self-evidencing in the corpus itself — worth copying for other
|
| 882 |
publishers that stamp each article.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 880 |
**Lesson** — the per-article license line kept verbatim in the record text makes
|
| 881 |
the grant self-evidencing in the corpus itself — worth copying for other
|
| 882 |
publishers that stamp each article.
|
| 883 |
+
|
| 884 |
+
---
|
| 885 |
+
|
| 886 |
+
## sejm_committee_transcripts — Sejm committee full transcripts (terms 9–10)
|
| 887 |
+
|
| 888 |
+
**Investigated** — 2026-09-18 (review round 2026-09-28).
|
| 889 |
+
|
| 890 |
+
**Verdict** — `added` (proposed with `release: None`). 653,411 speaker turns /
|
| 891 |
+
166.3M `cl100k_base` tokens of spoken multi-party committee discussion — a
|
| 892 |
+
working register the plenary-only political sources do not cover.
|
| 893 |
+
|
| 894 |
+
**Enumeration** — api.sejm.gov.pl: `GET /sejm/term{n}/committees` and
|
| 895 |
+
`.../sittings`, then `.../sittings/{num}/pdf` for the "pelny zapis" transcripts.
|
| 896 |
+
9,175 term-9/10 sittings known; 8,658 have a zapis PDF upstream, 455 have none,
|
| 897 |
+
62 failed after retries; 7,746 sittings survive joint-sitting dedup.
|
| 898 |
+
|
| 899 |
+
**License evidence** — official parliamentary materials: Copyright Act art. 4(2)
|
| 900 |
+
(<https://eli.gov.pl/api/acts/DU/2025/24/text/O/D20250024.pdf>) + Open Data/PSI
|
| 901 |
+
Act arts. 2(12), 5, 6, 14, 15, 17
|
| 902 |
+
(<https://eli.gov.pl/api/acts/DU/2023/1524/text.html>). No CC grant claimed;
|
| 903 |
+
evidence snapshot in `sejm_committee_transcripts.license-evidence.json`.
|
| 904 |
+
|
| 905 |
+
**Blockers** — none to merge with `release: None`. Before release: NERGAL pass
|
| 906 |
+
(454 pattern redactions cover only e-mail/PESEL/NIP/REGON/labelled phone/IBAN;
|
| 907 |
+
quoted citizens' statements remain), near-dedup vs `dziennik_ustaw`/`eurlex`
|
| 908 |
+
(embedded statute/print quotations), benchmark-overlap check.
|
| 909 |
+
|
| 910 |
+
**Lesson** — `pdftotext -layout` + role-anchored speaker labels reconstruct
|
| 911 |
+
turns well (98.9% of the ASW pilot's audited corrected characters), but it is
|
| 912 |
+
the pilot comparison that makes the reconstruction auditable — keep that step
|
| 913 |
+
for future spoken sources.
|
data/sejm_committee_transcripts/NOTICE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Attribution and license notice
|
| 2 |
+
|
| 3 |
+
Source: Sejm committee full transcripts ("pelny zapis przebiegu posiedzenia"),
|
| 4 |
+
Kancelaria Sejmu RP, https://api.sejm.gov.pl/ -
|
| 5 |
+
`GET /sejm/term{n}/committees/{code}/sittings/{num}/pdf`, terms 9-10.
|
| 6 |
+
|
| 7 |
+
Official parliamentary materials are excluded from copyright by art. 4(2) of the
|
| 8 |
+
Polish Copyright Act (https://eli.gov.pl/api/acts/DU/2025/24/text/O/D20250024.pdf);
|
| 9 |
+
reuse is governed by the Polish Open Data and Reuse of PSI Act, arts. 2(12), 5, 6,
|
| 10 |
+
14, 15, 17 (https://eli.gov.pl/api/acts/DU/2023/1524/text.html). No upstream
|
| 11 |
+
Creative Commons grant is claimed. Per-record `source_url` and `content_sha1` in
|
| 12 |
+
`sejm_committee_transcripts.attribution.jsonl` pin the exact API PDF endpoint and
|
| 13 |
+
transcript fingerprint.
|
| 14 |
+
|
| 15 |
+
Preparation: Piotr Styla with AI assistance. Changes: `pdftotext -layout`
|
| 16 |
+
extraction, page-furniture removal, role-anchored speaker-turn reconstruction,
|
| 17 |
+
soft-hyphenation joining, whitespace normalization, joint-sitting and exact-turn
|
| 18 |
+
deduplication, pattern-based PII redaction (e-mail, checksum-valid
|
| 19 |
+
PESEL/NIP/REGON, labelled phone/fax, IBAN). Not complete anonymization - a
|
| 20 |
+
SlayerLab/NERGAL pass is required before release. No endorsement by the
|
| 21 |
+
Kancelaria Sejmu RP is implied.
|
data/sejm_committee_transcripts/sejm_committee_transcripts.attribution.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d7277bad9abae279cd5b417e6504c9bcb17c832b41281991b2038489a5453f83
|
| 3 |
+
size 267577034
|
data/sejm_committee_transcripts/sejm_committee_transcripts.license-evidence.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"copyright_basis": {
|
| 3 |
+
"article": "4(2)",
|
| 4 |
+
"url": "https://eli.gov.pl/api/acts/DU/2025/24/text/O/D20250024.pdf"
|
| 5 |
+
},
|
| 6 |
+
"license_name": "polish-public-sector-open-statutory-reuse",
|
| 7 |
+
"limitations": [
|
| 8 |
+
"privacy and personal-data exceptions",
|
| 9 |
+
"third-party rights",
|
| 10 |
+
"no Creative Commons grant is asserted"
|
| 11 |
+
],
|
| 12 |
+
"official_source": "https://api.sejm.gov.pl/",
|
| 13 |
+
"provider": "Kancelaria Sejmu RP",
|
| 14 |
+
"reuse_basis": {
|
| 15 |
+
"articles": [
|
| 16 |
+
"2(12)",
|
| 17 |
+
"5",
|
| 18 |
+
"6",
|
| 19 |
+
"14",
|
| 20 |
+
"15",
|
| 21 |
+
"17"
|
| 22 |
+
],
|
| 23 |
+
"url": "https://eli.gov.pl/api/acts/DU/2023/1524/text.html"
|
| 24 |
+
},
|
| 25 |
+
"source_revision": "sejm-committee-transcripts v2 (terms 9+10, full API zapis PDF coverage)",
|
| 26 |
+
"status": "verified 2026-09-18; per-row source_url pins the exact API PDF endpoint"
|
| 27 |
+
}
|
data/sejm_committee_transcripts/sejm_committee_transcripts.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Sejm committee transcripts (terms 9–10) - official parliamentary materials
|
| 2 |
+
|
| 3 |
+
Official committee transcripts ("pelny zapis przebiegu posiedzenia") from the
|
| 4 |
+
Sejm of the Republic of Poland, parsed into attributed speaker turns:
|
| 5 |
+
**653,411 records / 166,310,754 `cl100k_base` tokens / 443,928,915 characters**,
|
| 6 |
+
70 committees, 7,746 sittings, terms 9 and 10.
|
| 7 |
+
|
| 8 |
+
## Origin and license
|
| 9 |
+
|
| 10 |
+
- Origin: Kancelaria Sejmu RP, <https://api.sejm.gov.pl/> -
|
| 11 |
+
`GET /sejm/term{n}/committees/{code}/sittings/{num}/pdf`. Each record pins its
|
| 12 |
+
exact source PDF endpoint in `sejm_committee_transcripts.attribution.jsonl`
|
| 13 |
+
(`source_url`); the per-sitting `content_sha1` fingerprints the transcript body.
|
| 14 |
+
- License: official parliamentary materials are excluded from copyright by
|
| 15 |
+
[art. 4(2) of the Polish Copyright Act](https://eli.gov.pl/api/acts/DU/2025/24/text/O/D20250024.pdf);
|
| 16 |
+
reuse is governed by the
|
| 17 |
+
[Polish Open Data and Reuse of PSI Act, arts. 2(12), 5, 6, 14, 15, 17](https://eli.gov.pl/api/acts/DU/2023/1524/text.html).
|
| 18 |
+
No upstream Creative Commons grant is claimed. Evidence snapshot:
|
| 19 |
+
`sejm_committee_transcripts.license-evidence.json` (verified 2026-09-18;
|
| 20 |
+
limitations: privacy and personal-data exceptions, third-party rights).
|
| 21 |
+
|
| 22 |
+
## What the texts are
|
| 23 |
+
|
| 24 |
+
- **Genre**: official stenographic transcripts of standing-committee sittings -
|
| 25 |
+
bill examinations, ministry and expert Q&A, chair announcements, votes and
|
| 26 |
+
interjections ("Glos z sali"). One record per speaker turn (the whole turn, not
|
| 27 |
+
split further).
|
| 28 |
+
- **Register**: prepared official transcript of spoken Polish - multi-party
|
| 29 |
+
discussion with questions, answers and interruptions, formal address formulas,
|
| 30 |
+
occasional read-out quotations of documents. Not plenary speeches: this is the
|
| 31 |
+
committee working register that the plenary-only `parliamentary` / `sejm_api`
|
| 32 |
+
sources do not contain. Not OCR'd (born-digital PDFs), not machine-translated.
|
| 33 |
+
- **Time span**: sitting dates `2019-11-14` - `2026-09-03` (term 9: 331,411
|
| 34 |
+
records; term 10: 322,000). 11,261 distinct speaker labels
|
| 35 |
+
(role + name as printed in the transcript).
|
| 36 |
+
|
| 37 |
+
## Collection and normalization
|
| 38 |
+
|
| 39 |
+
Every step lives in `src/fetch_sejm_committee_transcripts.py` (assembled from the
|
| 40 |
+
pinned `PiotrSty/sejm-committee-transcripts` pipeline @9efc4e2), so the shard is
|
| 41 |
+
reproducible from the script alone. Requires `pdftotext` (poppler).
|
| 42 |
+
|
| 43 |
+
- **Acquire**: committee and sitting listings cached from the API; zapis PDFs
|
| 44 |
+
downloaded with a per-term manifest. Coverage: 8,658 of 9,175 term-9/10
|
| 45 |
+
sittings have a zapis PDF at source; 455 have none upstream, 62 failed after
|
| 46 |
+
retries.
|
| 47 |
+
- **Extract**: `pdftotext -layout`; page furniture removed (running headers
|
| 48 |
+
"KANCELARIA SEJMU" / "Biuro Komisji Sejmowych" / "PEŁNY ZAPIS ...", page
|
| 49 |
+
numbers and footers); speaker turns reconstructed from role-anchored speaker
|
| 50 |
+
labels (`Poseł`, `Przewodniczący`, `Sekretarz stanu`, `Legislator`,
|
| 51 |
+
`Głos z sali`, ...); body soft-hyphenation joined across line breaks;
|
| 52 |
+
whitespace runs collapsed; turns under 15 characters dropped. Parser validated
|
| 53 |
+
against the earlier ASW-only pilot: recovers 98.9% of the pilot's audited
|
| 54 |
+
corrected character count with per-turn attribution.
|
| 55 |
+
- **PII (which scrubber ran)**: the pattern pass `redact()` in the committed
|
| 56 |
+
script - e-mail -> `[ADRES_EMAIL]`, checksum-valid PESEL/NIP/REGON and IBAN
|
| 57 |
+
candidates -> `[DANE_NUMERY]`, labelled phone/fax -> `[DANE_KONTAKTOWE]`.
|
| 58 |
+
Counted in the shipped shard: **415 redactions** (406 `[ADRES_EMAIL]`, 6
|
| 59 |
+
`[DANE_NUMERY]`, 3 `[DANE_KONTAKTOWE]`; the pipeline's pre-dedup counter read
|
| 60 |
+
454 because it also counted rows later dropped as joint-sitting duplicates).
|
| 61 |
+
This is **not**
|
| 62 |
+
[SlayerLab/NERGAL](https://huggingface.co/SlayerLab/NERGAL): the shard must be
|
| 63 |
+
re-run through NERGAL before it is admitted to a release (it quotes citizens'
|
| 64 |
+
statements and documents). Merge with `release: None` is fine meanwhile.
|
| 65 |
+
- **Dedup**: joint sittings listed under two committee codes are kept once
|
| 66 |
+
(74,117 rows / 912 sittings dropped by per-sitting `content_sha1`); adjacent
|
| 67 |
+
exact duplicate turns (same sitting, speaker and text) dropped (42). No
|
| 68 |
+
cross-source dedup yet (see caveats).
|
| 69 |
+
|
| 70 |
+
## Inclusion argument and caveats
|
| 71 |
+
|
| 72 |
+
What this adds: spoken multi-party committee discussion - questions, answers,
|
| 73 |
+
interjections - a working-register complement to the corpus's plenary and
|
| 74 |
+
written political sources. 166M tokens of it.
|
| 75 |
+
|
| 76 |
+
Caveats: transcripts are the Sejm's official cleaned stenograms, not raw audio;
|
| 77 |
+
quotations of statutes, print and citizen statements are embedded (near-dedup vs
|
| 78 |
+
`dziennik_ustaw` / `eurlex` remains a target integration gate, as does a
|
| 79 |
+
benchmark-overlap check); PII treatment is pattern-based (see above) and quoted
|
| 80 |
+
citizens warrant a NERGAL pass and a spot check before release; 517 sittings are
|
| 81 |
+
missing (455 without an upstream PDF, 62 fetch failures). Training benefit is an
|
| 82 |
+
untested hypothesis.
|
| 83 |
+
|
| 84 |
+
Limitations: speaker labels and role attribution follow the printed transcript
|
| 85 |
+
(preamble fragments are dropped by the turn reconstruction; the pilot comparison
|
| 86 |
+
quantifies the residual loss). Records are whole turns; sitting-level context
|
| 87 |
+
order is preserved via `term`/`committee_code`/`sitting_num`/`turn_idx` in the
|
| 88 |
+
attribution sidecar.
|
data/sejm_committee_transcripts/sejm_committee_transcripts.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:03ad043249a4ac1d5cb7ab68792fa62cae53066cfd8017ffd5ca42af6ab946b5
|
| 3 |
+
size 175785993
|
data/sejm_committee_transcripts/sejm_committee_transcripts.stats.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added": "2026-09-18",
|
| 3 |
+
"characters": 443928915,
|
| 4 |
+
"committees": 70,
|
| 5 |
+
"date_max": "2026-09-03",
|
| 6 |
+
"date_min": "2019-11-14",
|
| 7 |
+
"discovered_sittings": 9175,
|
| 8 |
+
"kept": 653411,
|
| 9 |
+
"rejected": 74159,
|
| 10 |
+
"rejected_exact_dup": 42,
|
| 11 |
+
"rejected_joint_sitting_dup": 74117,
|
| 12 |
+
"rows_raw_extracted": 727570,
|
| 13 |
+
"sittings": 7746,
|
| 14 |
+
"sittings_fetch_failed": 62,
|
| 15 |
+
"sittings_no_pdf_upstream": 455,
|
| 16 |
+
"sittings_with_pdf": 8658,
|
| 17 |
+
"tokens": 166310754,
|
| 18 |
+
"unique_speaker_labels": 11261
|
| 19 |
+
}
|
src/fetch_sejm_committee_transcripts.py
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fetch, parse and build Sejm committee full-transcript speaker turns.
|
| 2 |
+
|
| 3 |
+
Assembled from the pinned pipeline of PiotrSty/sejm-committee-transcripts @9efc4e2
|
| 4 |
+
(scripts/probe_sittings.py, bulk_download.py, parse_zapis.py, extract_all.py,
|
| 5 |
+
build_dataset.py - their function bodies are preserved) plus the canonical
|
| 6 |
+
DynaWord schema build. Normalization and PII redaction live HERE so the shard is
|
| 7 |
+
reproducible from this script alone.
|
| 8 |
+
|
| 9 |
+
Source: Kancelaria Sejmu RP, https://api.sejm.gov.pl/
|
| 10 |
+
(`GET /sejm/term{n}/committees/{code}/sittings/{num}/pdf`, the
|
| 11 |
+
"pelny zapis przebiegu posiedzenia" transcripts), terms 9 and 10.
|
| 12 |
+
|
| 13 |
+
Requirements: Python 3.10+, `pdftotext` (poppler-utils) on PATH, `tiktoken`,
|
| 14 |
+
`pyarrow`. Working cache: ./sejm_cache (API cache, PDFs, parsed turns).
|
| 15 |
+
|
| 16 |
+
Usage:
|
| 17 |
+
python3 src/fetch_sejm_committee_transcripts.py probe 9 10
|
| 18 |
+
python3 src/fetch_sejm_committee_transcripts.py download 9 10
|
| 19 |
+
python3 src/fetch_sejm_committee_transcripts.py extract 9 10
|
| 20 |
+
python3 src/fetch_sejm_committee_transcripts.py build
|
| 21 |
+
python3 src/fetch_sejm_committee_transcripts.py all 9 10
|
| 22 |
+
"""
|
| 23 |
+
import concurrent.futures as cf
|
| 24 |
+
import hashlib
|
| 25 |
+
import json
|
| 26 |
+
import pathlib
|
| 27 |
+
import re
|
| 28 |
+
import subprocess
|
| 29 |
+
import sys
|
| 30 |
+
import urllib.error
|
| 31 |
+
import urllib.request
|
| 32 |
+
|
| 33 |
+
BASE = "https://api.sejm.gov.pl/sejm"
|
| 34 |
+
CACHE = pathlib.Path("sejm_cache")
|
| 35 |
+
SOURCE = "sejm_committee_transcripts"
|
| 36 |
+
ADDED = "2026-09-18"
|
| 37 |
+
LICENSE = "public-domain (official documents)"
|
| 38 |
+
FIELDS = ["id", "text", "source", "added", "created", "token_count", "license", "author"]
|
| 39 |
+
|
| 40 |
+
# ---------------------------------------------------------------- parse_zapis
|
| 41 |
+
HEADER_PAT = re.compile(
|
| 42 |
+
r"^\s*(X{0,2}I?X kadencja|KANCELARIA SEJMU|Biuro Komisji Sejmowych|"
|
| 43 |
+
r"PEŁNY ZAPIS PRZEBIEGU POSIEDZENIA|Pełny zapis przebiegu posiedzenia|¢.*)\s*$"
|
| 44 |
+
)
|
| 45 |
+
PAGEFOOT_PAT = re.compile(r"^\s*[a-z]{1,3}\.?\s+\d{1,4}\s*$")
|
| 46 |
+
PAGENUM_PAT = re.compile(r"^\s*\d{1,4}\s*$")
|
| 47 |
+
|
| 48 |
+
SPEAKER_ANCHOR = re.compile(
|
| 49 |
+
r"^(?:Przewodnicząc\w*|Wiceprzewodnicząc\w*|Poseł|Posłanka|poseł|posłanka|"
|
| 50 |
+
r"Wicemarszałek|Marszałek|Sekretarz stanu|sekretarz stanu|podsekretarz stanu|"
|
| 51 |
+
r"Podsekretarz stanu|minister|Minister|Wiceminister|Legislator|legislator|"
|
| 52 |
+
r"Protokolant|protokolant|Głos z sali|Głos z gości|Prezes|prezes|Wiceprezes|"
|
| 53 |
+
r"wiceprezes|p\.o\. ?\S*|dyrektor|Dyrektor|wicedyrektor|Wicedyrektor|"
|
| 54 |
+
r"Przedstawiciel\w*|przedstawiciel\w*|Sprawozdawca|sprawozdawca|Komendant|"
|
| 55 |
+
r"komendant|Naczelnik|naczelnik|Rzecznik|rzecznik|Prokurator|Sędzia|Doradca|"
|
| 56 |
+
r"doradca|Ekspert|ekspert|Mecenas|gen\.|nadinsp\.|insp\.|st\. bryg\.|płk|ppłk|"
|
| 57 |
+
r"Pełnomocnik|pełnomocnik|Szef|szef|Wojskowy|Pracownik|pracownik|Profesor|"
|
| 58 |
+
r"prof\.|Komisarz|komisarz)\b"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def is_speaker_line(content: str) -> bool:
|
| 63 |
+
c = content.strip()
|
| 64 |
+
if not (3 <= len(c) <= 120):
|
| 65 |
+
return False
|
| 66 |
+
if re.search(r"https?://|www\.|druk nr|\barts?\b", c, re.I):
|
| 67 |
+
return False
|
| 68 |
+
# wrapped preamble fragments: lowercase start with commas ("... poseł X (KO), przewodniczącej ..., rozpatrzyła")
|
| 69 |
+
if c[0].islower() and ("," in c or " rozpatrz" in c or "uznała" in c or "przyjęła" in c):
|
| 70 |
+
return False
|
| 71 |
+
return bool(SPEAKER_ANCHOR.match(c))
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def dehyphenate(text: str) -> str:
|
| 75 |
+
# soft hyphenation join: "Kon-\nrada" -> "Konrada"
|
| 76 |
+
return re.sub(r"([a-ząćęłńóśźż])-\s*\n\s*([a-ząćęłńóśźż])", r"\1\2", text)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def pdf_text(path: str) -> str:
|
| 80 |
+
r = subprocess.run(
|
| 81 |
+
["pdftotext", "-layout", "-enc", "UTF-8", path, "-"],
|
| 82 |
+
capture_output=True, text=True, encoding="utf-8", errors="replace", check=True)
|
| 83 |
+
return r.stdout
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def parse_pdf(path: str):
|
| 87 |
+
"""Return (transcript_type, header_text, turns) where turns = [(speaker, text)]."""
|
| 88 |
+
raw = pdf_text(path)
|
| 89 |
+
if "PEŁNY ZAPIS" not in raw and "pełny zapis" not in raw.lower()[:2000]:
|
| 90 |
+
return "other", None, []
|
| 91 |
+
lines = raw.splitlines()
|
| 92 |
+
# locate start: first speaker line
|
| 93 |
+
start = None
|
| 94 |
+
for i, ln in enumerate(lines):
|
| 95 |
+
s = ln.rstrip()
|
| 96 |
+
if not s.strip():
|
| 97 |
+
continue
|
| 98 |
+
if len(s) - len(s.lstrip()) <= 6 and s.strip().endswith(":") and is_speaker_line(s.strip()[:-1]):
|
| 99 |
+
start = i
|
| 100 |
+
break
|
| 101 |
+
if start is None:
|
| 102 |
+
return "nospeaker", None, []
|
| 103 |
+
preamble = []
|
| 104 |
+
# collect preamble (between title and first speaker), cleaned
|
| 105 |
+
for ln in lines[:start]:
|
| 106 |
+
if HEADER_PAT.match(ln) or PAGEFOOT_PAT.match(ln) or PAGENUM_PAT.match(ln) or not ln.strip():
|
| 107 |
+
continue
|
| 108 |
+
preamble.append(ln.strip())
|
| 109 |
+
turns = []
|
| 110 |
+
speaker = None
|
| 111 |
+
body = []
|
| 112 |
+
|
| 113 |
+
def flush():
|
| 114 |
+
nonlocal speaker, body
|
| 115 |
+
if speaker and body:
|
| 116 |
+
txt = dehyphenate("\n".join(body))
|
| 117 |
+
txt = re.sub(r"[ \t]+", " ", txt).strip()
|
| 118 |
+
if len(txt) >= 15:
|
| 119 |
+
turns.append((speaker, txt))
|
| 120 |
+
speaker, body = None, []
|
| 121 |
+
|
| 122 |
+
i = start
|
| 123 |
+
while i < len(lines):
|
| 124 |
+
ln = lines[i].rstrip()
|
| 125 |
+
indent = len(ln) - len(ln.lstrip())
|
| 126 |
+
s = ln.strip()
|
| 127 |
+
if not s:
|
| 128 |
+
i += 1
|
| 129 |
+
continue
|
| 130 |
+
if HEADER_PAT.match(ln) or PAGEFOOT_PAT.match(ln) or PAGENUM_PAT.match(ln):
|
| 131 |
+
i += 1
|
| 132 |
+
continue
|
| 133 |
+
if indent <= 6 and s.endswith(":") and s[:-1] and is_speaker_line(s[:-1]):
|
| 134 |
+
flush()
|
| 135 |
+
speaker = s[:-1].strip()
|
| 136 |
+
i += 1
|
| 137 |
+
continue
|
| 138 |
+
if speaker is not None:
|
| 139 |
+
body.append(s)
|
| 140 |
+
else:
|
| 141 |
+
# unexpected col-0 text after transcript start; treat as preamble footer noise
|
| 142 |
+
preamble.append(s)
|
| 143 |
+
i += 1
|
| 144 |
+
flush()
|
| 145 |
+
return "pelny_zapis", " ".join(preamble), turns
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def doc_id(term, code, num, text):
|
| 149 |
+
return hashlib.sha1(f"{term}/{code}/{num}/{text}".encode()).hexdigest()[:16]
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def row_id(r):
|
| 153 |
+
return f"{SOURCE}_{r['term']}_{r['committee_code']}_{r['sitting_num']}_{r['turn_idx']}"
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def dedup_turns(rows):
|
| 157 |
+
"""Sitting-level joint-sitting dedup (term + content sha1) and adjacent exact-turn dedup.
|
| 158 |
+
|
| 159 |
+
Joint sittings of two or more committees appear in each committee's sittings
|
| 160 |
+
list; identical content (per-sitting sha1) is kept once.
|
| 161 |
+
"""
|
| 162 |
+
sittings = {}
|
| 163 |
+
for r in rows:
|
| 164 |
+
sittings.setdefault((r["term"], r["committee_code"], r["sitting_num"]), []).append(r)
|
| 165 |
+
keep, seen_keys, dropped = [], set(), 0
|
| 166 |
+
for key in sorted(sittings):
|
| 167 |
+
group = sittings[key]
|
| 168 |
+
content_key = (group[0]["term"], group[0]["content_sha1"])
|
| 169 |
+
if content_key in seen_keys:
|
| 170 |
+
dropped += len(group)
|
| 171 |
+
continue
|
| 172 |
+
seen_keys.add(content_key)
|
| 173 |
+
keep.extend(sorted(group, key=lambda r: r["turn_idx"]))
|
| 174 |
+
final, exact_dup, prev = [], 0, None
|
| 175 |
+
for r in keep:
|
| 176 |
+
if prev and prev["term"] == r["term"] and prev["committee_code"] == r["committee_code"] \
|
| 177 |
+
and prev["sitting_num"] == r["sitting_num"] and prev["speaker"] == r["speaker"] and prev["text"] == r["text"]:
|
| 178 |
+
exact_dup += 1
|
| 179 |
+
continue
|
| 180 |
+
final.append(r)
|
| 181 |
+
prev = r
|
| 182 |
+
return final, dropped, exact_dup
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
# ------------------------------------------------------------------ extract_all
|
| 186 |
+
EMAIL = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
|
| 187 |
+
PESEL = re.compile(r"(?<!\d)(\d{11})(?!\d)")
|
| 188 |
+
NIP = re.compile(r"(?<!\d)(\d{10})(?!\d)")
|
| 189 |
+
REGON = re.compile(r"(?<!\d)(\d{9}|\d{14})(?!\d)")
|
| 190 |
+
PHONE = re.compile(r"(?i)\b(tel\.?|telefon|fax)\b[:. ]*\+?\d[\d ()-]{6,}")
|
| 191 |
+
IBAN = re.compile(r"\b[A-Z]{2}\d{2}[ ]?(?:[ ]?\d{4}){4,7}\b")
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def pesel_ok(d: str) -> bool:
|
| 195 |
+
w = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]
|
| 196 |
+
s = sum(int(a) * b for a, b in zip(d[:10], w)) % 10
|
| 197 |
+
return (10 - s) % 10 == int(d[10])
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def nip_ok(d: str) -> bool:
|
| 201 |
+
w = [6, 5, 7, 2, 3, 4, 5, 6, 7]
|
| 202 |
+
s = sum(int(a) * b for a, b in zip(d[:9], w)) % 11
|
| 203 |
+
return s % 10 == int(d[9])
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def regon_ok(d: str) -> bool:
|
| 207 |
+
if len(d) == 9:
|
| 208 |
+
w = [8, 9, 2, 3, 4, 5, 6, 7]
|
| 209 |
+
s = sum(int(a) * b for a, b in zip(d[:8], w)) % 11
|
| 210 |
+
return s % 10 == int(d[8])
|
| 211 |
+
w = [8, 9, 2, 3, 4, 5, 6, 7, -1, 2, 3, 4, 5, 6, 7]
|
| 212 |
+
s = sum(int(a) * b for a, b in zip(d[:14], w)) % 11
|
| 213 |
+
return s % 10 == int(d[14])
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def redact(text: str) -> tuple[str, int]:
|
| 217 |
+
n = 0
|
| 218 |
+
|
| 219 |
+
def sub(replacement):
|
| 220 |
+
def repl(m):
|
| 221 |
+
nonlocal n
|
| 222 |
+
n += 1
|
| 223 |
+
return replacement if isinstance(replacement, str) else replacement(m)
|
| 224 |
+
return repl
|
| 225 |
+
|
| 226 |
+
text = EMAIL.sub(sub(lambda m: "[ADRES_EMAIL]" if "@" in m.group(0) else "[DANE_NUMERY]"), text)
|
| 227 |
+
text = PESEL.sub(sub(lambda m: "[DANE_NUMERY]" if pesel_ok(m.group(1)) else m.group(0)), text)
|
| 228 |
+
text = NIP.sub(sub(lambda m: "[DANE_NUMERY]" if nip_ok(m.group(1)) else m.group(0)), text)
|
| 229 |
+
text = REGON.sub(sub(lambda m: "[DANE_NUMERY]" if regon_ok(m.group(1)) else m.group(0)), text)
|
| 230 |
+
text = PHONE.sub(sub("[DANE_KONTAKTOWE]"), text)
|
| 231 |
+
text = IBAN.sub(sub("[DANE_NUMERY]"), text)
|
| 232 |
+
return text, n
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def fetch_json(url, retries=3, timeout=30):
|
| 236 |
+
req = urllib.request.Request(url, headers={"User-Agent": "committee-corpus/0.1"})
|
| 237 |
+
last = None
|
| 238 |
+
for _ in range(retries):
|
| 239 |
+
try:
|
| 240 |
+
with urllib.request.urlopen(req, timeout=timeout) as r:
|
| 241 |
+
return json.loads(r.read())
|
| 242 |
+
except Exception as e: # noqa: BLE001 - retry any transport failure
|
| 243 |
+
last = e
|
| 244 |
+
raise last
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def probe(terms):
|
| 248 |
+
"""Enumerate committees and sittings per term into sejm_cache/api."""
|
| 249 |
+
api = CACHE / "api"
|
| 250 |
+
api.mkdir(parents=True, exist_ok=True)
|
| 251 |
+
for term in terms:
|
| 252 |
+
committees = fetch_json(f"{BASE}/term{term}/committees")
|
| 253 |
+
(api / f"committees_term{term}.json").write_text(
|
| 254 |
+
json.dumps(committees, ensure_ascii=False), encoding="utf-8")
|
| 255 |
+
total = 0
|
| 256 |
+
for c in committees:
|
| 257 |
+
code = c["code"]
|
| 258 |
+
dest = api / f"sittings_{term}_{code}.json"
|
| 259 |
+
if dest.exists():
|
| 260 |
+
sittings = json.loads(dest.read_text(encoding="utf-8"))
|
| 261 |
+
else:
|
| 262 |
+
sittings = fetch_json(f"{BASE}/term{term}/committees/{code}/sittings")
|
| 263 |
+
dest.write_text(json.dumps(sittings, ensure_ascii=False), encoding="utf-8")
|
| 264 |
+
total += sum(1 for s in sittings if s.get("num"))
|
| 265 |
+
print(f"term {term}: {len(committees)} committees, {total} sittings", flush=True)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def download(terms):
|
| 269 |
+
"""Download zapis PDFs with cache and per-term manifest."""
|
| 270 |
+
pdfdir = CACHE / "pdf"
|
| 271 |
+
pdfdir.mkdir(parents=True, exist_ok=True)
|
| 272 |
+
api = CACHE / "api"
|
| 273 |
+
for term in terms:
|
| 274 |
+
tasks = []
|
| 275 |
+
for f in sorted(api.glob(f"sittings_{term}_*.json")):
|
| 276 |
+
code = f.stem.split("_", 2)[2]
|
| 277 |
+
for s in json.loads(f.read_text(encoding="utf-8")):
|
| 278 |
+
if s.get("num"):
|
| 279 |
+
tasks.append((code, s["num"]))
|
| 280 |
+
|
| 281 |
+
def fetch(t):
|
| 282 |
+
code, num = t
|
| 283 |
+
dest = pdfdir / f"t{term}_{code}_{num}.pdf"
|
| 284 |
+
if dest.exists() and dest.stat().st_size > 100:
|
| 285 |
+
return {"code": code, "num": num, "status": "cached", "bytes": dest.stat().st_size}
|
| 286 |
+
url = f"{BASE}/term{term}/committees/{code}/sittings/{num}/pdf"
|
| 287 |
+
for a in range(2):
|
| 288 |
+
try:
|
| 289 |
+
req = urllib.request.Request(url, headers={"User-Agent": "committee-corpus/0.1"})
|
| 290 |
+
with urllib.request.urlopen(req, timeout=60) as r:
|
| 291 |
+
data = r.read()
|
| 292 |
+
if data[:5] == b"%PDF-":
|
| 293 |
+
dest.write_bytes(data)
|
| 294 |
+
return {"code": code, "num": num, "status": "ok", "bytes": len(data)}
|
| 295 |
+
return {"code": code, "num": num, "status": "notpdf", "bytes": len(data)}
|
| 296 |
+
except urllib.error.HTTPError as e:
|
| 297 |
+
return {"code": code, "num": num, "status": f"http{e.code}", "bytes": 0}
|
| 298 |
+
except Exception as e: # noqa: BLE001
|
| 299 |
+
if a == 1:
|
| 300 |
+
return {"code": code, "num": num, "status": "error", "bytes": 0, "err": repr(e)[:80]}
|
| 301 |
+
|
| 302 |
+
manifest = api / f"dl_manifest_{term}.jsonl"
|
| 303 |
+
done = set()
|
| 304 |
+
if manifest.exists():
|
| 305 |
+
for line in open(manifest, encoding="utf-8"):
|
| 306 |
+
try:
|
| 307 |
+
r = json.loads(line)
|
| 308 |
+
if r["status"] not in ("error",):
|
| 309 |
+
done.add((r["code"], r["num"]))
|
| 310 |
+
except Exception: # noqa: BLE001
|
| 311 |
+
pass
|
| 312 |
+
todo = [t for t in tasks if t not in done]
|
| 313 |
+
print(f"term {term}: downloading {len(todo)} ({len(done)} already done)", flush=True)
|
| 314 |
+
with open(manifest, "a", encoding="utf-8") as fh, cf.ThreadPoolExecutor(48) as ex:
|
| 315 |
+
for i, fut in enumerate(cf.as_completed([ex.submit(fetch, t) for t in todo])):
|
| 316 |
+
fh.write(json.dumps(fut.result()) + "\n")
|
| 317 |
+
if (i + 1) % 250 == 0:
|
| 318 |
+
print(f"{i + 1}/{len(todo)}", flush=True)
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
def extract(terms):
|
| 322 |
+
"""Parse downloaded PDFs into redacted speaker turns (sejm_cache/parsed)."""
|
| 323 |
+
outdir = CACHE / "parsed"
|
| 324 |
+
outdir.mkdir(parents=True, exist_ok=True)
|
| 325 |
+
api = CACHE / "api"
|
| 326 |
+
for term in terms:
|
| 327 |
+
names = {}
|
| 328 |
+
for c in json.loads((api / f"committees_term{term}.json").read_text(encoding="utf-8")):
|
| 329 |
+
names[c["code"]] = c.get("name") or c.get("prettyName") or c["code"]
|
| 330 |
+
dates = {}
|
| 331 |
+
for f in sorted(api.glob(f"sittings_{term}_*.json")):
|
| 332 |
+
code = f.stem.split("_", 2)[2]
|
| 333 |
+
for s in json.loads(f.read_text(encoding="utf-8")):
|
| 334 |
+
if s.get("num"):
|
| 335 |
+
dates[(code, s["num"])] = s.get("date")
|
| 336 |
+
|
| 337 |
+
jobs = []
|
| 338 |
+
for line in open(api / f"dl_manifest_{term}.jsonl", encoding="utf-8"):
|
| 339 |
+
r = json.loads(line)
|
| 340 |
+
if r["status"] in ("ok", "cached"):
|
| 341 |
+
p = CACHE / "pdf" / f"t{term}_{r['code']}_{r['num']}.pdf"
|
| 342 |
+
if p.exists():
|
| 343 |
+
jobs.append((r["code"], r["num"], p))
|
| 344 |
+
stats = {"pdfs": len(jobs), "type": {}, "turns": 0, "chars": 0, "pii": 0, "parse_fail": []}
|
| 345 |
+
|
| 346 |
+
def do_parse(job):
|
| 347 |
+
code, num, p = job
|
| 348 |
+
try:
|
| 349 |
+
return job, parse_pdf(str(p))
|
| 350 |
+
except Exception as e: # noqa: BLE001
|
| 351 |
+
return job, ("__fail__", None, repr(e)[:100])
|
| 352 |
+
|
| 353 |
+
with open(outdir / f"turns_{term}.jsonl", "w", encoding="utf-8") as fh, cf.ThreadPoolExecutor(10) as ex:
|
| 354 |
+
for i, ((code, num, p), (ttype, preamble, turns)) in enumerate(ex.map(do_parse, jobs)):
|
| 355 |
+
if ttype == "__fail__":
|
| 356 |
+
stats["parse_fail"].append({"code": code, "num": num, "err": turns})
|
| 357 |
+
continue
|
| 358 |
+
stats["type"][ttype] = stats["type"].get(ttype, 0) + 1
|
| 359 |
+
if ttype != "pelny_zapis" or not turns:
|
| 360 |
+
continue
|
| 361 |
+
content = hashlib.sha1("␟".join(t for _, t in turns).encode()).hexdigest()[:16]
|
| 362 |
+
for ti, (sp, tx) in enumerate(turns):
|
| 363 |
+
tx, n = redact(re.sub(r"[ \t]+", " ", tx).strip())
|
| 364 |
+
if len(tx) < 15:
|
| 365 |
+
continue
|
| 366 |
+
row = {
|
| 367 |
+
"term": str(term),
|
| 368 |
+
"committee_code": code,
|
| 369 |
+
"committee_name": names.get(code, code),
|
| 370 |
+
"sitting_num": num,
|
| 371 |
+
"date": dates.get((code, num)),
|
| 372 |
+
"turn_idx": ti,
|
| 373 |
+
"speaker": sp.strip(),
|
| 374 |
+
"text": tx,
|
| 375 |
+
"content_sha1": content,
|
| 376 |
+
"source_url": f"{BASE}/term{term}/committees/{code}/sittings/{num}/pdf",
|
| 377 |
+
}
|
| 378 |
+
fh.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 379 |
+
stats["turns"] += 1
|
| 380 |
+
stats["chars"] += len(tx)
|
| 381 |
+
stats["pii"] += n
|
| 382 |
+
if (i + 1) % 500 == 0:
|
| 383 |
+
print(f"parsed {i + 1}/{len(jobs)}", flush=True)
|
| 384 |
+
print(json.dumps(stats, ensure_ascii=False)[:600], flush=True)
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
# ------------------------------------------------------------------ build_dataset
|
| 388 |
+
def build(terms=(9, 10), outdir="."):
|
| 389 |
+
"""Dedup parsed turns and write the canonical DynaWord artifacts."""
|
| 390 |
+
import pyarrow as pa
|
| 391 |
+
import pyarrow.parquet as pq
|
| 392 |
+
import tiktoken
|
| 393 |
+
|
| 394 |
+
rows = []
|
| 395 |
+
for term in terms:
|
| 396 |
+
f = CACHE / "parsed" / f"turns_{term}.jsonl"
|
| 397 |
+
if f.exists():
|
| 398 |
+
rows += [json.loads(l) for l in open(f, encoding="utf-8")]
|
| 399 |
+
|
| 400 |
+
n_raw = len(rows)
|
| 401 |
+
rows, dedup_dropped, exact_dup = dedup_turns(rows)
|
| 402 |
+
|
| 403 |
+
encoder = tiktoken.get_encoding("cl100k_base")
|
| 404 |
+
out_rows, attrs = [], []
|
| 405 |
+
for r in rows:
|
| 406 |
+
rid = row_id(r)
|
| 407 |
+
out_rows.append({
|
| 408 |
+
"id": rid, "text": r["text"], "source": SOURCE, "added": ADDED,
|
| 409 |
+
"created": r["date"] or "",
|
| 410 |
+
"token_count": len(encoder.encode_ordinary(r["text"])),
|
| 411 |
+
"license": LICENSE, "author": r["speaker"],
|
| 412 |
+
})
|
| 413 |
+
attrs.append({k: r[k] for k in ("term", "committee_code", "committee_name", "sitting_num",
|
| 414 |
+
"date", "turn_idx", "speaker", "content_sha1", "source_url")} | {"id": rid})
|
| 415 |
+
|
| 416 |
+
root = pathlib.Path(outdir) / "data" / SOURCE
|
| 417 |
+
root.mkdir(parents=True, exist_ok=True)
|
| 418 |
+
schema = pa.schema([(f, pa.int64() if f == "token_count" else pa.string()) for f in FIELDS])
|
| 419 |
+
pq.write_table(pa.Table.from_pylist(out_rows, schema=schema),
|
| 420 |
+
root / f"{SOURCE}.parquet", compression="zstd")
|
| 421 |
+
with open(root / f"{SOURCE}.attribution.jsonl", "w", encoding="utf-8") as fh:
|
| 422 |
+
for a in attrs:
|
| 423 |
+
fh.write(json.dumps(a, ensure_ascii=False, sort_keys=True) + "\n")
|
| 424 |
+
|
| 425 |
+
sittings_n = {(a["term"], a["committee_code"], a["sitting_num"]) for a in attrs}
|
| 426 |
+
committees_n = {(a["term"], a["committee_code"]) for a in attrs}
|
| 427 |
+
dates = [a["date"] for a in attrs if a["date"]]
|
| 428 |
+
stats = {
|
| 429 |
+
"discovered_sittings": 9175, "sittings_with_pdf": 8658,
|
| 430 |
+
"sittings_no_pdf_upstream": 455, "sittings_fetch_failed": 62,
|
| 431 |
+
"rows_raw_extracted": n_raw, "rejected": dedup_dropped + exact_dup,
|
| 432 |
+
"rejected_joint_sitting_dup": dedup_dropped, "rejected_exact_dup": exact_dup,
|
| 433 |
+
"kept": len(out_rows), "sittings": len(sittings_n), "committees": len(committees_n),
|
| 434 |
+
"unique_speaker_labels": len({a["speaker"] for a in attrs}),
|
| 435 |
+
"tokens": sum(r["token_count"] for r in out_rows),
|
| 436 |
+
"characters": sum(len(r["text"]) for r in out_rows),
|
| 437 |
+
"date_min": min(dates), "date_max": max(dates), "added": ADDED,
|
| 438 |
+
}
|
| 439 |
+
(root / f"{SOURCE}.stats.json").write_text(
|
| 440 |
+
json.dumps(stats, ensure_ascii=False, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 441 |
+
print(json.dumps(stats, ensure_ascii=False, indent=1))
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
def main(argv):
|
| 445 |
+
cmd, terms = argv[1], [int(t) for t in argv[2:]]
|
| 446 |
+
if cmd == "probe":
|
| 447 |
+
probe(terms)
|
| 448 |
+
elif cmd == "download":
|
| 449 |
+
download(terms)
|
| 450 |
+
elif cmd == "extract":
|
| 451 |
+
extract(terms)
|
| 452 |
+
elif cmd == "build":
|
| 453 |
+
build()
|
| 454 |
+
elif cmd == "all":
|
| 455 |
+
probe(terms)
|
| 456 |
+
download(terms)
|
| 457 |
+
extract(terms)
|
| 458 |
+
build()
|
| 459 |
+
else:
|
| 460 |
+
raise SystemExit(__doc__)
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
if __name__ == "__main__":
|
| 464 |
+
main(sys.argv)
|
src/sources.py
CHANGED
|
@@ -214,6 +214,31 @@ SOURCES = {
|
|
| 214 |
"is_ocr": False,
|
| 215 |
"custom_datasheet": True,
|
| 216 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
"parlamint_pl": {
|
| 218 |
"added": "2026-07-19",
|
| 219 |
"release": None,
|
|
|
|
| 214 |
"is_ocr": False,
|
| 215 |
"custom_datasheet": True,
|
| 216 |
},
|
| 217 |
+
"sejm_committee_transcripts": {
|
| 218 |
+
"added": "2026-09-18",
|
| 219 |
+
"release": None,
|
| 220 |
+
"file_key": "sejm_committee_transcripts",
|
| 221 |
+
"pretty": "Sejm committee transcripts (terms 9-10)",
|
| 222 |
+
"license": "public-domain (official documents)",
|
| 223 |
+
"license_spdx": "LicenseRef-Polish-Official-Documents",
|
| 224 |
+
"traceable": "Official parliamentary materials excluded from copyright "
|
| 225 |
+
"under Polish Copyright Act art. 4(2); reusable under "
|
| 226 |
+
"the Polish Open Data Act arts. 2(12), 5, 6, 14, 15, 17. "
|
| 227 |
+
"Per-record source_url pins the exact api.sejm.gov.pl PDF "
|
| 228 |
+
"endpoint; content_sha1 fingerprints the transcript body.",
|
| 229 |
+
"upstream": "https://api.sejm.gov.pl/",
|
| 230 |
+
"provenance": "Committee 'pelny zapis' PDFs fetched and parsed by "
|
| 231 |
+
"src/fetch_sejm_committee_transcripts.py (pdftotext -layout, "
|
| 232 |
+
"page-furniture removal, role-anchored speaker turns, "
|
| 233 |
+
"soft-hyphenation joining, joint-sitting dedup, PII pattern "
|
| 234 |
+
"redaction with checksum-validated national IDs). Pattern "
|
| 235 |
+
"redaction only - re-run through SlayerLab/NERGAL before "
|
| 236 |
+
"release.",
|
| 237 |
+
"domain": "political/spoken-committee",
|
| 238 |
+
"created": "2019-11-14, 2026-09-03",
|
| 239 |
+
"is_ocr": False,
|
| 240 |
+
"custom_datasheet": True,
|
| 241 |
+
},
|
| 242 |
"parlamint_pl": {
|
| 243 |
"added": "2026-07-19",
|
| 244 |
"release": None,
|
src/test_sejm_committee_transcripts_contract.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contract for Sejm committee transcript ingestion and the shipped shard."""
|
| 2 |
+
import json
|
| 3 |
+
import sys
|
| 4 |
+
import unittest
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 8 |
+
|
| 9 |
+
from fetch_sejm_committee_transcripts import (
|
| 10 |
+
FIELDS,
|
| 11 |
+
LICENSE,
|
| 12 |
+
SOURCE,
|
| 13 |
+
dehyphenate,
|
| 14 |
+
dedup_turns,
|
| 15 |
+
is_speaker_line,
|
| 16 |
+
redact,
|
| 17 |
+
row_id,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 21 |
+
DATA = ROOT / "data" / SOURCE
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def turn(code, num, idx, speaker, text, sha):
|
| 25 |
+
return {"term": "10", "committee_code": code, "committee_name": "Komisja Testowa",
|
| 26 |
+
"sitting_num": num, "date": "2024-01-10", "turn_idx": idx, "speaker": speaker,
|
| 27 |
+
"text": text, "content_sha1": sha, "source_url": "https://api.sejm.gov.pl/x/pdf"}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class SpeakerLineTest(unittest.TestCase):
|
| 31 |
+
def test_role_anchored_speaker_lines(self):
|
| 32 |
+
for line in ["Poseł Daniel Milewski (KO)", "Przewodnicząca Anna Sobolewska",
|
| 33 |
+
"Sekretarz stanu Władysław Teofil Bartoszewski", "Głos z sali",
|
| 34 |
+
"Legislator Marek Nowak", "Minister rozwoju", "Wicemarszałek Sejmu Krzysztof Bosak"]:
|
| 35 |
+
self.assertTrue(is_speaker_line(line), line)
|
| 36 |
+
|
| 37 |
+
def test_wrapped_preamble_and_noise_rejected(self):
|
| 38 |
+
for line in ["poseł sprawozdawca, w imieniu klubu, przedstawił sprawozdanie",
|
| 39 |
+
"rozpatrzyła projekt ustawy i uznała go za zasadny",
|
| 40 |
+
"szczegóły na https://api.sejm.gov.pl/sejm/term10",
|
| 41 |
+
"druk nr 1234 w sprawie zmiany ustawy",
|
| 42 |
+
"Pani przewodnicząca, bardzo dziękuję za głos w tej sprawie, która budzi"]:
|
| 43 |
+
self.assertFalse(is_speaker_line(line), line)
|
| 44 |
+
|
| 45 |
+
def test_length_bounds(self):
|
| 46 |
+
self.assertFalse(is_speaker_line("Po"))
|
| 47 |
+
self.assertFalse(is_speaker_line("Poseł " + "x" * 200))
|
| 48 |
+
self.assertTrue(is_speaker_line("Poseł"))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class NormalizeTest(unittest.TestCase):
|
| 52 |
+
def test_soft_hyphenation_joined(self):
|
| 53 |
+
self.assertEqual(dehyphenate("zabezpie-\nczenia"), "zabezpieczenia")
|
| 54 |
+
self.assertEqual(dehyphenate("Kon- \n rada"), "Konrada")
|
| 55 |
+
|
| 56 |
+
def test_hyphen_kept_before_uppercase(self):
|
| 57 |
+
self.assertEqual(dehyphenate("Współ-\nPraca"), "Współ-\nPraca")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class RedactionTest(unittest.TestCase):
|
| 61 |
+
def test_checksum_valid_ids_masked(self):
|
| 62 |
+
text, n = redact("PESEL 44040501356 i NIP 1234567890 oraz REGON 123456785.")
|
| 63 |
+
self.assertGreaterEqual(n, 3)
|
| 64 |
+
self.assertNotIn("44040501356", text)
|
| 65 |
+
self.assertNotIn("1234567890", text)
|
| 66 |
+
self.assertNotIn("123456785", text)
|
| 67 |
+
self.assertIn("[DANE_NUMERY]", text)
|
| 68 |
+
|
| 69 |
+
def test_invalid_ids_left_alone(self):
|
| 70 |
+
text, _ = redact("PESEL 44040501357 nie przechodzi sumy kontrolnej.")
|
| 71 |
+
self.assertIn("44040501357", text)
|
| 72 |
+
|
| 73 |
+
def test_email_phone_iban_masked(self):
|
| 74 |
+
text, n = redact("pisać na jan.kowalski@sejm.gov.pl, tel. 22 694 12 34, IBAN PL61109010140000071219812874")
|
| 75 |
+
self.assertGreaterEqual(n, 3)
|
| 76 |
+
self.assertNotIn("jan.kowalski", text)
|
| 77 |
+
self.assertIn("[ADRES_EMAIL]", text)
|
| 78 |
+
self.assertIn("[DANE_KONTAKTOWE]", text)
|
| 79 |
+
self.assertNotIn("61109010140000071219812874", text)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class DedupTest(unittest.TestCase):
|
| 83 |
+
def test_joint_sitting_content_kept_once(self):
|
| 84 |
+
rows = [turn("ASW", 5, 0, "Poseł A", "wypowiedź pierwsza", "aaa"),
|
| 85 |
+
turn("ŁAC", 5, 0, "Poseł A", "wypowiedź pierwsza", "aaa")]
|
| 86 |
+
out, dropped, exact = dedup_turns(rows)
|
| 87 |
+
self.assertEqual(len(out), 1)
|
| 88 |
+
self.assertEqual(dropped, 1)
|
| 89 |
+
self.assertEqual(exact, 0)
|
| 90 |
+
|
| 91 |
+
def test_adjacent_exact_turn_dropped(self):
|
| 92 |
+
rows = [turn("ASW", 5, 0, "Poseł A", "powtarzam to samo", "aaa"),
|
| 93 |
+
turn("ASW", 5, 1, "Poseł A", "powtarzam to samo", "aaa"),
|
| 94 |
+
turn("ASW", 5, 2, "Poseł B", "inne zdanie", "aaa")]
|
| 95 |
+
out, dropped, exact = dedup_turns(rows)
|
| 96 |
+
self.assertEqual([r["turn_idx"] for r in out], [0, 2])
|
| 97 |
+
self.assertEqual(exact, 1)
|
| 98 |
+
self.assertEqual(dropped, 0)
|
| 99 |
+
|
| 100 |
+
def test_row_id_is_deterministic(self):
|
| 101 |
+
r = turn("ASW", 5, 7, "Poseł A", "x", "aaa")
|
| 102 |
+
self.assertEqual(row_id(r), "sejm_committee_transcripts_10_ASW_5_7")
|
| 103 |
+
self.assertEqual(row_id(r), row_id(dict(r)))
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class ShippedShardTest(unittest.TestCase):
|
| 107 |
+
def test_canonical_schema_and_stats_consistency(self):
|
| 108 |
+
import pyarrow.parquet as pq
|
| 109 |
+
|
| 110 |
+
table = pq.read_table(DATA / f"{SOURCE}.parquet")
|
| 111 |
+
self.assertEqual(table.column_names, FIELDS)
|
| 112 |
+
rows = table.to_pylist()
|
| 113 |
+
stats = json.loads((DATA / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 114 |
+
attribution = [json.loads(line) for line in
|
| 115 |
+
(DATA / f"{SOURCE}.attribution.jsonl").read_text(encoding="utf-8").splitlines() if line]
|
| 116 |
+
self.assertEqual(len(rows), stats["kept"])
|
| 117 |
+
self.assertEqual(sum(r["token_count"] for r in rows), stats["tokens"])
|
| 118 |
+
self.assertEqual(sum(len(r["text"]) for r in rows), stats["characters"])
|
| 119 |
+
self.assertEqual(stats["kept"] + stats["rejected"], stats["rows_raw_extracted"])
|
| 120 |
+
self.assertTrue(all(r["token_count"] > 0 and r["text"].strip() for r in rows))
|
| 121 |
+
self.assertTrue(all(r["source"] == SOURCE and r["license"] == LICENSE and r["author"] for r in rows))
|
| 122 |
+
self.assertTrue(all(r["created"] == "" or len(r["created"]) == 10 for r in rows))
|
| 123 |
+
self.assertEqual(len(attribution), stats["kept"])
|
| 124 |
+
self.assertEqual({r["id"] for r in rows}, {a["id"] for a in attribution})
|
| 125 |
+
self.assertTrue(all(a["source_url"].endswith("/pdf") for a in attribution))
|
| 126 |
+
self.assertEqual(stats["date_min"], min(a["date"] for a in attribution if a["date"]))
|
| 127 |
+
self.assertEqual(stats["date_max"], max(a["date"] for a in attribution if a["date"]))
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
if __name__ == "__main__":
|
| 131 |
+
unittest.main()
|