Datasets:
sejm_committee_transcripts: keep only official speakers, cut guest speech and page blocks (v0.2.6 rights audit) (#106)
Browse files- sejm_committee_transcripts: keep only statements by official speakers (v0.2.6 rights audit) (a153fbf5378f855477957b5c4ddaf01944b07277)
- sejm_committee_transcripts: cut turns at every speaker label and strip page blocks (7e48dfcaad899598527ed6d8042a0b53c58643df)
- artifacts/source_findings.md +82 -0
- data/sejm_committee_transcripts/NOTICE.md +6 -3
- data/sejm_committee_transcripts/sejm_committee_transcripts.attribution.jsonl +2 -2
- data/sejm_committee_transcripts/sejm_committee_transcripts.license-evidence.json +15 -1
- data/sejm_committee_transcripts/sejm_committee_transcripts.md +126 -30
- data/sejm_committee_transcripts/sejm_committee_transcripts.parquet +2 -2
- data/sejm_committee_transcripts/sejm_committee_transcripts.speaker-roles.csv +0 -0
- data/sejm_committee_transcripts/sejm_committee_transcripts.stats.json +98 -19
- src/clean_sejm_committee_transcripts.py +240 -0
- src/fetch_sejm_committee_transcripts.py +524 -99
- src/sources.py +23 -5
- src/test_sejm_committee_transcripts_contract.py +902 -18
artifacts/source_findings.md
CHANGED
|
@@ -2297,3 +2297,85 @@ The datasheet states the caveats and gives the requested source note; the regist
|
|
| 2297 |
|
| 2298 |
**Not established** — a lawyer's reading of the SIS terms; the SIS page on the fetch date (bot
|
| 2299 |
challenge); the Kancelaria Sejmu BIP reuse page; personal names (NERGAL, v2#60).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2297 |
|
| 2298 |
**Not established** — a lawyer's reading of the SIS terms; the SIS page on the fetch date (bot
|
| 2299 |
challenge); the Kancelaria Sejmu BIP reuse page; personal names (NERGAL, v2#60).
|
| 2300 |
+
|
| 2301 |
+
## sejm_committee_transcripts — only statements by official speakers (2026-10-07)
|
| 2302 |
+
|
| 2303 |
+
**Finding** (October 2026 rights audit) — art. 4 pkt 2 of the copyright act covers official
|
| 2304 |
+
documents, and a committee transcript also holds statements by guests, experts and
|
| 2305 |
+
representatives of unions, NGOs and companies, and about 2,900 anonymous "Głos z sali" turns.
|
| 2306 |
+
The audit's heuristic put the non-official speakers at about 5% of the characters. The first
|
| 2307 |
+
allowlist cut 11.9%, but it split turns only at lines that start with a role word, so a guest's
|
| 2308 |
+
label (`Świadek`, `Członek zarządu ...`) and speech stayed inside the previous official turn
|
| 2309 |
+
(`10_SPC_62_14`, `10_SKGK_3_24`): the real share of non-official text was higher, and the shard
|
| 2310 |
+
still carried it. Hub PR 37 added all 653,411 turns to main.
|
| 2311 |
+
|
| 2312 |
+
**Fix** — `fetch_sejm_committee_transcripts.SPEAKER_RULES` is a fail-closed allowlist: a piece
|
| 2313 |
+
is kept only if its `author` label, NFC-normalised, fully matches one anchored rule (MPs, chairs
|
| 2314 |
+
who are MPs, Marshals of the Sejm and Senate, senators, members of the government, secretaries and
|
| 2315 |
+
undersecretaries of state in a ministry or the KPRM, heads of bodies named in the Constitution,
|
| 2316 |
+
Biuro Legislacyjne legislators, BAS/BEOS experts and specialists, Sejm committee secretaries,
|
| 2317 |
+
heads of the Sejm and Senate offices). One label-line detector (`is_label`/`split_at_labels`) and
|
| 2318 |
+
one page-block stripper (`strip_page_blocks`) live in the fetch script and are used by `parse_pdf()`
|
| 2319 |
+
and by `src/clean_sejm_committee_transcripts.py`, which re-filters the pinned pre-filter release
|
| 2320 |
+
(the PDF cache is not kept; SHA-256 pins, input stats checked against the input Parquet): every
|
| 2321 |
+
stored turn is cut at each label line (piece 0 keeps the id and author, later pieces get the label
|
| 2322 |
+
as author and the id `<id>_<k>`), page blocks (page number + stenographer initials, `Pełny Zapis
|
| 2323 |
+
Przebiegu Posiedzenia:` title, `Komisji ... (Nr N)`) are removed as a unit with a word hyphenated
|
| 2324 |
+
across one rejoined (v2#95), and every piece is classified. 653,411 turns → 740,018 pieces →
|
| 2325 |
+
613,722 records (727,570 raw + 86,607 split out; joint-sitting duplicates 74,117, exact duplicates
|
| 2326 |
+
77, under 15 characters 16,080, not official 110,181), 443,928,915 → 298,555,500 characters,
|
| 2327 |
+
166,310,754 → 112,003,155 tokens; the 110,181 dropped pieces are 127,167,730 characters (28.6%
|
| 2328 |
+
of the unfiltered release) under 21,364 labels. 122,521 page blocks removed, 4,929 hyphenated
|
| 2329 |
+
words rejoined. Of the 3,790 labels kept, `mp` 220,125 pieces, `mp_committee_chair` 302,535,
|
| 2330 |
+
`state_secretary` 45,800, `sejm_legislator` 34,563, `sejm_committee_secretary` 1,873,
|
| 2331 |
+
`government_member` 4,154, `constitutional_organ_head` 841, `sejm_senate_marshal` 1,490,
|
| 2332 |
+
`sejm_bureau_expert` 1,048, `sejm_senate_office_head` 720, `senator` 573.
|
| 2333 |
+
`sejm_committee_transcripts.speaker-roles.csv` lists every role label (the label without the
|
| 2334 |
+
person's name) with its decision and volume. Parquet sha256
|
| 2335 |
+
`8c7d038e83bb32afd465271198c6ea673069647dc28e21eee9b3fca56c885118`, attribution
|
| 2336 |
+
`9ff1c0c39b2c4b9e81f1ef63f8c33b11e7a4fe269fd2b70e8b20d7a90b7504ba`.
|
| 2337 |
+
|
| 2338 |
+
**Judgement calls** — dropped, though official or arguably so: staff of state bodies the list
|
| 2339 |
+
does not name (directors of ministry departments, deputy presidents of NIK, agency heads), MPs of
|
| 2340 |
+
the European Parliament, the presidential-office secretaries of state, a "Przewodniczący" without
|
| 2341 |
+
a party tag, the Marshal's advisers, former MPs and ministers, KRRiT members, bare `Zastępca szefa
|
| 2342 |
+
KPRM` and `Pełnomocnik rządu ...` labels without a state-secretary rank, the deputy chair of the
|
| 2343 |
+
MON subcommittee on the reinvestigation of the air accident (`Pierwszy zastępca przewodniczącego Podkomisji ...`,
|
| 2344 |
+
not an MP), secretaries of works councils, of the Komisja Wspólna Rządu i Samorządu Terytorialnego
|
| 2345 |
+
and of the Rada Młodzieżowa, and the bare `Sekretarz stanu NAME` with no body named. Allowlist gaps
|
| 2346 |
+
closed after the cut exposed them (maintainer's standing approval for false exclusions of MPs, government members
|
| 2347 |
+
and Sejm/Senate staff): `Legislatorka`, `Sekretarz Komisji NAME`, `Senator RP`, `Ministra`, `Szef
|
| 2348 |
+
KPRM`, `Członek Rady Ministrów`, `Wicemarszałkini`, BEOS/BAS specialists and experts with a topic,
|
| 2349 |
+
deputy chief of the Chancellery, `P.o. dyrektora`, state secretaries holding a government office,
|
| 2350 |
+
double-hyphen names and eleven exact labels (typos, name-plus-party forms; fourteen after the second
|
| 2351 |
+
round). Second round (91 pieces,
|
| 2352 |
+
158,442 characters): the chair of the MON subcommittee on the reinvestigation of the air accident, an MP, in two
|
| 2353 |
+
exact labels without "poseł" and one with it (21 pieces, 66,583 characters); state secretaries with
|
| 2354 |
+
the rank in any position (`Pełnomocnik rządu ..., sekretarz stanu w MP NAME`, `Zastępca szefa KPRM
|
| 2355 |
+
podsekretarz stanu NAME`, `NAME podsekretarz stanu w ...`, one exact typo label `PodPodsekretarz`; 49 pieces, 89,234
|
| 2356 |
+
characters);
|
| 2357 |
+
`Sekretarz Komisji <Sejm committee> NAME` and `Starszy sekretarz Komisji` (18 pieces, 839
|
| 2358 |
+
characters; the committee is matched against a list of Sejm committee names); `Dyrektor Biura
|
| 2359 |
+
Obsługi Posłów` (3 pieces, 1,786 characters). Plain "Legislator NAME" is
|
| 2360 |
+
kept: 99.7% of its characters belong to names that carry an explicit Biuro Legislacyjne label
|
| 2361 |
+
elsewhere.
|
| 2362 |
+
|
| 2363 |
+
**Precision of the cut** (seeded sample, seed 20261008): 150 of 150 detected label lines were labels;
|
| 2364 |
+
of 150 colon-terminated lines the detector rejected, 149 were prose and one a label with prose in
|
| 2365 |
+
front of it on the same line (`... odwołuje Poseł Paweł Jabłoński (PiS):`), which stays inside the
|
| 2366 |
+
previous piece. Known classes: prose ending in capitalised words before a colon is cut (the piece
|
| 2367 |
+
is dropped: conservative); a label with an internal colon or wrapped over three lines is cut late or
|
| 2368 |
+
not at all; a prose-prefixed label on one line is missed (an official's label is harmless, a guest's
|
| 2369 |
+
would leave the words in the previous piece).
|
| 2370 |
+
|
| 2371 |
+
**Not established** — whether guest statements fall under art. 4 pkt 2 (a question for a
|
| 2372 |
+
lawyer; the allowlist is the cautious option); that every kept label is an official acting in
|
| 2373 |
+
office (the name slot accepts any two or three capitalised tokens); a rebuild from the PDFs
|
| 2374 |
+
(no `pdftotext` or cache here: `build()` and `parse_pdf()` are tested on a synthetic cache and by
|
| 2375 |
+
sharing the detector with the clean script, not on the PDFs); the NERGAL pass; about 845 footer-shaped
|
| 2376 |
+
lines of real text (`2020 r.`) and 82 records quoting the transcript title in running text remain.
|
| 2377 |
+
|
| 2378 |
+
**Lesson** — a heuristic share of non-official text says how much to expect, not what to drop; and
|
| 2379 |
+
a speaker filter is only as good as the turn boundaries under it: the first allowlist filtered
|
| 2380 |
+
labels correctly but kept a guest's words inside an official's turn because the splitter knew only
|
| 2381 |
+
role-anchored labels. Cut at everything that looks like a label, then classify.
|
data/sejm_committee_transcripts/NOTICE.md
CHANGED
|
@@ -13,9 +13,12 @@ Creative Commons grant is claimed. Per-record `source_url` and `content_sha1` in
|
|
| 13 |
transcript fingerprint.
|
| 14 |
|
| 15 |
Preparation: Piotr Styla with AI assistance. Changes: `pdftotext -layout`
|
| 16 |
-
extraction, page-furniture
|
| 17 |
-
soft-hyphenation joining, whitespace normalization, joint-sitting and exact-turn
|
| 18 |
-
deduplication,
|
|
|
|
|
|
|
|
|
|
| 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.
|
|
|
|
| 13 |
transcript fingerprint.
|
| 14 |
|
| 15 |
Preparation: Piotr Styla with AI assistance. Changes: `pdftotext -layout`
|
| 16 |
+
extraction, page-furniture and page-break-block removal, speaker-turn reconstruction
|
| 17 |
+
(turns cut at every speaker label line), soft-hyphenation joining, whitespace normalization, joint-sitting and exact-turn
|
| 18 |
+
deduplication, removal of every turn whose speaker is not an MP, a member of the
|
| 19 |
+
government, a head of a constitutional organ or Sejm/Senate staff (guests,
|
| 20 |
+
experts, representatives of unions, NGOs and companies, "Glos z sali"),
|
| 21 |
+
pattern-based PII redaction (e-mail, checksum-valid
|
| 22 |
PESEL/NIP/REGON, labelled phone/fax, IBAN). Not complete anonymization - a
|
| 23 |
SlayerLab/NERGAL pass is required before release. No endorsement by the
|
| 24 |
Kancelaria Sejmu RP is implied.
|
data/sejm_committee_transcripts/sejm_committee_transcripts.attribution.jsonl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ff1c0c39b2c4b9e81f1ef63f8c33b11e7a4fe269fd2b70e8b20d7a90b7504ba
|
| 3 |
+
size 250310942
|
data/sejm_committee_transcripts/sejm_committee_transcripts.license-evidence.json
CHANGED
|
@@ -7,7 +7,14 @@
|
|
| 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",
|
|
@@ -23,5 +30,12 @@
|
|
| 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 |
}
|
|
|
|
| 7 |
"limitations": [
|
| 8 |
"privacy and personal-data exceptions",
|
| 9 |
"third-party rights",
|
| 10 |
+
"no Creative Commons grant is asserted",
|
| 11 |
+
"speaker scope: only statements by official speakers are kept; whether guest statements are official documents is not decided",
|
| 12 |
+
"turns are cut at speaker label lines by a heuristic detector: a label line it misses leaves the words after it inside the previous piece"
|
| 13 |
+
],
|
| 14 |
+
"not_checked": [
|
| 15 |
+
"lawyer review of whether statements by guests, experts and staff of state bodies fall under art. 4(2) of the Polish Copyright Act",
|
| 16 |
+
"a person-by-person check that every kept label belongs to an official acting in office (the rules read the printed role label)",
|
| 17 |
+
"third-party text quoted inside an official's turn"
|
| 18 |
],
|
| 19 |
"official_source": "https://api.sejm.gov.pl/",
|
| 20 |
"provider": "Kancelaria Sejmu RP",
|
|
|
|
| 30 |
"url": "https://eli.gov.pl/api/acts/DU/2023/1524/text.html"
|
| 31 |
},
|
| 32 |
"source_revision": "sejm-committee-transcripts v2 (terms 9+10, full API zapis PDF coverage)",
|
| 33 |
+
"speaker_scope": {
|
| 34 |
+
"dropped": "guests, experts, representatives of unions, NGOs, local-government associations and companies, anonymous 'Glos z sali' turns, directors of ministry departments, agency heads, MEPs, the presidential-office secretaries of state, secretaries of works councils and of the Komisja Wspólna Rządu i Samorządu Terytorialnego, the deputy chair of the MON subcommittee, advisers of the Marshal and any other label the rules do not name",
|
| 35 |
+
"kept": "MPs, committee chairs who are MPs (also subcommittee chairs and deputy chairs when the label says poseł), senators, Marshals of the Sejm and Senate, members of the government, secretaries and undersecretaries of state in a ministry or the KPRM (the rank in any position of the label), heads of bodies named in the Constitution (RPO, RPD, Prezes NIK/NBP/TK/NSA, Pierwszy Prezes SN, KRRiT and KRS chairs, Prokurator Generalny), Biuro Legislacyjne legislators, BAS/BEOS experts and specialists and BAS division heads, secretaries of Sejm committees, heads of the Sejm and Senate offices (the Chancellery heads and directors of its units, the Biuro Obsługi Posłów, the commander and an expert of the Marshal's Guard)",
|
| 36 |
+
"role_table": "data/sejm_committee_transcripts/sejm_committee_transcripts.speaker-roles.csv",
|
| 37 |
+
"rule": "a piece of a turn (turns are cut at every speaker label line) is kept only if its speaker label fully matches an anchored rule in SPEAKER_RULES (src/fetch_sejm_committee_transcripts.py); every other label, and every label no rule recognises, is dropped",
|
| 38 |
+
"status": "proposed by the October 2026 rights audit, not lawyer-signed-off"
|
| 39 |
+
},
|
| 40 |
"status": "verified 2026-09-18; per-row source_url pins the exact API PDF endpoint"
|
| 41 |
}
|
data/sejm_committee_transcripts/sejm_committee_transcripts.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 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 |
-
**
|
|
|
|
|
|
|
| 6 |
70 committees, 7,746 sittings, terms 9 and 10.
|
| 7 |
|
| 8 |
## Origin and license
|
|
@@ -17,21 +19,24 @@ Sejm of the Republic of Poland, parsed into attributed speaker turns:
|
|
| 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,
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 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:
|
| 34 |
-
records; term 10:
|
| 35 |
(role + name as printed in the transcript).
|
| 36 |
|
| 37 |
## Collection and normalization
|
|
@@ -46,43 +51,134 @@ reproducible from the script alone. Requires `pdftotext` (poppler).
|
|
| 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);
|
| 50 |
-
|
| 51 |
-
`
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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: **
|
| 59 |
-
`[DANE_NUMERY]`,
|
| 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
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
## Inclusion argument and caveats
|
| 71 |
|
| 72 |
-
What this adds: spoken multi-party committee discussion - questions
|
| 73 |
-
|
| 74 |
-
written political sources.
|
|
|
|
| 75 |
|
| 76 |
-
Caveats:
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 87 |
order is preserved via `term`/`committee_code`/`sitting_num`/`turn_idx` in the
|
| 88 |
attribution sidecar.
|
|
|
|
| 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 and
|
| 5 |
+
**limited to statements by official speakers** (MPs, members of the government,
|
| 6 |
+
heads of constitutional organs, Sejm and Senate staff; see "Speaker allowlist"):
|
| 7 |
+
**613,722 records / 112,003,155 `cl100k_base` tokens / 298,555,500 characters**,
|
| 8 |
70 committees, 7,746 sittings, terms 9 and 10.
|
| 9 |
|
| 10 |
## Origin and license
|
|
|
|
| 19 |
[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).
|
| 20 |
No upstream Creative Commons grant is claimed. Evidence snapshot:
|
| 21 |
`sejm_committee_transcripts.license-evidence.json` (verified 2026-09-18;
|
| 22 |
+
limitations: privacy and personal-data exceptions, third-party rights, and the
|
| 23 |
+
speaker scope below). Not lawyer-signed-off.
|
| 24 |
|
| 25 |
## What the texts are
|
| 26 |
|
| 27 |
- **Genre**: official stenographic transcripts of standing-committee sittings -
|
| 28 |
+
bill examinations, questions from MPs and answers from ministers and officials,
|
| 29 |
+
chair announcements and votes. Statements by guests and experts and the
|
| 30 |
+
anonymous "Glos z sali" interjections are not in the shard. One record per
|
| 31 |
+
speaker turn; a turn ends at every speaker label line, so a guest's label and
|
| 32 |
+
words are not left inside an official's record.
|
| 33 |
- **Register**: prepared official transcript of spoken Polish - multi-party
|
| 34 |
discussion with questions, answers and interruptions, formal address formulas,
|
| 35 |
occasional read-out quotations of documents. Not plenary speeches: this is the
|
| 36 |
committee working register that the plenary-only `parliamentary` / `sejm_api`
|
| 37 |
sources do not contain. Not OCR'd (born-digital PDFs), not machine-translated.
|
| 38 |
+
- **Time span**: sitting dates `2019-11-14` - `2026-09-03` (term 9: 313,699
|
| 39 |
+
records; term 10: 300,023). 3,790 distinct speaker labels
|
| 40 |
(role + name as printed in the transcript).
|
| 41 |
|
| 42 |
## Collection and normalization
|
|
|
|
| 51 |
retries.
|
| 52 |
- **Extract**: `pdftotext -layout`; page furniture removed (running headers
|
| 53 |
"KANCELARIA SEJMU" / "Biuro Komisji Sejmowych" / "PEŁNY ZAPIS ...", page
|
| 54 |
+
numbers and footers); a page-break block (page number and stenographer
|
| 55 |
+
initials, the `Pełny Zapis Przebiegu Posiedzenia:` title, the committee line
|
| 56 |
+
`Komisji ... (Nr N)`) removed as a unit by `strip_page_blocks()`, with a word
|
| 57 |
+
hyphenated across the block rejoined; speaker turns cut at every line that is a
|
| 58 |
+
speaker label (`is_label()`: role and title words plus a personal name with an
|
| 59 |
+
optional party tag, or `Świadek nr 3`, `Głos z sali`, `Tłumacz`), not only at
|
| 60 |
+
lines that start with a role word; body soft-hyphenation joined across line
|
| 61 |
+
breaks; whitespace runs collapsed; turns under 15 characters dropped. The same
|
| 62 |
+
two functions run in `src/clean_sejm_committee_transcripts.py` on the stored
|
| 63 |
+
text, so a fresh parse and the shipped shard cut at the same lines. Applied to
|
| 64 |
+
the stored pre-filter release: 122,521 page blocks removed (4,929 hyphenated
|
| 65 |
+
words rejoined, 5,197 footers glued onto a word repaired, 7,736 stray footers
|
| 66 |
+
removed) and 86,607 label lines found inside turns. The cut is not rerun on the
|
| 67 |
+
PDFs (not cached). The parser was validated against the earlier ASW-only
|
| 68 |
+
pilot (98.9% of the pilot's audited corrected character count with per-turn
|
| 69 |
+
attribution) before the label-line cut, which was not compared with the pilot.
|
| 70 |
- **PII (which scrubber ran)**: the pattern pass `redact()` in the committed
|
| 71 |
script - e-mail -> `[ADRES_EMAIL]`, checksum-valid PESEL/NIP/REGON and IBAN
|
| 72 |
candidates -> `[DANE_NUMERY]`, labelled phone/fax -> `[DANE_KONTAKTOWE]`.
|
| 73 |
+
Counted in the shipped shard: **403 redactions** (396 `[ADRES_EMAIL]`, 6
|
| 74 |
+
`[DANE_NUMERY]`, 1 `[DANE_KONTAKTOWE]`; the pipeline's pre-dedup counter read
|
| 75 |
+
454 because it also counted rows later dropped as joint-sitting duplicates or,
|
| 76 |
+
since the speaker filter, as statements by non-official speakers).
|
| 77 |
This is **not**
|
| 78 |
[SlayerLab/NERGAL](https://huggingface.co/SlayerLab/NERGAL): the shard must be
|
| 79 |
re-run through NERGAL before it is admitted to a release (it quotes citizens'
|
| 80 |
statements and documents). Merge with `release: None` is fine meanwhile.
|
| 81 |
- **Dedup**: joint sittings listed under two committee codes are kept once
|
| 82 |
(74,117 rows / 912 sittings dropped by per-sitting `content_sha1`); adjacent
|
| 83 |
+
exact duplicate turns (same sitting, speaker and text) dropped (77: the 42 of
|
| 84 |
+
the pre-filter release and 35 that the cut at label lines made adjacent);
|
| 85 |
+
pieces under 15 characters after the cut dropped (16,080). No cross-source
|
| 86 |
+
dedup yet (see caveats).
|
| 87 |
+
- **Speaker allowlist** (applied after the dedup and after the cut at label
|
| 88 |
+
lines): `src/clean_sejm_committee_transcripts.py` cuts every stored turn of the
|
| 89 |
+
pinned pre-filter release at its label lines (86,607 pieces split out; the
|
| 90 |
+
first piece keeps the turn's `id` and `author`, the k-th later piece gets the
|
| 91 |
+
label as `author` and the id `<id>_<k>`, with k counted before dropping, so a
|
| 92 |
+
kept piece can be `_2` while `_1` was dropped; the pieces of one turn share
|
| 93 |
+
`turn_idx`). A piece is kept only if its speaker label matches, in full, one of
|
| 94 |
+
the anchored rules `SPEAKER_RULES` in `src/fetch_sejm_committee_transcripts.py`;
|
| 95 |
+
every other label is dropped, and so is a label no rule recognises (fail
|
| 96 |
+
closed). The rules, with the pieces each keeps:
|
| 97 |
+
MPs (`mp`: 220,125, including "spoza skladu Komisji"), committee chairs who are
|
| 98 |
+
MPs, and subcommittee chairs and deputy chairs when the label says "poseł"
|
| 99 |
+
(`mp_committee_chair`: 302,535), Marshals of the Sejm and Senate
|
| 100 |
+
(`sejm_senate_marshal`: 1,490), the Prime Minister, deputy Prime Ministers,
|
| 101 |
+
ministers and other members of the Council of Ministers (`government_member`:
|
| 102 |
+
4,154), secretaries and undersecretaries of state in a ministry or the Chancellery
|
| 103 |
+
of the Prime Minister, the rank in any position of the label ("Pełnomocnik rządu
|
| 104 |
+
..., sekretarz stanu w MP NAME", "Zastępca szefa KPRM podsekretarz stanu NAME";
|
| 105 |
+
`state_secretary`: 45,800), heads of bodies named in the
|
| 106 |
+
Constitution (`constitutional_organ_head`: 841 - Rzecznik Praw Obywatelskich and
|
| 107 |
+
Praw Dziecka, Prezes NIK, NBP, TK, NSA, Pierwszy Prezes SN, the KRRiT and KRS
|
| 108 |
+
chairs, Prokurator Generalny), Biuro Legislacyjne legislators
|
| 109 |
+
(`sejm_legislator`: 34,563), BAS and BEOS experts and specialists and BAS division
|
| 110 |
+
heads (`sejm_bureau_expert`: 1,048), secretaries of Sejm committees, "Sekretarz
|
| 111 |
+
Komisji <Sejm committee> NAME" (`sejm_committee_secretary`: 1,873), the heads of the Sejm and Senate
|
| 112 |
+
offices (`sejm_senate_office_head`: 720; the Chancellery heads, the directors of
|
| 113 |
+
its units, the Biuro Obsługi Posłów, the director of the Marshal's cabinet, the commander and an expert of
|
| 114 |
+
the Marshal's Guard) and senators ("Senator RP NAME", `senator`: 573). Fourteen labels
|
| 115 |
+
with a typo in the transcript or without a role word are kept by exact label
|
| 116 |
+
(`EXACT_LABELS`: 41 turns, 70,395 characters, 63,208 of them the two labels of
|
| 117 |
+
the chair of the MON subcommittee, who is an MP), each counted under the rule it
|
| 118 |
+
belongs to. Dropped: 110,181 pieces (127,167,730 characters, 46,920,738 tokens;
|
| 119 |
+
28.6% of the characters of the pre-filter release) with 21,364 distinct labels,
|
| 120 |
+
among them 35,813 "Swiadek" pieces, 2,941 "Glos z sali" pieces, directors of
|
| 121 |
+
ministry departments, deputy presidents of NIK, heads of agencies (UOKiK, Wody
|
| 122 |
+
Polskie, KNF, IPN), candidates for posts, the Rzecznik Praw Pacjenta and the
|
| 123 |
+
Rzecznik MSP, the deputy chair of the MON subcommittee (not an MP), the
|
| 124 |
+
secretaries of state of the presidential office, "Zastępca szefa KPRM" and
|
| 125 |
+
"Pełnomocnik rządu" labels without a state-secretary rank, the secretaries of
|
| 126 |
+
works councils and of the Komisja Wspólna Rządu i Samorządu Terytorialnego, and the representatives and experts of unions, local government
|
| 127 |
+
associations, NGOs and companies. The dropped share is higher than the 11.9% of the
|
| 128 |
+
earlier shard because the guests who used to sit inside an official's turn are now
|
| 129 |
+
separated from it and dropped, not mainly because more labels are refused. A
|
| 130 |
+
dropped piece leaves no marker; the pieces of a turn share `turn_idx`, so the
|
| 131 |
+
sequence in a sitting has gaps, and a sitting with no official piece would have no
|
| 132 |
+
rows (none is lost: all 7,746 sittings keep at least one record).
|
| 133 |
+
`sejm_committee_transcripts.speaker-roles.csv` lists every distinct role label
|
| 134 |
+
(the speaker label without the person's name) with its decision, rule, pieces,
|
| 135 |
+
characters and distinct labels. `build()` applies the same detector, stripper and
|
| 136 |
+
rules after the dedup; that path is tested on a synthetic cache and has not been
|
| 137 |
+
rerun on the PDFs, and a fresh build numbers and hashes the cut turns anew, so
|
| 138 |
+
its ids differ from the ids of the clean script.
|
| 139 |
|
| 140 |
## Inclusion argument and caveats
|
| 141 |
|
| 142 |
+
What this adds: spoken multi-party committee discussion - questions from MPs,
|
| 143 |
+
answers from ministers and officials, chair announcements - a working-register
|
| 144 |
+
complement to the corpus's plenary and written political sources. 112M tokens
|
| 145 |
+
of it.
|
| 146 |
|
| 147 |
+
Caveats: the speaker allowlist is the conservative reading of art. 4(2). Whether
|
| 148 |
+
the statements of guests and experts are official documents is not settled, so
|
| 149 |
+
they are left out, and so are statements of staff of state bodies that the
|
| 150 |
+
allowlist does not name (e.g. department directors and agency heads; their
|
| 151 |
+
share was not measured again after the cut at label lines). The
|
| 152 |
+
allowlist reads the printed role label, not the person: a name slot accepts any
|
| 153 |
+
two or three capitalised tokens, so a label that has the shape of an official's is
|
| 154 |
+
kept. Labels of MPs of the European Parliament, of former MPs and of foreign
|
| 155 |
+
delegations, a "Przewodniczący" without a party tag and advisers of the Marshal
|
| 156 |
+
are dropped without being reviewed one by one; MP labels with a glued,
|
| 157 |
+
comma-separated or unclosed party tag, surname-only labels with a party tag and
|
| 158 |
+
"Przewodniczący NAME (PARTY)" are kept, and so are eleven labels with a typo or without a role word, by exact
|
| 159 |
+
label. The cut at label lines is a heuristic: on a seeded sample (seed
|
| 160 |
+
20261008) all 150 detected label lines were labels and 149 of 150
|
| 161 |
+
colon-terminated lines it rejected were prose; the miss was a label with prose in
|
| 162 |
+
front of it on the same line ("... odwołuje Poseł Paweł Jabłoński (PiS):"), which
|
| 163 |
+
stays inside the previous piece (an official's label, so only the attribution is
|
| 164 |
+
off; the same shape with a guest's label would leave the guest's words in the
|
| 165 |
+
previous piece). The detector errs towards cutting: a
|
| 166 |
+
sentence that looks like a label (capitalised words before a colon) only splits an
|
| 167 |
+
official's turn and drops the part after it. Page-break blocks are removed by
|
| 168 |
+
pattern; about 845 short lines of footer shape that are real text (a year such as
|
| 169 |
+
"2020 r.") remain, and 82 records still quote the transcript's title in running
|
| 170 |
+
text (the transcript "zostanie zamieszczony w Systemie Informacyjnym Sejmu"). Not
|
| 171 |
+
lawyer-signed-off. Transcripts are the Sejm's official cleaned stenograms, not
|
| 172 |
+
raw audio; quotations of statutes, print and citizen statements are embedded
|
| 173 |
+
(near-dedup vs `dziennik_ustaw` / `eurlex` remains a target integration gate, as
|
| 174 |
+
does a benchmark-overlap check) and the filter does not touch them, even inside
|
| 175 |
+
an official's turn; PII treatment is pattern-based (see above) and quoted citizens
|
| 176 |
+
warrant a NERGAL pass and a spot check before release; 517 sittings are missing
|
| 177 |
+
(455 without an upstream PDF, 62 fetch failures). Training benefit is an untested
|
| 178 |
+
hypothesis.
|
| 179 |
|
| 180 |
Limitations: speaker labels and role attribution follow the printed transcript
|
| 181 |
(preamble fragments are dropped by the turn reconstruction; the pilot comparison
|
| 182 |
+
quantifies the residual loss). Records are turns cut at label lines; sitting-level context
|
| 183 |
order is preserved via `term`/`committee_code`/`sitting_num`/`turn_idx` in the
|
| 184 |
attribution sidecar.
|
data/sejm_committee_transcripts/sejm_committee_transcripts.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8c7d038e83bb32afd465271198c6ea673069647dc28e21eee9b3fca56c885118
|
| 3 |
+
size 121187049
|
data/sejm_committee_transcripts/sejm_committee_transcripts.speaker-roles.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/sejm_committee_transcripts/sejm_committee_transcripts.stats.json
CHANGED
|
@@ -1,19 +1,98 @@
|
|
| 1 |
-
{
|
| 2 |
-
"added": "2026-09-18",
|
| 3 |
-
"characters":
|
| 4 |
-
"committees": 70,
|
| 5 |
-
"date_max": "2026-09-03",
|
| 6 |
-
"date_min": "2019-11-14",
|
| 7 |
-
"discovered_sittings": 9175,
|
| 8 |
-
"kept":
|
| 9 |
-
"
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
-
"
|
| 18 |
-
"
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added": "2026-09-18",
|
| 3 |
+
"characters": 298555500,
|
| 4 |
+
"committees": 70,
|
| 5 |
+
"date_max": "2026-09-03",
|
| 6 |
+
"date_min": "2019-11-14",
|
| 7 |
+
"discovered_sittings": 9175,
|
| 8 |
+
"kept": 613722,
|
| 9 |
+
"page_blocks": {
|
| 10 |
+
"glued_footers_repaired": 5197,
|
| 11 |
+
"hyphenated_words_rejoined": 4929,
|
| 12 |
+
"removed": 122521,
|
| 13 |
+
"stray_footers_removed": 7736
|
| 14 |
+
},
|
| 15 |
+
"rejected": 200455,
|
| 16 |
+
"rejected_exact_dup": 77,
|
| 17 |
+
"rejected_joint_sitting_dup": 74117,
|
| 18 |
+
"rejected_not_official_speaker": 110181,
|
| 19 |
+
"rejected_too_short": 16080,
|
| 20 |
+
"rows_raw_extracted": 727570,
|
| 21 |
+
"rows_split_out": 86607,
|
| 22 |
+
"sittings": 7746,
|
| 23 |
+
"sittings_fetch_failed": 62,
|
| 24 |
+
"sittings_no_pdf_upstream": 455,
|
| 25 |
+
"sittings_with_pdf": 8658,
|
| 26 |
+
"speaker_allowlist": {
|
| 27 |
+
"input_sha256": {
|
| 28 |
+
"sejm_committee_transcripts.attribution.jsonl": "d7277bad9abae279cd5b417e6504c9bcb17c832b41281991b2038489a5453f83",
|
| 29 |
+
"sejm_committee_transcripts.parquet": "03ad043249a4ac1d5cb7ab68792fa62cae53066cfd8017ffd5ca42af6ab946b5",
|
| 30 |
+
"sejm_committee_transcripts.stats.json": "e24f5c0fb638b54cb6b6c4086b95f0fb771cde714a60434a769f2376252b0831"
|
| 31 |
+
},
|
| 32 |
+
"kept_by_rule": {
|
| 33 |
+
"constitutional_organ_head": {
|
| 34 |
+
"characters": 2541563,
|
| 35 |
+
"speaker_labels": 37,
|
| 36 |
+
"turns": 841
|
| 37 |
+
},
|
| 38 |
+
"government_member": {
|
| 39 |
+
"characters": 7055794,
|
| 40 |
+
"speaker_labels": 149,
|
| 41 |
+
"turns": 4154
|
| 42 |
+
},
|
| 43 |
+
"mp": {
|
| 44 |
+
"characters": 132728415,
|
| 45 |
+
"speaker_labels": 1654,
|
| 46 |
+
"turns": 220125
|
| 47 |
+
},
|
| 48 |
+
"mp_committee_chair": {
|
| 49 |
+
"characters": 80689528,
|
| 50 |
+
"speaker_labels": 311,
|
| 51 |
+
"turns": 302535
|
| 52 |
+
},
|
| 53 |
+
"sejm_bureau_expert": {
|
| 54 |
+
"characters": 4106916,
|
| 55 |
+
"speaker_labels": 289,
|
| 56 |
+
"turns": 1048
|
| 57 |
+
},
|
| 58 |
+
"sejm_committee_secretary": {
|
| 59 |
+
"characters": 118027,
|
| 60 |
+
"speaker_labels": 93,
|
| 61 |
+
"turns": 1873
|
| 62 |
+
},
|
| 63 |
+
"sejm_legislator": {
|
| 64 |
+
"characters": 13802216,
|
| 65 |
+
"speaker_labels": 185,
|
| 66 |
+
"turns": 34563
|
| 67 |
+
},
|
| 68 |
+
"sejm_senate_marshal": {
|
| 69 |
+
"characters": 623790,
|
| 70 |
+
"speaker_labels": 34,
|
| 71 |
+
"turns": 1490
|
| 72 |
+
},
|
| 73 |
+
"sejm_senate_office_head": {
|
| 74 |
+
"characters": 1176469,
|
| 75 |
+
"speaker_labels": 68,
|
| 76 |
+
"turns": 720
|
| 77 |
+
},
|
| 78 |
+
"senator": {
|
| 79 |
+
"characters": 653167,
|
| 80 |
+
"speaker_labels": 69,
|
| 81 |
+
"turns": 573
|
| 82 |
+
},
|
| 83 |
+
"state_secretary": {
|
| 84 |
+
"characters": 55059615,
|
| 85 |
+
"speaker_labels": 901,
|
| 86 |
+
"turns": 45800
|
| 87 |
+
}
|
| 88 |
+
},
|
| 89 |
+
"removed": {
|
| 90 |
+
"characters": 127167730,
|
| 91 |
+
"speaker_labels": 21364,
|
| 92 |
+
"tokens": 46920738,
|
| 93 |
+
"turns": 110181
|
| 94 |
+
}
|
| 95 |
+
},
|
| 96 |
+
"tokens": 112003155,
|
| 97 |
+
"unique_speaker_labels": 3790
|
| 98 |
+
}
|
src/clean_sejm_committee_transcripts.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Keep only official speakers in the sejm_committee_transcripts shard (October 2026 rights audit).
|
| 3 |
+
|
| 4 |
+
Committee transcripts also hold statements by guests, experts and representatives of unions, NGOs
|
| 5 |
+
and companies, and anonymous "Głos z sali" interjections. Only statements by MPs, members of the
|
| 6 |
+
government, heads of constitutional organs and Sejm/Senate staff are official materials in the
|
| 7 |
+
sense of art. 4 pkt 2 of the Polish copyright act. The allowlist is
|
| 8 |
+
fetch_sejm_committee_transcripts.SPEAKER_RULES: a turn is kept only if its `author` label fully
|
| 9 |
+
matches one rule (or is one of the few typo labels in EXACT_LABELS), so an unrecognised label is
|
| 10 |
+
dropped.
|
| 11 |
+
|
| 12 |
+
The pre-filter shard started a turn only at a line that began with one of a few anchor words
|
| 13 |
+
("Poseł", "Minister", ...). Any other label ("Świadek ...", "Członek zarządu ...") never started a
|
| 14 |
+
turn, so a guest's label and speech sat inside the preceding official turn. The PDF cache of the
|
| 15 |
+
fetcher is not kept, so this script works on the pinned pre-filter release files and first re-cuts
|
| 16 |
+
every input turn with the same code that `parse_pdf()` uses on a fresh PDF:
|
| 17 |
+
|
| 18 |
+
1. Page-break blocks (page number + stenographer initials, "Pełny Zapis Przebiegu Posiedzenia:",
|
| 19 |
+
"Komisji ... (nr N)") are removed (`strip_page_blocks`); a word hyphenated across a block is
|
| 20 |
+
rejoined.
|
| 21 |
+
2. The turn is cut at every label line (`split_at_labels`). Piece 0, the text before the first
|
| 22 |
+
label, keeps the row id and author. The k-th later piece (k = 1, 2, ... in the turn, counted
|
| 23 |
+
before any piece is dropped) becomes its own row: author = the label (NFC, colon stripped),
|
| 24 |
+
id = "<original id>_<k>", every other field copied from the turn, so the sidecar line is
|
| 25 |
+
the turn's line with the new `speaker` and `id`. `turn_idx` and `content_sha1` stay those of the
|
| 26 |
+
input turn; ids are unique, `turn_idx` is not.
|
| 27 |
+
3. A piece shorter than 15 characters is dropped (rejected_too_short), then a piece equal to the
|
| 28 |
+
previous piece of its sitting (same author and text) is dropped (rejected_exact_dup, added to the
|
| 29 |
+
pinned count), as `build()` does.
|
| 30 |
+
4. Every piece is classified by `classify_speaker`; allowlisted pieces are kept, the rest are dropped
|
| 31 |
+
without a marker (rejected_not_official_speaker). A sitting without an official piece has no rows.
|
| 32 |
+
|
| 33 |
+
Stats: rows_split_out counts the extra rows made in step 2, so kept + rejected == rows_raw_extracted
|
| 34 |
+
+ rows_split_out. A piece whose text did not change keeps its stored token_count; every other piece
|
| 35 |
+
is counted again with tiktoken cl100k_base.
|
| 36 |
+
|
| 37 |
+
A fresh `build()` from the PDFs cuts at the same lines with the same code but does not know the
|
| 38 |
+
input turns: it numbers the cut turns consecutively ("..._<turn_idx>" without "_<k>") and hashes
|
| 39 |
+
the cut turns for `content_sha1`. The PDFs are not available here, so that equivalence of text,
|
| 40 |
+
author and order is by construction and not checked. The old indent test (a label line started within
|
| 41 |
+
6 columns of the margin) is gone from both, because the stored text has no indentation.
|
| 42 |
+
|
| 43 |
+
It also writes sejm_committee_transcripts.speaker-roles.csv, one row per distinct role label (the
|
| 44 |
+
speaker label with the person's name cut off), decision and rule, with piece and character counts.
|
| 45 |
+
|
| 46 |
+
The inputs are the pre-filter release files, pinned by SHA-256. Restore them before a rerun:
|
| 47 |
+
git checkout 0bbdb0d -- data/sejm_committee_transcripts/sejm_committee_transcripts.{parquet,attribution.jsonl,stats.json}
|
| 48 |
+
python3 src/clean_sejm_committee_transcripts.py
|
| 49 |
+
"""
|
| 50 |
+
from __future__ import annotations
|
| 51 |
+
|
| 52 |
+
import argparse
|
| 53 |
+
import csv
|
| 54 |
+
import json
|
| 55 |
+
import re
|
| 56 |
+
from collections import Counter, defaultdict
|
| 57 |
+
from pathlib import Path
|
| 58 |
+
|
| 59 |
+
import pyarrow as pa
|
| 60 |
+
import pyarrow.parquet as pq
|
| 61 |
+
|
| 62 |
+
from fetch_sejm_committee_transcripts import (
|
| 63 |
+
ATTRIBUTION_KEYS, FIELDS, MIN_TURN_CHARS, SOURCE, SPEAKER_RULES, classify_speaker, count_tokens, dedup_turns,
|
| 64 |
+
shard_stats, split_at_labels, strip_page_blocks, turn_text)
|
| 65 |
+
from sejm_api_common import check_pin, replace_all, write_json
|
| 66 |
+
|
| 67 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 68 |
+
DATA = ROOT / "data" / SOURCE
|
| 69 |
+
# Pre-filter release files (main at 0bbdb0d, added in Hub PR 37).
|
| 70 |
+
INPUT_SHA256 = {
|
| 71 |
+
f"{SOURCE}.parquet": "03ad043249a4ac1d5cb7ab68792fa62cae53066cfd8017ffd5ca42af6ab946b5",
|
| 72 |
+
f"{SOURCE}.attribution.jsonl": "d7277bad9abae279cd5b417e6504c9bcb17c832b41281991b2038489a5453f83",
|
| 73 |
+
f"{SOURCE}.stats.json": "e24f5c0fb638b54cb6b6c4086b95f0fb771cde714a60434a769f2376252b0831",
|
| 74 |
+
}
|
| 75 |
+
ROLES_CSV = f"{SOURCE}.speaker-roles.csv"
|
| 76 |
+
ROLES_HEADER = ["role", "decision", "rule", "turns", "characters", "speaker_labels"]
|
| 77 |
+
|
| 78 |
+
# ---- role label: the speaker label without the person's name (evidence table only; the filter
|
| 79 |
+
# itself never uses it). A name is a run of capitalised tokens, preceded by given names seen in
|
| 80 |
+
# the MPs' labels; whatever is left in front is the role.
|
| 81 |
+
_CAP, _LOW = "A-ZĄĆĘŁŃÓŚŹŻ", "a-ząćęłńóśźżéüöäèç"
|
| 82 |
+
_NAME_TOKEN = re.compile(rf"[{_CAP}][{_LOW}'’.]+(?:-[{_CAP}][{_LOW}'’]+)*|[{_CAP}]\.")
|
| 83 |
+
_PARTICLES = {"de", "von", "van", "vel", "di", "du", "la", "le", "da", "ter", "den", "der", "ibn", "bin", "al", "el"}
|
| 84 |
+
_PARTY_TAIL = re.compile(r"(.+?) \([^()]{1,60}\)((?: ?[–−-] ?.*)?)")
|
| 85 |
+
_MP_LABEL = re.compile(r"(?:Przewodnicząc\w+ |Wiceprzewodnicząc\w+ )?(?:Poseł|Posłanka|poseł|posłanka) (.+?) \([^)]+\)")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def given_names(labels) -> set[str]:
|
| 89 |
+
"""First names taken from the MP labels ("Poseł Jan Maria Kowalski (PARTY)")."""
|
| 90 |
+
names: set[str] = set()
|
| 91 |
+
for label in labels:
|
| 92 |
+
if match := _MP_LABEL.match(label):
|
| 93 |
+
names.update(match.group(1).split()[:-1])
|
| 94 |
+
return names
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def role_of(label: str, given: set[str]) -> str:
|
| 98 |
+
"""`label` without the person's name: surname (with particles), then given names, are cut.
|
| 99 |
+
|
| 100 |
+
A party in parentheses ends the name of an MP label; what follows it (" – spoza składu
|
| 101 |
+
Komisji") stays with the role. A label whose last token is not a name ("Głos z sali") is
|
| 102 |
+
its own role."""
|
| 103 |
+
suffix = ""
|
| 104 |
+
if match := _PARTY_TAIL.fullmatch(label):
|
| 105 |
+
label, suffix = match.groups()
|
| 106 |
+
tokens = label.split()
|
| 107 |
+
cut = len(tokens) - 1
|
| 108 |
+
if cut < 1 or not _NAME_TOKEN.fullmatch(tokens[-1]):
|
| 109 |
+
return label + suffix
|
| 110 |
+
while cut - 1 >= 1 and tokens[cut - 1].lower() in _PARTICLES:
|
| 111 |
+
cut -= 1
|
| 112 |
+
if cut - 1 >= 1 and _NAME_TOKEN.fullmatch(tokens[cut - 1]):
|
| 113 |
+
cut -= 1
|
| 114 |
+
while cut - 1 >= 1 and tokens[cut - 1] in given:
|
| 115 |
+
cut -= 1
|
| 116 |
+
return " ".join(tokens[:cut]) + suffix
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def roles_table(label_stats: dict[str, tuple[int, int, str | None]]) -> list[list]:
|
| 120 |
+
"""CSV rows from {label: (turns, characters, rule or None)}, biggest first."""
|
| 121 |
+
given = given_names(label_stats)
|
| 122 |
+
groups: dict[tuple[str, str, str], list[int]] = defaultdict(lambda: [0, 0, 0])
|
| 123 |
+
for label, (turns, characters, rule) in label_stats.items():
|
| 124 |
+
group = groups[(role_of(label, given), "include" if rule else "exclude", rule or "")]
|
| 125 |
+
group[0] += turns
|
| 126 |
+
group[1] += characters
|
| 127 |
+
group[2] += 1
|
| 128 |
+
rows = [[role, decision, rule, *counts] for (role, decision, rule), counts in groups.items()]
|
| 129 |
+
return sorted(rows, key=lambda row: (-row[4], row[0], row[1], row[2]))
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def write_roles(path: Path, rows: list[list]) -> None:
|
| 133 |
+
with path.open("w", encoding="utf-8", newline="") as stream:
|
| 134 |
+
writer = csv.writer(stream, lineterminator="\n")
|
| 135 |
+
writer.writerow(ROLES_HEADER)
|
| 136 |
+
writer.writerows(rows)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def cut_turn(row: dict, attribution: dict) -> tuple[list[dict], dict]:
|
| 140 |
+
"""(pieces, page-block counts) of one input turn (steps 1 and 2 of the module docstring).
|
| 141 |
+
|
| 142 |
+
A piece is the row fields and the sidecar fields in one dict; `token_count` is None where the
|
| 143 |
+
text is new and has to be counted."""
|
| 144 |
+
lines, counts = strip_page_blocks(row["text"].split("\n"))
|
| 145 |
+
pieces = []
|
| 146 |
+
for k, (label, body) in enumerate(split_at_labels(lines)):
|
| 147 |
+
piece = {**row, **attribution, "text": turn_text(body)}
|
| 148 |
+
if k:
|
| 149 |
+
piece.update(id=f"{row['id']}_{k}", author=label, speaker=label)
|
| 150 |
+
if k or piece["text"] != row["text"]:
|
| 151 |
+
piece["token_count"] = None
|
| 152 |
+
pieces.append(piece)
|
| 153 |
+
return pieces, counts
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def build(input_dir: Path, out_dir: Path) -> dict:
|
| 157 |
+
for name, sha in INPUT_SHA256.items():
|
| 158 |
+
check_pin(input_dir / name, sha, f"restore it with `git checkout 0bbdb0d -- data/{SOURCE}/{name}`")
|
| 159 |
+
table = pq.read_table(input_dir / f"{SOURCE}.parquet")
|
| 160 |
+
with (input_dir / f"{SOURCE}.attribution.jsonl").open(encoding="utf-8") as stream:
|
| 161 |
+
sidecar = [json.loads(line) for line in stream]
|
| 162 |
+
stats = json.loads((input_dir / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 163 |
+
rows = table.to_pylist()
|
| 164 |
+
if [r["id"] for r in rows] != [a["id"] for a in sidecar]:
|
| 165 |
+
raise SystemExit("the attribution sidecar does not line up with the input Parquet")
|
| 166 |
+
recomputed = shard_stats(rows, sidecar)
|
| 167 |
+
if recomputed != {key: stats[key] for key in recomputed}:
|
| 168 |
+
raise SystemExit("the input stats.json does not describe the input Parquet")
|
| 169 |
+
|
| 170 |
+
pieces, page_blocks = [], Counter()
|
| 171 |
+
for row, attribution in zip(rows, sidecar):
|
| 172 |
+
cut, counts = cut_turn(row, attribution)
|
| 173 |
+
pieces += cut
|
| 174 |
+
page_blocks.update(counts)
|
| 175 |
+
rows_split_out = len(pieces) - len(rows)
|
| 176 |
+
if len({p["id"] for p in pieces}) != len(pieces):
|
| 177 |
+
raise SystemExit("cutting the turns made duplicate ids")
|
| 178 |
+
long_enough = [p for p in pieces if len(p["text"]) >= MIN_TURN_CHARS]
|
| 179 |
+
too_short = len(pieces) - len(long_enough)
|
| 180 |
+
pieces, joint_dup, exact_dup = dedup_turns(long_enough)
|
| 181 |
+
if joint_dup:
|
| 182 |
+
raise SystemExit("the input holds a joint-sitting duplicate; it was deduplicated before")
|
| 183 |
+
new_text = [p for p in pieces if p["token_count"] is None]
|
| 184 |
+
for piece, tokens in zip(new_text, count_tokens([p["text"] for p in new_text])):
|
| 185 |
+
piece["token_count"] = tokens
|
| 186 |
+
|
| 187 |
+
rule_of = {label: classify_speaker(label) for label in {p["author"] for p in pieces}}
|
| 188 |
+
label_stats: dict[str, list] = {label: [0, 0, rule] for label, rule in rule_of.items()}
|
| 189 |
+
for piece in pieces:
|
| 190 |
+
entry = label_stats[piece["author"]]
|
| 191 |
+
entry[0] += 1
|
| 192 |
+
entry[1] += len(piece["text"])
|
| 193 |
+
kept = [p for p in pieces if rule_of[p["author"]]]
|
| 194 |
+
dropped = [p for p in pieces if not rule_of[p["author"]]]
|
| 195 |
+
kept_rows = [{field: p[field] for field in FIELDS} for p in kept]
|
| 196 |
+
kept_sidecar = [{key: p[key] for key in ATTRIBUTION_KEYS} | {"id": p["id"]} for p in kept]
|
| 197 |
+
|
| 198 |
+
removed = {"turns": len(dropped), "characters": sum(len(p["text"]) for p in dropped),
|
| 199 |
+
"tokens": sum(p["token_count"] for p in dropped),
|
| 200 |
+
"speaker_labels": sum(1 for rule in rule_of.values() if rule is None)}
|
| 201 |
+
kept_by_rule = {}
|
| 202 |
+
for rule_id, _ in SPEAKER_RULES:
|
| 203 |
+
matched = [entry for entry in label_stats.values() if entry[2] == rule_id]
|
| 204 |
+
kept_by_rule[rule_id] = {"speaker_labels": len(matched), "turns": sum(e[0] for e in matched),
|
| 205 |
+
"characters": sum(e[1] for e in matched)}
|
| 206 |
+
|
| 207 |
+
stats.update(shard_stats(kept_rows, kept_sidecar))
|
| 208 |
+
stats["rows_split_out"] = rows_split_out
|
| 209 |
+
stats["rejected_too_short"] = too_short
|
| 210 |
+
stats["rejected_exact_dup"] += exact_dup
|
| 211 |
+
stats["rejected_not_official_speaker"] = removed["turns"]
|
| 212 |
+
stats["rejected"] += too_short + exact_dup + removed["turns"]
|
| 213 |
+
stats["page_blocks"] = {"removed": page_blocks["blocks"], "hyphenated_words_rejoined": page_blocks["rejoined"],
|
| 214 |
+
"glued_footers_repaired": page_blocks["fused"],
|
| 215 |
+
"stray_footers_removed": page_blocks["lone_footers"]}
|
| 216 |
+
stats["speaker_allowlist"] = {"input_sha256": INPUT_SHA256, "removed": removed, "kept_by_rule": kept_by_rule}
|
| 217 |
+
if stats["kept"] + stats["rejected"] != stats["rows_raw_extracted"] + rows_split_out:
|
| 218 |
+
raise SystemExit("stats drop counts do not add up to the extracted rows")
|
| 219 |
+
|
| 220 |
+
replace_all({
|
| 221 |
+
out_dir / f"{SOURCE}.parquet": lambda p: pq.write_table(
|
| 222 |
+
pa.Table.from_pylist(kept_rows, schema=table.schema), p, compression="zstd"),
|
| 223 |
+
out_dir / f"{SOURCE}.attribution.jsonl": lambda p: p.write_text(
|
| 224 |
+
"".join(json.dumps(line, ensure_ascii=False, sort_keys=True) + "\n" for line in kept_sidecar), encoding="utf-8"),
|
| 225 |
+
out_dir / f"{SOURCE}.stats.json": lambda p: write_json(p, stats),
|
| 226 |
+
out_dir / ROLES_CSV: lambda p: write_roles(
|
| 227 |
+
p, roles_table({label: tuple(entry) for label, entry in label_stats.items()})),
|
| 228 |
+
})
|
| 229 |
+
return stats
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def main() -> None:
|
| 233 |
+
parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
| 234 |
+
parser.add_argument("--data", type=Path, default=DATA, help="directory holding the (restored) input files; outputs are written there")
|
| 235 |
+
args = parser.parse_args()
|
| 236 |
+
print(json.dumps(build(args.data, args.data), indent=2, ensure_ascii=False))
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
if __name__ == "__main__":
|
| 240 |
+
main()
|
src/fetch_sejm_committee_transcripts.py
CHANGED
|
@@ -3,8 +3,26 @@
|
|
| 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
|
| 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
|
|
@@ -27,6 +45,7 @@ import pathlib
|
|
| 27 |
import re
|
| 28 |
import subprocess
|
| 29 |
import sys
|
|
|
|
| 30 |
import urllib.error
|
| 31 |
import urllib.request
|
| 32 |
|
|
@@ -36,6 +55,10 @@ 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(
|
|
@@ -45,32 +68,6 @@ HEADER_PAT = re.compile(
|
|
| 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)
|
|
@@ -84,65 +81,24 @@ def pdf_text(path: str) -> str:
|
|
| 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 |
-
|
| 93 |
-
|
| 94 |
-
|
| 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 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 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):
|
|
@@ -182,6 +138,462 @@ def dedup_turns(rows):
|
|
| 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)")
|
|
@@ -361,7 +773,7 @@ def extract(terms):
|
|
| 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) <
|
| 365 |
continue
|
| 366 |
row = {
|
| 367 |
"term": str(term),
|
|
@@ -385,11 +797,27 @@ def extract(terms):
|
|
| 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:
|
|
@@ -399,19 +827,21 @@ def build(terms=(9, 10), outdir="."):
|
|
| 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
|
| 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)
|
|
@@ -422,19 +852,14 @@ def build(terms=(9, 10), outdir="."):
|
|
| 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,
|
|
|
|
| 432 |
"rejected_joint_sitting_dup": dedup_dropped, "rejected_exact_dup": exact_dup,
|
| 433 |
-
"
|
| 434 |
-
|
| 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")
|
|
|
|
| 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, PII redaction and the speaker allowlist live
|
| 7 |
+
HERE so the shard is reproducible from this script alone.
|
| 8 |
+
|
| 9 |
+
Turns: a turn starts at every label line (`split_at_labels`: a line ending with ":" whose text is a
|
| 10 |
+
speaker label, whoever the speaker is, also a label wrapped over two lines), after the PDF page-break
|
| 11 |
+
blocks (page number + stenographer initials, the title "Pełny Zapis Przebiegu Posiedzenia:", the
|
| 12 |
+
committee line "Komisji ... (nr N)") were cut out and a word hyphenated across one was rejoined
|
| 13 |
+
(`strip_page_blocks`). The pinned upstream rule (a label had to start with one of a fixed list of role
|
| 14 |
+
words and be indented at most 6 spaces) left every other speaker's words inside the previous turn; the
|
| 15 |
+
indent check is gone because the stored text has no indentation to check.
|
| 16 |
+
|
| 17 |
+
Speaker allowlist: only turns whose speaker label fully matches `SPEAKER_RULES` (MPs,
|
| 18 |
+
members of the government, heads of constitutional organs, Sejm/Senate staff) or is one of
|
| 19 |
+
the typo labels in `EXACT_LABELS` are kept; guests, experts, union/NGO/company representatives, "Głos z sali" and
|
| 20 |
+
every unrecognised label are dropped. The shard on the Hub was filtered with
|
| 21 |
+
src/clean_sejm_committee_transcripts.py (the PDF cache is not kept): it applies the same page-block
|
| 22 |
+
stripper and label detector to the stored turn text, so it cuts the same lines a fresh parse would.
|
| 23 |
+
A turn it cuts into pieces keeps its id for the first piece and gets `<id>_<k>` for the next ones, so the
|
| 24 |
+
ids differ from a fresh `build()`, which numbers the cut turns consecutively (`turn_idx` and the
|
| 25 |
+
content hash differ too); the text and the authors are the same.
|
| 26 |
|
| 27 |
Source: Kancelaria Sejmu RP, https://api.sejm.gov.pl/
|
| 28 |
(`GET /sejm/term{n}/committees/{code}/sittings/{num}/pdf`, the
|
|
|
|
| 45 |
import re
|
| 46 |
import subprocess
|
| 47 |
import sys
|
| 48 |
+
import unicodedata
|
| 49 |
import urllib.error
|
| 50 |
import urllib.request
|
| 51 |
|
|
|
|
| 55 |
ADDED = "2026-09-18"
|
| 56 |
LICENSE = "public-domain (official documents)"
|
| 57 |
FIELDS = ["id", "text", "source", "added", "created", "token_count", "license", "author"]
|
| 58 |
+
# The attribution sidecar line of a row: these keys of the parsed turn, plus the row id.
|
| 59 |
+
ATTRIBUTION_KEYS = ("term", "committee_code", "committee_name", "sitting_num", "date", "turn_idx", "speaker",
|
| 60 |
+
"content_sha1", "source_url")
|
| 61 |
+
MIN_TURN_CHARS = 15
|
| 62 |
|
| 63 |
# ---------------------------------------------------------------- parse_zapis
|
| 64 |
HEADER_PAT = re.compile(
|
|
|
|
| 68 |
PAGEFOOT_PAT = re.compile(r"^\s*[a-z]{1,3}\.?\s+\d{1,4}\s*$")
|
| 69 |
PAGENUM_PAT = re.compile(r"^\s*\d{1,4}\s*$")
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def dehyphenate(text: str) -> str:
|
| 72 |
# soft hyphenation join: "Kon-\nrada" -> "Konrada"
|
| 73 |
return re.sub(r"([a-ząćęłńóśźż])-\s*\n\s*([a-ząćęłńóśźż])", r"\1\2", text)
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
def parse_pdf(path: str):
|
| 84 |
+
"""Return (transcript_type, header_text, turns) where turns = [(speaker, text)].
|
| 85 |
+
|
| 86 |
+
Turns start at every label line (`split_at_labels`), whoever the speaker is; the allowlist is
|
| 87 |
+
applied later. Page-break blocks are cut out first (`strip_page_blocks`)."""
|
| 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 = [s for s in (ln.strip() for ln in raw.splitlines())
|
| 92 |
+
if s and not (HEADER_PAT.match(s) or PAGEFOOT_PAT.match(s) or PAGENUM_PAT.match(s))]
|
| 93 |
+
pieces = split_at_labels(strip_page_blocks(lines)[0])
|
| 94 |
+
if len(pieces) == 1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
return "nospeaker", None, []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
turns = []
|
| 97 |
+
for label, body in pieces[1:]:
|
| 98 |
+
text = turn_text(body)
|
| 99 |
+
if len(text) >= MIN_TURN_CHARS:
|
| 100 |
+
turns.append((label, text))
|
| 101 |
+
return "pelny_zapis", " ".join(pieces[0][1]), turns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
def doc_id(term, code, num, text):
|
|
|
|
| 138 |
return final, dropped, exact_dup
|
| 139 |
|
| 140 |
|
| 141 |
+
# ------------------------------------------------------------------ speaker allowlist
|
| 142 |
+
# Legal basis is the official-documents exclusion (Polish copyright act art. 4 pkt 2). It
|
| 143 |
+
# covers statements made in office by MPs, senators, members of the government, heads of
|
| 144 |
+
# constitutional organs and Sejm/Senate staff. Guests, experts, union/NGO/company
|
| 145 |
+
# representatives and the anonymous "Głos z sali" are not covered, so their turns are
|
| 146 |
+
# dropped. The allowlist is fail-closed: a turn is kept only if its raw `speaker` label
|
| 147 |
+
# matches one rule below IN FULL (name tail included) or is one of the typo labels in
|
| 148 |
+
# EXACT_LABELS; every other label is dropped, including any label this code has never seen.
|
| 149 |
+
# Rule ids are persisted in the stats and in data/<SOURCE>/<SOURCE>.speaker-roles.csv, so keep
|
| 150 |
+
# them stable.
|
| 151 |
+
_UP = "A-ZĄĆĘŁŃÓŚŹŻ"
|
| 152 |
+
_LO = "a-ząćęłńóśźżéüöäèç"
|
| 153 |
+
_TOK = rf"[{_UP}][{_LO}'’.]+(?:(?: ?[-–]){{1,2}} ?[{_UP}][{_LO}'’]+)*" # Kowalski, Kowalska-Nowak, Kowalska – Nowak, O'Neill, "Kowalska- -Nowak"
|
| 154 |
+
_NAME = rf"{_TOK}(?: (?:(?:[Vv]el|de|von|van) )?{_TOK}){{1,2}}" # 2-3 tokens, optional particle
|
| 155 |
+
_TAIL = r"(?: (?:prof\.|dr|hab\.|inż\.|mgr))*(?: " + _NAME + ")?" # titles + optional name
|
| 156 |
+
# Party tag after a name: "(PiS)", glued "Kowalski(PiS)", "Kowalski, (KP)", and the typos "((PSL-TD)", "(PSL-TD".
|
| 157 |
+
_PARTY = r"[ ,.]{0,3}(?:\(\(?[^()\n]{1,60}\)|\([^()\s]{1,30})"
|
| 158 |
+
# "Poseł Jan Kowalski (PiS)", surname-only "Poseł Kowalski (PiS)"; without a party only when the label
|
| 159 |
+
# says the MP is outside the committee ("Poseł Jan Kowalski – spoza składu Komisji", party may follow).
|
| 160 |
+
# A party tag may be followed by a note on whom the MP speaks for. The label must name the MP: a bare
|
| 161 |
+
# "Poseł" or "Poseł (PiS)" never matches.
|
| 162 |
+
_SPOZA = r" ?[–−-] ?(?:poseł )?spoza sk[łl]ad(?:u|ów) (?:[Kk]omisji|podkomisji)"
|
| 163 |
+
_NOTE = r"(?:" + _SPOZA + r"|(?: ?[–−-] ?przedstawiciel Komisji| reprezentując[ayą]) [^()\n]{1,80})"
|
| 164 |
+
_MP = (rf"(?:[Pp]oseł|[Pp]osłanka)(?: wnioskodawc[aęy])? "
|
| 165 |
+
rf"(?:{_NAME}(?:{_PARTY}(?:{_NOTE})?|{_SPOZA}(?:{_PARTY})?)|{_TOK}{_PARTY}(?:{_NOTE})?)")
|
| 166 |
+
# "Podkomisji", with the topic some subcommittees carry: "Podkomisji d.s. Ponownego Zbadania Wypadku Lotniczego".
|
| 167 |
+
_SUBCOMMITTEE = rf"[Pp]odkomisji(?: (?:d\.s\.|ds\.|do [Ss]praw)(?: [{_UP}{_LO}-]+){{1,10}})?"
|
| 168 |
+
_CHAIR_DEPUTY = r"(?:(?:[Pp]ierwsz[ya]|[Dd]rug[ia]) )?[Zz]astęp(?:ca|czyni) przewodnicząc(?:ego|ej)"
|
| 169 |
+
_SEJM_BUREAU = (r"(?:BAS|Bas|BEOS|Beos|Biur\w+ Analiz Sejmowych"
|
| 170 |
+
r"|Biur\w+ Ekspertyz(?: (?i:i))? Ocen(?:y)? Skutków Regulacji)(?: (?:w )?Kancelarii Sejmu(?: RP)?)?")
|
| 171 |
+
# Other units of the Kancelaria Sejmu whose directors are Sejm staff; "KS" is the label's own short form of
|
| 172 |
+
# "Kancelarii Sejmu" ("Dyrektor BOM KS", "Dyrektor biura KS"), BKSP the Biuro Komunikacji Społecznej.
|
| 173 |
+
_SEJM_OFFICE = (rf"(?:{_SEJM_BUREAU}|Biur\w+ Legislacy\w+|Biur\w+ Komisji Sejmowych|Biur\w+ Obsługi Posłów|Bibliotek\w+ Sejmow\w+|BKSP"
|
| 174 |
+
r"|[\w -]+ Kancelarii (?:Sejmu|Senatu)|(?:[Bb]iura(?: [\w-]+)?|B[A-ZŁ]{1,3}) KS)")
|
| 175 |
+
_BL = r"(?:BL|Biur\w+ Legislacy\w+)(?: (?:w )?Kancelarii Sejmu)?" # Biuro Legislacyjne ("Legislacyjego" typo too)
|
| 176 |
+
_MINISTRY_WORDS = "|".join(r"ds\." if w == "ds." else w for w in (
|
| 177 |
+
"rolnictwa rozwoju przedsiębiorczości wsi klimatu środowiska zdrowia sportu turystyki edukacji narodowej narodowego nauki "
|
| 178 |
+
"szkolnictwa wyższego kultury dziedzictwa spraw wewnętrznych administracji sprawiedliwości "
|
| 179 |
+
"zagranicznych cyfryzacji technologii polityki senioralnej gospodarki morskiej żeglugi "
|
| 180 |
+
"śródlądowej przemysłu funduszy regionalnej rodziny pracy społecznej finansów infrastruktury "
|
| 181 |
+
"obrony energii aktywów państwowych równości Unii Europejskiej europejskich UE ds. do i w z "
|
| 182 |
+
"KPRM Kancelarii Prezesa Rady Ministrów RM członek szef koordynator służb specjalnych "
|
| 183 |
+
"prokurator generalny przewodniczący Komitetu Stałego").split())
|
| 184 |
+
_MINISTRY_ABBREVIATION = r"\bM[A-ZŚŻŁ][A-Za-zŚŻŁśżł]{0,6}\b"
|
| 185 |
+
_STATE_SECRETARY_WORDS = _MINISTRY_WORDS + "|" + "|".join(
|
| 186 |
+
"we Ministerstwie Ministerstwa Ministerstwo zastępca szefa pełnomocnik rządu główny generalny generalna "
|
| 187 |
+
"konserwator geolog kraju przyrody inspektor informacji finansowej zabytków leśnictwa łowiectwa osób "
|
| 188 |
+
"niepełnosprawnych wsi CPK KAS dla RP spraw".split())
|
| 189 |
+
# What a state secretary may hold besides the post ("pełnomocnik rządu do spraw równego traktowania",
|
| 190 |
+
# "szef Krajowej Administracji Skarbowej"): an office noun, then letters-only words (no digits, so
|
| 191 |
+
# "w latach 2015–2018" never passes), then the name. The same offices may stand BEFORE the rank
|
| 192 |
+
# ("Pełnomocnik rządu ds. X, sekretarz stanu w MP NAME", "Zastępca szefa KPRM podsekretarz stanu NAME");
|
| 193 |
+
# there only the government offices, not "przewodniczący"/"sekretarz", open the label.
|
| 194 |
+
_OFFICE_WORD = r"[^\W\d_]+(?:-[^\W\d_]+)*[.,]?"
|
| 195 |
+
_OFFICE_NOUN = r"pełnomocni(?:k|czka)|szef(?:owa)?|zastępc[ay]|zastępczyni|wiceprzewodnicząc[ya]|główn[yae]"
|
| 196 |
+
_STATE_OFFICE = (rf"[ ,–-]+(?:(?:i|oraz) )?(?i:{_OFFICE_NOUN}|przewodnicząc[ya]|sekretarz)(?: {_OFFICE_WORD}){{0,14}}")
|
| 197 |
+
_STATE_PREFIX = rf"(?i:{_OFFICE_NOUN})(?: {_OFFICE_WORD}){{0,14}}[ ,–-]+"
|
| 198 |
+
_STATE_RANK = r"(?:[Pp]od)?[Ss]ekretarza? [Ss]tanu"
|
| 199 |
+
_STATE_BODY = rf"(?:[ ,–-]+(?:(?i:{_STATE_SECRETARY_WORDS})|{_MINISTRY_ABBREVIATION}))*" # "w MRiPS", "w Ministerstwie Zdrowia"
|
| 200 |
+
# A state secretary's label names a government body, never the President's office ("Kancelaria Prezydenta",
|
| 201 |
+
# KPRP, BPM stay out: 1A) and never a former post ("były podsekretarz stanu", "b. sekretarz stanu").
|
| 202 |
+
_GOVERNMENT_BODY = (rf"(?:{_MINISTRY_ABBREVIATION}|(?i:ministerst)|KPRM|Kancelarii Prezesa Rady Ministrów"
|
| 203 |
+
r"|Komitetu (?:do [Ss]praw|ds\.) Pożytku Publicznego)")
|
| 204 |
+
_NOT_STATE_SECRETARY = r"(?:Prezydent|KPRP|KP RP|BPM|(?i:\bbył|ówczesn|dawn)|\bb\.)"
|
| 205 |
+
_CONSTITUTIONAL_HEAD = "|".join([
|
| 206 |
+
r"Prezes (?:NIK|Najwyższej Izby Kontroli)",
|
| 207 |
+
r"Prezes (?:NBP|Narodowego Banku Polskiego)",
|
| 208 |
+
r"Prezes (?:TK|Trybunału Konstytucyjnego)",
|
| 209 |
+
r"Prezes (?:NSA|Naczelnego Sądu Administracyjnego)",
|
| 210 |
+
r"Pierwszy Prezes (?:SN|Sądu Najwyższego)",
|
| 211 |
+
r"Rzecznik [Pp]raw [Oo]bywatelskich",
|
| 212 |
+
r"Rzecznik [Pp]raw [Dd]ziecka",
|
| 213 |
+
r"Przewodnicząc(?:y|a) (?:KRRiT|Krajowej Rady Radiofonii i Telewizji)",
|
| 214 |
+
r"Przewodnicząc(?:y|a) (?:KRS|Krajowej Rady Sądownictwa)",
|
| 215 |
+
r"Prokurator Generalny",
|
| 216 |
+
])
|
| 217 |
+
|
| 218 |
+
# Standing committees of the Sejm (terms 9 and 10, as in the `committee_name` column) after "Komisji", i.e. in
|
| 219 |
+
# the genitive: "Komisja Regulaminowa, ..." is "Komisji Regulaminowej, ...". Extraordinary and investigative
|
| 220 |
+
# committees are not listed: no secretary of one is labelled in the data.
|
| 221 |
+
_SEJM_COMMITTEES = "|".join(re.escape(name) for name in (
|
| 222 |
+
"Administracji i Spraw Wewnętrznych", "Cyfryzacji, Innowacyjności i Nowoczesnych Technologii",
|
| 223 |
+
"do Spraw Deregulacji", "do Spraw Dzieci i Młodzieży", "do Spraw Energii, Klimatu i Aktywów Państwowych",
|
| 224 |
+
"do Spraw Kontroli Państwowej", "do Spraw Petycji", "do Spraw Unii Europejskiej",
|
| 225 |
+
"Edukacji i Nauki", "Edukacji, Nauki i Młodzieży", "Etyki Poselskiej", "Finansów Publicznych",
|
| 226 |
+
"Gospodarki i Rozwoju", "Gospodarki Morskiej i Żeglugi Śródlądowej", "Infrastruktury",
|
| 227 |
+
"Kultury Fizycznej, Sportu i Turystyki", "Kultury i Środków Przekazu",
|
| 228 |
+
"Kultury, Dziedzictwa Narodowego i Środków Przekazu", "Łączności z Polakami za Granicą",
|
| 229 |
+
"Mniejszości Narodowych i Etnicznych", "Obrony Narodowej", "Ochrony Środowiska, Zasobów Naturalnych i Leśnictwa",
|
| 230 |
+
"Odpowiedzialności Konstytucyjnej", "Polityki Senioralnej", "Polityki Społecznej i Rodziny",
|
| 231 |
+
"Regulaminowej, Spraw Poselskich i Immunitetowych", "Rolnictwa i Rozwoju Wsi",
|
| 232 |
+
"Samorządu Terytorialnego i Polityki Regionalnej", "Spraw Zagranicznych", "Sprawiedliwości i Praw Człowieka",
|
| 233 |
+
"Ustawodawczej", "Zdrowia"))
|
| 234 |
+
|
| 235 |
+
# (rule id, pattern matched with fullmatch). First match wins.
|
| 236 |
+
SPEAKER_RULES = [
|
| 237 |
+
("mp", re.compile(_MP)),
|
| 238 |
+
# "Przewodniczący poseł NAME (PARTY)" (the party may be missing), the older order
|
| 239 |
+
# "Poseł przewodniczący NAME (PARTY)", and "Przewodnicząca NAME (PARTY)", where the party tag stands
|
| 240 |
+
# in for the missing "poseł". A "Przewodniczący NAME" without a party tag never matches.
|
| 241 |
+
# A subcommittee's chair or deputy chair ("Przewodniczący Podkomisji d.s. X poseł NAME (PARTY)",
|
| 242 |
+
# "Pierwszy zastępca przewodniczącego Podkomisji poseł NAME") only with "poseł"/"posłanka" ahead of the name: a
|
| 243 |
+
# subcommittee can be a ministry's, with members who are no MPs.
|
| 244 |
+
# ponytail: any 2-3 capitalised words before the party tag count as the name; tighten if an
|
| 245 |
+
# "Przewodniczący Rady Miasta (PO)"-type label ever shows up (the 2026-10 data has none).
|
| 246 |
+
("mp_committee_chair", re.compile(
|
| 247 |
+
rf"(?:Wice)?[Pp]rzewodnicząc[ya](?: {_SUBCOMMITTEE})? (?:{_MP}|(?:poseł|posłanka) {_NAME})"
|
| 248 |
+
rf"|{_CHAIR_DEPUTY} {_SUBCOMMITTEE} (?:{_MP}|(?:poseł|posłanka) {_NAME})"
|
| 249 |
+
rf"|(?:[Pp]oseł|[Pp]osłanka) (?:wice)?przewodnicząc[yą] {_NAME}{_PARTY}"
|
| 250 |
+
rf"|Przewodnicząc[ya] {_NAME}{_PARTY}")),
|
| 251 |
+
("senator", re.compile(rf"(?:Senator|Senatorka)(?: RP)? {_NAME}(?:{_PARTY})?")),
|
| 252 |
+
("sejm_senate_marshal", re.compile(
|
| 253 |
+
rf"(?:Wicemarszałkini|(?:Wice)?[Mm]arszałek) (?:Sejmu|Senatu)(?: (?:RP|Rzeczypospolitej Polskiej))?(?:,? poseł)?{_TAIL}(?:{_PARTY})?")),
|
| 254 |
+
# "Ministra" is the feminine title; "Szef KPRM" is a minister-member of the Council of Ministers;
|
| 255 |
+
# "Członek Rady Ministrów" is a member by definition. "Minister pełnomocny" (an ambassador) never matches.
|
| 256 |
+
("government_member", re.compile(
|
| 257 |
+
rf"(?:Wice)?[Pp]rezes (?:Rady Ministrów|RM)(?:, minister(?:[ ,]+[{_LO}]+)+)?{_TAIL}"
|
| 258 |
+
rf"|Minist(?:er|ra)(?:[ ,–-]+(?i:{_MINISTRY_WORDS}))*{_TAIL}"
|
| 259 |
+
rf"|Szef (?:KPRM|Kancelarii Prezesa Rady Ministrów){_TAIL}"
|
| 260 |
+
rf"|Członek Rady Ministrów(?:[ ,]+(?:minister )?(?:ds\.|do spraw)(?: [{_LO}]+){{1,3}})?{_TAIL}")),
|
| 261 |
+
# Secretaries/undersecretaries of state in a ministry or the PM's chancellery, the rank in any
|
| 262 |
+
# position: first ("Sekretarz stanu w MZ NAME"), after the government offices they hold ("Pełnomocnik
|
| 263 |
+
# rządu do spraw X, sekretarz stanu w MRiPS NAME", "Zastępca szefa KPRM podsekretarz stanu NAME") or
|
| 264 |
+
# after the name ("Anna Radwan-Röhrenschef podsekretarz stanu w Ministerstwie Spraw Zagranicznych").
|
| 265 |
+
# Between the rank and the name only ministry words, ministry abbreviations (MF, MSWiA) and the
|
| 266 |
+
# government offices they hold ("główny konserwator zabytków") are allowed; a surname alone is
|
| 267 |
+
# enough after the body ("w MSiT Gut-Mostowy"). The label must name a government body and no
|
| 268 |
+
# presidential-office marker (KPRP etc.). Prose that merely contains the rank ("Witam panią X,
|
| 269 |
+
# sekretarz stanu w ...") starts with neither an office noun nor a name, so it never matches.
|
| 270 |
+
("state_secretary", re.compile(
|
| 271 |
+
rf"(?!.*{_NOT_STATE_SECRETARY})(?=.*{_GOVERNMENT_BODY})"
|
| 272 |
+
rf"(?:(?:{_STATE_PREFIX})?{_STATE_RANK}{_STATE_BODY}(?:{_STATE_OFFICE} {_NAME}|{_TAIL}| {_TOK})"
|
| 273 |
+
rf"|{_NAME} {_STATE_RANK}{_STATE_BODY})")),
|
| 274 |
+
("constitutional_organ_head", re.compile(rf"(?:{_CONSTITUTIONAL_HEAD}){_TAIL}")),
|
| 275 |
+
# Plain "Legislator NAME" is the transcripts' own form for the Biuro Legislacyjne of the
|
| 276 |
+
# Kancelaria Sejmu (the same names carry an explicit BL affiliation elsewhere). Legislators
|
| 277 |
+
# of clubs, ministries and other bodies always carry their affiliation, so they never match.
|
| 278 |
+
# Also "Legislator sejmowy", "Legislator z Kancelarii Sejmu" and the name-first order
|
| 279 |
+
# "Legislator NAME z Biura Legislacyjnego".
|
| 280 |
+
("sejm_legislator", re.compile(
|
| 281 |
+
rf"Legislator(?:ka)? (?:(?:[zZw] )?{_BL}{_TAIL}|(?:sejmowy|[zZ] Kancelarii Sejmu){_TAIL}|{_NAME}(?: [zZw] {_BL})?)")),
|
| 282 |
+
# BAS/BEOS staff: experts and specialists (optionally "ds. <topic>"), heads of a BAS division
|
| 283 |
+
# ("Naczelnik wydziału w BAS") and the committee-secretariat staff of BAS. An "Ekspert zewnętrzny"
|
| 284 |
+
# (commissioned from outside) is not staff and never matches.
|
| 285 |
+
("sejm_bureau_expert", re.compile(
|
| 286 |
+
rf"(?:Ekspert(?:ka)?|(?:Główny )?[Ss]pecjalist(?:a|ka))(?: (?:[zw] )?(?i:ds\.|do spraw)(?: [{_UP}{_LO}-]+){{1,6}})?(?: [zw])? "
|
| 287 |
+
+ _SEJM_BUREAU + _TAIL
|
| 288 |
+
+ rf"|Naczelnik [Ww]ydziału(?: (?:[{_UP}][{_LO}]+(?:-[{_UP}][{_LO}]+)?|[iwz])){{0,7}} {_SEJM_BUREAU}{_TAIL}"
|
| 289 |
+
+ rf"|Pracownic[ay] sekretariatu Komisji w {_SEJM_BUREAU}{_TAIL}")),
|
| 290 |
+
# Heads of Kancelaria Sejmu/Senatu units: the Chancellery, BAS/BEOS, Biuro Legislacyjne, Biuro
|
| 291 |
+
# Komisji Sejmowych, the Sejm Library, the Marshal's cabinet and the Marshal's Guard (whose "Ekspert"
|
| 292 |
+
# is Sejm staff too, so it sits in this rule: rule ids stay stable).
|
| 293 |
+
# The deputy chief ("Zastępca szefa Kancelarii Sejmu") and the chief in the feminine are included.
|
| 294 |
+
("sejm_senate_office_head", re.compile(
|
| 295 |
+
r"(?:(?:Zastępca [Ss]zefa|Szef(?:owa)?) (?:Kancelarii (?:Sejmu|Senatu)(?: RP| Rzeczypospolitej Polskiej)?|KS)"
|
| 296 |
+
rf"|(?:(?:Wice)?[Dd]yrektor|P\.o\. dyrektora) {_SEJM_OFFICE}"
|
| 297 |
+
r"|Dyrektor generalny kierujący [Gg]abinetem [Mm]arszałka Sejmu(?: RP)?"
|
| 298 |
+
rf"|(?:Komendant|Ekspert) Straży Marszałkowskiej){_TAIL}")),
|
| 299 |
+
# Secretaries of Sejm committees are Sejm staff (Biuro Komisji Sejmowych): "Sekretarz Komisji FIRST
|
| 300 |
+
# LAST", the same with the name of a Sejm committee ahead of the name ("Sekretarz Komisji Zdrowia
|
| 301 |
+
# NAME"), "Sekretarz Komisji z Biura Spraw Międzynarodowych NAME" and "Starszy sekretarz". The name
|
| 302 |
+
# is always two tokens: a secretary of a works council or of a joint commission carries more words
|
| 303 |
+
# ("Komisji Wspólnej Rządu i Samorządu Terytorialnego"), and the adjective forms below ("Komisji
|
| 304 |
+
# Zakładowej NSZZ ...") are excluded explicitly. A committee name the list does not know is dropped.
|
| 305 |
+
("sejm_committee_secretary", re.compile(
|
| 306 |
+
rf"(?:Starszy sekretarz|Sekretarz) Komisji (?:(?!(?:Zakładowej|Międzyzakładowej|Wspólnej|Krajowej|Regionalnej|Rewizyjnej|Okręgowej) ){_TOK} {_TOK}"
|
| 307 |
+
rf"|(?:{_SEJM_COMMITTEES}|z Biura (?:Spraw Międzynarodowych|Komisji Sejmowych)) {_TOK} {_TOK})")),
|
| 308 |
+
]
|
| 309 |
+
|
| 310 |
+
# Labels that are official speakers beyond doubt but that no rule above can take without also taking
|
| 311 |
+
# look-alikes. Each is a transcript typo or a bare name-plus-party form, matched in full and in NFC, mapped to
|
| 312 |
+
# the rule it belongs to:
|
| 313 |
+
# - a misspelt MP name ("Szynkowski vel sęk", "TchórzePwski", glued "TomaszLatos"), the party tag is there;
|
| 314 |
+
# - a stray "z" after "Legislator" (a rule for it would also take "Legislator z Ministerstwa Zdrowia");
|
| 315 |
+
# - a club tag "(KO)" on a Biuro Legislacyjne legislator (her label "Legislator Katarzyna Abramowicz
|
| 316 |
+
# z Biura Legislacyjnego" shows the affiliation; a rule for "Legislator NAME (PARTY)" would also take
|
| 317 |
+
# club legislators).
|
| 318 |
+
# Keep this short: a new label belongs here only after it is checked against the same person's other labels.
|
| 319 |
+
EXACT_LABELS = {
|
| 320 |
+
"Poseł Szymon Szynkowski vel sęk (PiS)": "mp",
|
| 321 |
+
"Przewodniczący poseł Krzysztof TchórzePwski (PiS)": "mp_committee_chair",
|
| 322 |
+
"Przewodniczący poseł TomaszLatos (PiS)": "mp_committee_chair",
|
| 323 |
+
"Legislator z Jarosław Lichocki": "sejm_legislator",
|
| 324 |
+
"Legislator z Konrad Nietrzebka": "sejm_legislator",
|
| 325 |
+
"Legislator Katarzyna Abramowicz (KO)": "sejm_legislator",
|
| 326 |
+
# MPs labelled by name and party tag only (no "Poseł"), and chair labels with a typo in "Przewodniczący"
|
| 327 |
+
"Kamila Gasiuk-Pihowicz (KO)": "mp",
|
| 328 |
+
"Ryszard Terlecki (PiS)": "mp",
|
| 329 |
+
"Agnieszka Maria Kłopotek (PSL=TD)": "mp",
|
| 330 |
+
"zrzewodniczący poseł Tomasz Ławniczak (PiS)": "mp_committee_chair",
|
| 331 |
+
"Pewodniczący poseł Piotr Babinetz (PiS)": "mp_committee_chair",
|
| 332 |
+
# Antoni Macierewicz (an MP) as chair of the MON subcommittee on the Smolensk crash, labelled without "poseł"
|
| 333 |
+
# (the rule needs it: the subcommittee is a ministry's, its deputy chair Kazimierz Nowaczyk is no MP)
|
| 334 |
+
"Przewodniczący podkomisji Antoni Macierewicz": "mp_committee_chair",
|
| 335 |
+
"Przewodniczący Podkomisji ds. ponownego zbadania wypadku lotniczego Antoni Macierewicz": "mp_committee_chair",
|
| 336 |
+
"PodPodsekretarz stanu w MKiDN Marek Krawczyk": "state_secretary", # typo in "Podsekretarz"
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
def classify_speaker(label):
|
| 341 |
+
"""Rule id of the first allowlist rule that fully matches `label`, else None (dropped).
|
| 342 |
+
|
| 343 |
+
The label is matched in NFC: two shipped labels carry a decomposed "ó" (o + U+0301).
|
| 344 |
+
"""
|
| 345 |
+
label = unicodedata.normalize("NFC", label)
|
| 346 |
+
if label in EXACT_LABELS:
|
| 347 |
+
return EXACT_LABELS[label]
|
| 348 |
+
for rule_id, pattern in SPEAKER_RULES:
|
| 349 |
+
if pattern.fullmatch(label):
|
| 350 |
+
return rule_id
|
| 351 |
+
return None
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
# ------------------------------------------------------------------ label lines and page blocks
|
| 355 |
+
# ONE label detector and ONE page-block stripper, used by parse_pdf() (a fresh PDF) and by
|
| 356 |
+
# clean_sejm_committee_transcripts.py (stored turn text), so both cut turns at the same lines.
|
| 357 |
+
#
|
| 358 |
+
# Label line: a line that ends with ":" and whose text before it is a speaker label, that is
|
| 359 |
+
# (optional role/title words) + a personal name (+ optional party/note in brackets, an organisation
|
| 360 |
+
# in quotes, a title suffix such as "prof. ucz."), or one of the unnamed forms "Głos z sali",
|
| 361 |
+
# "Świadek nr 3", "Tłumacz". A label is also whatever classify_speaker() accepts. Anything else ending
|
| 362 |
+
# with ":" is prose and stays in the text: "Proponuję brzmienie:", "Pełny Zapis Przebiegu
|
| 363 |
+
# Posiedzenia:", "Ja zacytuję pana ministra Jana Kowalskiego:".
|
| 364 |
+
# The detector is deliberately generous (a wrongly cut sentence only splits one turn and the
|
| 365 |
+
# piece is dropped, while a missed label leaves a guest's words inside an official's turn).
|
| 366 |
+
# Known misses (measured on a seeded sample, see the commit message): a label that follows prose on the
|
| 367 |
+
# same line ("... odwołuje Poseł Paweł Jabłoński (PiS):") and a label wrapped over three lines stay in
|
| 368 |
+
# the previous text. Known false positives: prose that ends in capitalised words before a colon.
|
| 369 |
+
LABEL_MIN, LABEL_MAX = 3, 300 # the longest labels in the data (a candidate for an ambassador) are about 260
|
| 370 |
+
MAX_LABEL_TOKENS = 40
|
| 371 |
+
_ABBREV = {
|
| 372 |
+
"prof", "dr", "hab", "inż", "mgr", "ds", "im", "ul", "rez", "nadinsp", "insp", "bryg", "gen", "płk", "ppłk",
|
| 373 |
+
"mjr", "kpt", "por", "st", "mł", "podinsp", "nadkom", "kom", "asp", "sierż", "doc", "lek", "med", "ks", "sp",
|
| 374 |
+
"z", "o", "oo", "nr", "p", "r", "tzw", "pk", "kg", "adm", "cdr", "ppor", "ltn", "sztab", "dyw", "pil", "dypl",
|
| 375 |
+
"wz", "zw", "red", "arch", "jr", "sr", "n", "m", "al", "pl", "os", "woj", "pow", "gm", "min", "wicemin",
|
| 376 |
+
"pełn", "zast", "kier", "dyr", "ob", "prez", "mec", "adw",
|
| 377 |
+
}
|
| 378 |
+
_NAME_PARTICLES = {"vel", "de", "von", "van", "di", "da", "del", "della", "du", "le", "la", "ter", "ten", "der",
|
| 379 |
+
"den", "al", "el", "bin", "ibn", "ben", "dos", "das", "do", "y", "ap", "i"} # "Jordi Salvador i Duch"
|
| 380 |
+
# a lone surname is a name only right after one of these ("Poseł Kowalski", "pan Kowalski")
|
| 381 |
+
_HONORIFICS = {
|
| 382 |
+
"pan", "pani", "panie", "panu", "poseł", "posłanka", "posła", "minister", "ministrze", "ks", "ksiądz", "dr",
|
| 383 |
+
"prof", "hab", "gen", "płk", "ppłk", "mjr", "kpt", "por", "insp", "nadinsp", "adm", "bryg", "sierż", "mł",
|
| 384 |
+
"rez", "mgr", "inż", "senator", "marszałek", "prezes", "burmistrz", "wójt", "starosta", "ambasador", "radca",
|
| 385 |
+
"mecenas", "sędzia", "profesor", "doktor",
|
| 386 |
+
}
|
| 387 |
+
_PROSE_WORDS = {"ja", "Ja", "my", "My", "że", "się", "nie", "jest", "są", "to"} # never inside a label
|
| 388 |
+
_UNNAMED_LABEL = re.compile(
|
| 389 |
+
r"[Gg][łl]os(?:y)? (?:z|za|poza|ze|spoza|zza|w) \S+(?: \S+){0,3}"
|
| 390 |
+
r"|Świadek(?: nr)? \d+|Statysta [A-Z.]+|Tłumacz(?:ka)?|Protokolant(?:ka)?")
|
| 391 |
+
_BRACKETS = re.compile(r"\s*\([^()]{0,60}\)")
|
| 392 |
+
_QUOTED = re.compile(r"\s*„[^”]{0,100}”") # an organisation named in a label: Inicjatorka akcji „Hejt nie jest OK” Ewa Abart
|
| 393 |
+
_TITLE_SUFFIX = re.compile(r"\s+prof\.(?:\s+[^\W\d_]{1,6}\.?)?$") # "dr hab. Jan Kowalski prof. ucz."
|
| 394 |
+
_INITIALS = re.compile(r"(?:[^\W\d_]\.){2,3}") # "M.B."
|
| 395 |
+
_TERMINAL = ".?!:;…"
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def _name_part(part):
|
| 399 |
+
"""One hyphen-free part of a name: Kowalski, O'Neill, Coşkun, "P." (an initial), "M.B."."""
|
| 400 |
+
part = part.strip("„”\"'")
|
| 401 |
+
if _INITIALS.fullmatch(part):
|
| 402 |
+
return True
|
| 403 |
+
letters = [c for c in part if c.isalpha()]
|
| 404 |
+
if not letters or not letters[0].isupper():
|
| 405 |
+
return False
|
| 406 |
+
if len(letters) == 1:
|
| 407 |
+
return part.rstrip(".") == letters[0]
|
| 408 |
+
return any(c.islower() for c in letters) and not any(c.isdigit() for c in part)
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def _name_token(token):
|
| 412 |
+
parts = [p for p in re.split(r"[-–]", token) if p] or [""]
|
| 413 |
+
return _name_part(parts[0]) and all(_name_part(p) or p.islower() for p in parts[1:]) # "Sowiń-ski"
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
def _name_tail(tokens):
|
| 417 |
+
"""(name weight, index of its first token) of the personal name closing `tokens`; "M.B." weighs 2."""
|
| 418 |
+
i, weight = len(tokens), 0
|
| 419 |
+
while i > 0 and weight < 3:
|
| 420 |
+
token = tokens[i - 1]
|
| 421 |
+
if _name_token(token) and not (token.rstrip(".").lower() in _ABBREV and token.endswith(".") and len(token) > 2):
|
| 422 |
+
i -= 1
|
| 423 |
+
weight += 2 if _INITIALS.fullmatch(token) else 1
|
| 424 |
+
elif token.lower() in _NAME_PARTICLES and weight and i > 1 and _name_token(tokens[i - 2]):
|
| 425 |
+
i -= 1
|
| 426 |
+
else:
|
| 427 |
+
break
|
| 428 |
+
return weight, i
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
def _structural_label(body):
|
| 432 |
+
"""Role/title words + a personal name (+ bracketed party or note); `body` is the line without its colon."""
|
| 433 |
+
if _UNNAMED_LABEL.fullmatch(body):
|
| 434 |
+
return True
|
| 435 |
+
if re.search(r"[?;]|https?://", body):
|
| 436 |
+
return False
|
| 437 |
+
core = _QUOTED.sub(" ", body)
|
| 438 |
+
while "(" in core and _BRACKETS.search(core):
|
| 439 |
+
core = _BRACKETS.sub("", core, count=1)
|
| 440 |
+
core = _TITLE_SUFFIX.sub("", core.strip(" ,"))
|
| 441 |
+
if "(" in core or ")" in core or re.search(r"\bdruk\b", core):
|
| 442 |
+
return False
|
| 443 |
+
tokens = core.split()
|
| 444 |
+
if not tokens or len(tokens) > MAX_LABEL_TOKENS or any(t in _PROSE_WORDS for t in tokens):
|
| 445 |
+
return False
|
| 446 |
+
head = core.split(",")[0].split() # "Pan Imię Nazwisko, rola ..."
|
| 447 |
+
if head[0] in ("Pan", "Pani") and len(head) >= 3 and "," in core and all(_name_token(t) for t in head[1:]):
|
| 448 |
+
return True
|
| 449 |
+
weight, start = _name_tail(tokens)
|
| 450 |
+
if weight >= 2:
|
| 451 |
+
return True
|
| 452 |
+
return weight == 1 and start > 0 and tokens[start - 1].rstrip(".").lower() in _HONORIFICS
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
def is_label(body):
|
| 456 |
+
"""True if `body` (a line without its closing colon) is a speaker label."""
|
| 457 |
+
body = unicodedata.normalize("NFC", body.strip())
|
| 458 |
+
if _TITLE.search(body): # the page-block title is capitalised words like a name: never a label
|
| 459 |
+
return False
|
| 460 |
+
return LABEL_MIN <= len(body) <= LABEL_MAX and (classify_speaker(body) is not None or _structural_label(body))
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def split_at_labels(lines):
|
| 464 |
+
"""[(label or None, [lines])]; the first piece (label None) is whatever precedes the first label.
|
| 465 |
+
|
| 466 |
+
A label wrapped over two lines is one label: the line before the colon line has no closing
|
| 467 |
+
punctuation and the two joined are a label too (unless the colon line alone is an allowlisted label).
|
| 468 |
+
"""
|
| 469 |
+
pieces = [(None, [])]
|
| 470 |
+
for line in lines:
|
| 471 |
+
line = line.strip()
|
| 472 |
+
if not line:
|
| 473 |
+
continue
|
| 474 |
+
label = None
|
| 475 |
+
if line.endswith(":"):
|
| 476 |
+
body = line[:-1].rstrip()
|
| 477 |
+
previous = pieces[-1][1][-1] if pieces[-1][1] else None
|
| 478 |
+
joined = None
|
| 479 |
+
if previous is not None and previous[-1] not in _TERMINAL:
|
| 480 |
+
# a double-barrelled name broken at its hyphen is written "Karpiel-" / "-Semberecka"
|
| 481 |
+
joined = previous[:-1] + body if previous[-1] == "-" and body[:1] == "-" else f"{previous} {body}"
|
| 482 |
+
if joined and classify_speaker(body) is None and is_label(joined):
|
| 483 |
+
pieces[-1][1].pop()
|
| 484 |
+
label = joined
|
| 485 |
+
elif is_label(body):
|
| 486 |
+
label = body
|
| 487 |
+
if label is None:
|
| 488 |
+
pieces[-1][1].append(line)
|
| 489 |
+
else:
|
| 490 |
+
pieces.append((unicodedata.normalize("NFC", label), []))
|
| 491 |
+
return pieces
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
# Page-break block: footer (page number + stenographer initials), the title, and the committee line(s):
|
| 495 |
+
# 56 m.h. / Pełny Zapis Przebiegu Posiedzenia: / Komisji Finansów Publicznych (nr 12)
|
| 496 |
+
# Title variants: any case, "Pełny apis ...", doubled. Committee lines start with "Komisj" and end with "(nr N)".
|
| 497 |
+
_TITLE = re.compile(r"pe[łl]ny\s+(?:za|a)?pis\s+przebiegu\s+posiedzenia", re.I)
|
| 498 |
+
_INITIALS_TOKEN = r"(?:[^\W\d_][.,\\]+){1,4}[^\W\d_]?" # "m.h." "k.k.m." "I.W.T" (not "tys." or "Dziękuję.")
|
| 499 |
+
_FOOTER = re.compile(rf"(?:\d{{1,4}}\s+)?(?:{_INITIALS_TOKEN}\s*){{1,6}}(?:\s+\d{{1,4}})?")
|
| 500 |
+
# In the pinned data pdftotext's footer was glued onto a hyphenated word ("pro-" + "b.m. 5" became "prob.m. 5").
|
| 501 |
+
_FUSED_FOOTER = re.compile(r"(.*?[a-ząćęłńóśźż])((?:[a-z]\.){2,3}(?:\s*,\s*(?:[a-z]\.){2,3})*)\s+\d{1,4}")
|
| 502 |
+
_COMMITTEE_END = re.compile(r"\((?:[Nn]r|NR)\.? ?\d+\)?\s*[,.]?\s*$")
|
| 503 |
+
_COMMITTEE_WINDOW = 4 # lines
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _after_title(line):
|
| 507 |
+
"""Text after the (possibly doubled) title, or None if `line` is not a title line.
|
| 508 |
+
|
| 509 |
+
The colon may be missing only when the title is the whole line."""
|
| 510 |
+
rest, found = line, False
|
| 511 |
+
while match := _TITLE.match(rest):
|
| 512 |
+
found = True
|
| 513 |
+
rest = rest[match.end():].strip()
|
| 514 |
+
colon = rest.startswith(":")
|
| 515 |
+
rest = rest.lstrip(":").strip()
|
| 516 |
+
if rest and not colon:
|
| 517 |
+
return None
|
| 518 |
+
return rest if found else None
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
def _committee_end(lines, first, first_text=None):
|
| 522 |
+
"""Index after the committee lines that start at `first`, or None if no "(nr N)" ends them."""
|
| 523 |
+
for k in range(first, min(len(lines), first + _COMMITTEE_WINDOW)):
|
| 524 |
+
if _COMMITTEE_END.search(first_text if k == first and first_text is not None else lines[k]):
|
| 525 |
+
k += 1
|
| 526 |
+
while k < len(lines) and lines[k].startswith("Komisj") and _COMMITTEE_END.search(lines[k]):
|
| 527 |
+
k += 1
|
| 528 |
+
return k
|
| 529 |
+
return None
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _headless_block(lines, i, out):
|
| 533 |
+
"""A block without its title line: committee lines at `i` right after a footer."""
|
| 534 |
+
return lines[i].startswith("Komisj") and bool(out) and _is_footer(out[-1]) and _committee_end(lines, i) is not None
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
def _is_footer(line):
|
| 538 |
+
letters = len(re.findall(r"[^\W\d_]", line)) # two initials at least: "2020 r." is a year, "6 r.g" a footer
|
| 539 |
+
return len(line) <= 30 and bool(re.search(r"\d", line)) and letters >= 2 and bool(_FOOTER.fullmatch(line))
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
def _is_lone_footer(line):
|
| 543 |
+
"""A footer on its own, with no title after it: it has to be clearly one ("12 m.c.", "r.k. 7")."""
|
| 544 |
+
return _is_footer(line) and len(re.findall(r"[.,\\]", line)) >= 2
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
def strip_page_blocks(lines):
|
| 548 |
+
"""(lines without page-break blocks, counts). A word hyphenated across a block is rejoined.
|
| 549 |
+
|
| 550 |
+
The counts are {"blocks", "rejoined" (hyphenated words), "fused" (glued footers), "lone_footers"}."""
|
| 551 |
+
lines = [s for s in (line.strip() for line in lines) if s]
|
| 552 |
+
out, counts, i, n = [], {"blocks": 0, "rejoined": 0, "fused": 0}, 0, len(lines)
|
| 553 |
+
while i < n:
|
| 554 |
+
rest = _after_title(lines[i])
|
| 555 |
+
if rest is not None: # title line (the committee text may follow on it)
|
| 556 |
+
first = i if rest else i + 1
|
| 557 |
+
has_committee = bool(rest) or (i + 1 < n and lines[i + 1].startswith("Komisj"))
|
| 558 |
+
end = _committee_end(lines, first, rest or None) if has_committee else i + 1
|
| 559 |
+
if end is None: # no "(nr N)": drop the title and, if it stands alone, one committee line
|
| 560 |
+
end = i + 1 if rest else i + 2
|
| 561 |
+
elif _headless_block(lines, i, out): # the title line is missing (dropped before this module existed)
|
| 562 |
+
end = _committee_end(lines, i)
|
| 563 |
+
else:
|
| 564 |
+
out.append(lines[i])
|
| 565 |
+
i += 1
|
| 566 |
+
continue
|
| 567 |
+
counts["blocks"] += 1
|
| 568 |
+
glue = False
|
| 569 |
+
if out and _is_footer(out[-1]):
|
| 570 |
+
out.pop()
|
| 571 |
+
elif out and len(out[-1]) > 12 and (fused := _FUSED_FOOTER.fullmatch(out[-1])):
|
| 572 |
+
out[-1], glue = fused.group(1), True
|
| 573 |
+
counts["fused"] += 1
|
| 574 |
+
if out and not glue and re.search(r"[a-ząćęłńóśźż]-$", out[-1]) and end < n and lines[end][:1].islower():
|
| 575 |
+
out[-1], glue = out[-1][:-1], True
|
| 576 |
+
counts["rejoined"] += 1
|
| 577 |
+
if glue and end < n:
|
| 578 |
+
out[-1] += lines[end]
|
| 579 |
+
end += 1
|
| 580 |
+
i = end
|
| 581 |
+
kept = [line for line in out if not _is_lone_footer(line)] # a footer whose title was filtered out earlier
|
| 582 |
+
counts["lone_footers"] = len(out) - len(kept)
|
| 583 |
+
return kept, counts
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
def turn_text(lines):
|
| 587 |
+
"""Text of a turn: lines joined, soft hyphenation undone, spaces collapsed."""
|
| 588 |
+
return re.sub(r"[ \t]+", " ", dehyphenate("\n".join(lines))).strip()
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
def count_tokens(texts):
|
| 592 |
+
"""cl100k_base token counts of `texts` (also used by clean_sejm_committee_transcripts.py)."""
|
| 593 |
+
import tiktoken
|
| 594 |
+
return [len(ids) for ids in tiktoken.get_encoding("cl100k_base").encode_ordinary_batch(texts)]
|
| 595 |
+
|
| 596 |
+
|
| 597 |
# ------------------------------------------------------------------ extract_all
|
| 598 |
EMAIL = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
|
| 599 |
PESEL = re.compile(r"(?<!\d)(\d{11})(?!\d)")
|
|
|
|
| 773 |
content = hashlib.sha1("␟".join(t for _, t in turns).encode()).hexdigest()[:16]
|
| 774 |
for ti, (sp, tx) in enumerate(turns):
|
| 775 |
tx, n = redact(re.sub(r"[ \t]+", " ", tx).strip())
|
| 776 |
+
if len(tx) < MIN_TURN_CHARS:
|
| 777 |
continue
|
| 778 |
row = {
|
| 779 |
"term": str(term),
|
|
|
|
| 797 |
|
| 798 |
|
| 799 |
# ------------------------------------------------------------------ build_dataset
|
| 800 |
+
def shard_stats(rows, attrs):
|
| 801 |
+
"""Content-derived stats of a shard (also used by clean_sejm_committee_transcripts.py).
|
| 802 |
+
|
| 803 |
+
`rows` are the parquet rows, `attrs` the parallel attribution sidecar lines.
|
| 804 |
+
"""
|
| 805 |
+
dates = [a["date"] for a in attrs if a["date"]]
|
| 806 |
+
return {
|
| 807 |
+
"kept": len(rows),
|
| 808 |
+
"sittings": len({(a["term"], a["committee_code"], a["sitting_num"]) for a in attrs}),
|
| 809 |
+
"committees": len({(a["term"], a["committee_code"]) for a in attrs}),
|
| 810 |
+
"unique_speaker_labels": len({a["speaker"] for a in attrs}),
|
| 811 |
+
"tokens": sum(r["token_count"] for r in rows),
|
| 812 |
+
"characters": sum(len(r["text"]) for r in rows),
|
| 813 |
+
"date_min": min(dates), "date_max": max(dates),
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
|
| 817 |
def build(terms=(9, 10), outdir="."):
|
| 818 |
"""Dedup parsed turns and write the canonical DynaWord artifacts."""
|
| 819 |
import pyarrow as pa
|
| 820 |
import pyarrow.parquet as pq
|
|
|
|
| 821 |
|
| 822 |
rows = []
|
| 823 |
for term in terms:
|
|
|
|
| 827 |
|
| 828 |
n_raw = len(rows)
|
| 829 |
rows, dedup_dropped, exact_dup = dedup_turns(rows)
|
| 830 |
+
# Speaker allowlist (see classify_speaker). A dropped turn leaves no marker: every row is
|
| 831 |
+
# one turn, so nothing else is cut and the surviving ids keep their `turn_idx` gaps.
|
| 832 |
+
n_deduped = len(rows)
|
| 833 |
+
rows = [r for r in rows if classify_speaker(r["speaker"])]
|
| 834 |
+
not_official = n_deduped - len(rows)
|
| 835 |
|
|
|
|
| 836 |
out_rows, attrs = [], []
|
| 837 |
+
for r, tokens in zip(rows, count_tokens([r["text"] for r in rows])):
|
| 838 |
rid = row_id(r)
|
| 839 |
out_rows.append({
|
| 840 |
"id": rid, "text": r["text"], "source": SOURCE, "added": ADDED,
|
| 841 |
+
"created": r["date"] or "", "token_count": tokens,
|
|
|
|
| 842 |
"license": LICENSE, "author": r["speaker"],
|
| 843 |
})
|
| 844 |
+
attrs.append({k: r[k] for k in ATTRIBUTION_KEYS} | {"id": rid})
|
|
|
|
| 845 |
|
| 846 |
root = pathlib.Path(outdir) / "data" / SOURCE
|
| 847 |
root.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 852 |
for a in attrs:
|
| 853 |
fh.write(json.dumps(a, ensure_ascii=False, sort_keys=True) + "\n")
|
| 854 |
|
|
|
|
|
|
|
|
|
|
| 855 |
stats = {
|
| 856 |
"discovered_sittings": 9175, "sittings_with_pdf": 8658,
|
| 857 |
"sittings_no_pdf_upstream": 455, "sittings_fetch_failed": 62,
|
| 858 |
+
"rows_raw_extracted": n_raw,
|
| 859 |
+
"rejected": dedup_dropped + exact_dup + not_official,
|
| 860 |
"rejected_joint_sitting_dup": dedup_dropped, "rejected_exact_dup": exact_dup,
|
| 861 |
+
"rejected_not_official_speaker": not_official,
|
| 862 |
+
**shard_stats(out_rows, attrs), "added": ADDED,
|
|
|
|
|
|
|
|
|
|
| 863 |
}
|
| 864 |
(root / f"{SOURCE}.stats.json").write_text(
|
| 865 |
json.dumps(stats, ensure_ascii=False, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
src/sources.py
CHANGED
|
@@ -375,14 +375,32 @@ SOURCES = {
|
|
| 375 |
"the Polish Open Data Act arts. 2(12), 5, 6, 14, 15, 17. "
|
| 376 |
"Per-record source_url pins the exact api.sejm.gov.pl PDF "
|
| 377 |
"endpoint; content_sha1 fingerprints the transcript body.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
"upstream": "https://api.sejm.gov.pl/",
|
| 379 |
"provenance": "Committee 'pelny zapis' PDFs fetched and parsed by "
|
| 380 |
"src/fetch_sejm_committee_transcripts.py (pdftotext -layout, "
|
| 381 |
-
"page-furniture
|
| 382 |
-
"
|
| 383 |
-
"
|
| 384 |
-
"
|
| 385 |
-
"
|
|
|
|
|
|
|
|
|
|
| 386 |
"domain": "political/spoken-committee",
|
| 387 |
"created": "2019-11-14, 2026-09-03",
|
| 388 |
"is_ocr": False,
|
|
|
|
| 375 |
"the Polish Open Data Act arts. 2(12), 5, 6, 14, 15, 17. "
|
| 376 |
"Per-record source_url pins the exact api.sejm.gov.pl PDF "
|
| 377 |
"endpoint; content_sha1 fingerprints the transcript body.",
|
| 378 |
+
"legal_note": "Not lawyer-signed-off. Only turns by MPs, members of the "
|
| 379 |
+
"government, heads of constitutional organs and Sejm/Senate "
|
| 380 |
+
"staff are kept (613,722 records, 298,555,500 characters = "
|
| 381 |
+
"67.3% of the 443,928,915 of the unfiltered release; turns "
|
| 382 |
+
"are cut at every speaker label line first): a piece whose "
|
| 383 |
+
"speaker label matches no allowlist rule is dropped, among "
|
| 384 |
+
"them guests, experts, representatives of unions, NGOs and "
|
| 385 |
+
"companies and every 'Glos z sali' piece. "
|
| 386 |
+
"Whether guest statements are official documents under "
|
| 387 |
+
"art. 4(2) is open; so is the treatment of staff of state "
|
| 388 |
+
"bodies the allowlist does not name. The label-line "
|
| 389 |
+
"detector is a heuristic (a missed label leaves the words "
|
| 390 |
+
"after it in the previous piece). The rules read the "
|
| 391 |
+
"printed role label, not the person. Role table: data/sejm_committee_transcripts/"
|
| 392 |
+
"sejm_committee_transcripts.speaker-roles.csv.",
|
| 393 |
"upstream": "https://api.sejm.gov.pl/",
|
| 394 |
"provenance": "Committee 'pelny zapis' PDFs fetched and parsed by "
|
| 395 |
"src/fetch_sejm_committee_transcripts.py (pdftotext -layout, "
|
| 396 |
+
"page-furniture and page-break-block removal, speaker turns "
|
| 397 |
+
"cut at every speaker label line, soft-hyphenation "
|
| 398 |
+
"joining, joint-sitting dedup, speaker "
|
| 399 |
+
"allowlist, PII pattern redaction with checksum-validated "
|
| 400 |
+
"national IDs). src/clean_sejm_committee_transcripts.py "
|
| 401 |
+
"cuts and re-filters the pinned pre-filter release "
|
| 402 |
+
"(653,411 turns -> 740,018 pieces -> 613,722 records). Pattern redaction only - re-run through "
|
| 403 |
+
"SlayerLab/NERGAL before release.",
|
| 404 |
"domain": "political/spoken-committee",
|
| 405 |
"created": "2019-11-14, 2026-09-03",
|
| 406 |
"is_ocr": False,
|
src/test_sejm_committee_transcripts_contract.py
CHANGED
|
@@ -1,18 +1,26 @@
|
|
| 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 |
)
|
|
@@ -27,25 +35,223 @@ def turn(code, num, idx, speaker, text, sha):
|
|
| 27 |
"text": text, "content_sha1": sha, "source_url": "https://api.sejm.gov.pl/x/pdf"}
|
| 28 |
|
| 29 |
|
| 30 |
-
class
|
| 31 |
-
|
| 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 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
def test_length_bounds(self):
|
| 46 |
-
self.assertFalse(
|
| 47 |
-
self.assertFalse(
|
| 48 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
class NormalizeTest(unittest.TestCase):
|
|
@@ -103,6 +309,619 @@ class DedupTest(unittest.TestCase):
|
|
| 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
|
|
@@ -116,8 +935,10 @@ class ShippedShardTest(unittest.TestCase):
|
|
| 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"])
|
|
@@ -126,6 +947,69 @@ class ShippedShardTest(unittest.TestCase):
|
|
| 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()
|
|
|
|
| 1 |
"""Contract for Sejm committee transcript ingestion and the shipped shard."""
|
| 2 |
+
import csv
|
| 3 |
+
import hashlib
|
| 4 |
import json
|
| 5 |
+
import os
|
| 6 |
import sys
|
| 7 |
+
import tempfile
|
| 8 |
+
import unicodedata
|
| 9 |
import unittest
|
| 10 |
from pathlib import Path
|
| 11 |
|
| 12 |
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 13 |
|
| 14 |
+
import clean_sejm_committee_transcripts as clean
|
| 15 |
+
import fetch_sejm_committee_transcripts as fetch
|
| 16 |
from fetch_sejm_committee_transcripts import (
|
| 17 |
FIELDS,
|
| 18 |
LICENSE,
|
| 19 |
SOURCE,
|
| 20 |
+
SPEAKER_RULES,
|
| 21 |
+
classify_speaker,
|
| 22 |
dehyphenate,
|
| 23 |
dedup_turns,
|
|
|
|
| 24 |
redact,
|
| 25 |
row_id,
|
| 26 |
)
|
|
|
|
| 35 |
"text": text, "content_sha1": sha, "source_url": "https://api.sejm.gov.pl/x/pdf"}
|
| 36 |
|
| 37 |
|
| 38 |
+
class LabelDetectorTest(unittest.TestCase):
|
| 39 |
+
"""is_label(): the one detector that decides which "...:" lines start a turn."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
LABELS = [
|
| 42 |
+
"Poseł Daniel Milewski (KO)", "Przewodnicząca Anna Sobolewska",
|
| 43 |
+
"Sekretarz stanu Władysław Teofil Bartoszewski", "Legislator Marek Nowak", "Poseł Kowalski",
|
| 44 |
+
# speakers who are not on the allowlist are labels too: they must start a turn so that they can be dropped
|
| 45 |
+
"Świadek prof. dr hab. Robert Flisiak",
|
| 46 |
+
"Członek zarządu Fundacji im. Stefana Batorego Krzysztof Izdebski",
|
| 47 |
+
"Zastępca Wójta Gminy Jan Kowalski", "Pan Jan Kowalski, dyrektor departamentu", "Radca prawny M.B.",
|
| 48 |
+
"Głos z sali", "Głos z gości", "Świadek nr 3", "Tłumacz", "Tłumaczka",
|
| 49 |
+
# real shapes: a handle, a quoted organisation, a title suffix, a particle, a web address
|
| 50 |
+
"Członek Stowarzyszenia @ELKApw Joanna Karczewska",
|
| 51 |
+
"Kierownik AI Work Team na Wydziale Prawa i Administracji Uniwersytetu Łódzkiego dr hab. Krzysztof Stefański prof. ucz.",
|
| 52 |
+
"Przewodniczący Krajowej Sekcji Funkcjonariuszy i Pracowników Policji NSZZ „Solidarność” Jacek Łukasik",
|
| 53 |
+
"Prezes Stowarzyszenia „Dzieci są darem” Anna Karpiel-Semberecka",
|
| 54 |
+
"Wydawca magazynu „Świat Kominków” i portalu www.kominki.org Dariusz Marciniak",
|
| 55 |
+
"Członek Komisji Praw Społecznych i Spraw Konsumenckich Kongresu Deputowanych Królestwa Hiszpanii Jordi Salvador i Duch",
|
| 56 |
+
]
|
| 57 |
+
PROSE = [
|
| 58 |
+
"Proponuję brzmienie", "Dziękuję bardzo", "Mamy następujące punkty", "Zgodnie z art. 5 ust. 2",
|
| 59 |
+
"Ja zacytuję pana ministra Jana Kowalskiego", # prose before a name
|
| 60 |
+
"Czy to jest dobre rozwiązanie?", "Pan Jan Kowalski się zgodził; Anna Nowak też",
|
| 61 |
+
"szczegóły na https://api.sejm.gov.pl/sejm/term10", "druk nr 1234 w sprawie zmiany ustawy",
|
| 62 |
+
"Pełny Zapis Przebiegu Posiedzenia", "PEŁNY ZAPIS PRZEBIEGU POSIEDZENIA", "pełny zapis przebiegu posiedzenia",
|
| 63 |
+
"Państwo", "Jan", "Po", "",
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
+
def test_labels_are_detected(self):
|
| 67 |
+
for body in self.LABELS:
|
| 68 |
+
self.assertTrue(fetch.is_label(body), body)
|
| 69 |
+
|
| 70 |
+
def test_prose_and_the_page_title_are_not_labels(self):
|
| 71 |
+
for body in self.PROSE:
|
| 72 |
+
self.assertFalse(fetch.is_label(body), body)
|
| 73 |
|
| 74 |
def test_length_bounds(self):
|
| 75 |
+
self.assertFalse(fetch.is_label("Po"))
|
| 76 |
+
self.assertFalse(fetch.is_label("Poseł " + "x" * 400))
|
| 77 |
+
self.assertFalse(fetch.is_label("Poseł Jan " + "Kowalski " * 100))
|
| 78 |
+
|
| 79 |
+
def test_detection_is_nfc(self):
|
| 80 |
+
self.assertTrue(fetch.is_label(unicodedata.normalize("NFD", "Poseł Paweł Kowalski (KO)")))
|
| 81 |
+
|
| 82 |
+
def test_every_allowlisted_label_is_detected(self):
|
| 83 |
+
# a label the allowlist keeps but the detector misses would stay inside the previous turn
|
| 84 |
+
for label, _ in ALLOWED:
|
| 85 |
+
self.assertTrue(fetch.is_label(label.replace("\n", " ")), label)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class SplitAtLabelsTest(unittest.TestCase):
|
| 89 |
+
def test_cut_at_every_label_whoever_the_speaker(self):
|
| 90 |
+
pieces = fetch.split_at_labels([
|
| 91 |
+
"Dziękuję. To wszystko.", "Poseł Jan Kowalski (KO):", "Mam pytanie.",
|
| 92 |
+
"Świadek prof. dr hab. Robert Flisiak:", "Odpowiadam.", "Tłumacz:", "Przekładam."])
|
| 93 |
+
self.assertEqual(pieces, [
|
| 94 |
+
(None, ["Dziękuję. To wszystko."]), ("Poseł Jan Kowalski (KO)", ["Mam pytanie."]),
|
| 95 |
+
("Świadek prof. dr hab. Robert Flisiak", ["Odpowiadam."]), ("Tłumacz", ["Przekładam."])])
|
| 96 |
+
|
| 97 |
+
def test_first_piece_is_empty_when_the_text_starts_with_a_label(self):
|
| 98 |
+
self.assertEqual(fetch.split_at_labels(["Głos z sali:", "Tak."]), [(None, []), ("Głos z sali", ["Tak."])])
|
| 99 |
+
|
| 100 |
+
def test_prose_with_a_colon_stays_in_the_text(self):
|
| 101 |
+
lines = ["Proponuję brzmienie:", "Pełny Zapis Przebiegu Posiedzenia:", "Czy to prawda?", "dalej"]
|
| 102 |
+
self.assertEqual(fetch.split_at_labels(lines), [(None, lines)])
|
| 103 |
+
|
| 104 |
+
def test_label_wrapped_over_two_lines(self):
|
| 105 |
+
pieces = fetch.split_at_labels([
|
| 106 |
+
"Koniec poprzedniej wypowiedzi.", "Członek zarządu Fundacji im. Stefana", "Batorego Krzysztof Izdebski:", "Tak jest."])
|
| 107 |
+
self.assertEqual(pieces, [
|
| 108 |
+
(None, ["Koniec poprzedniej wypowiedzi."]),
|
| 109 |
+
("Członek zarządu Fundacji im. Stefana Batorego Krzysztof Izdebski", ["Tak jest."])])
|
| 110 |
+
|
| 111 |
+
def test_hyphenated_name_wrapped_at_its_hyphen(self):
|
| 112 |
+
pieces = fetch.split_at_labels(["Prezes Stowarzyszenia Anna Karpiel-", "-Semberecka:", "tekst"])
|
| 113 |
+
self.assertEqual(pieces, [(None, []), ("Prezes Stowarzyszenia Anna Karpiel-Semberecka", ["tekst"])])
|
| 114 |
+
|
| 115 |
+
def test_no_join_after_closing_punctuation(self):
|
| 116 |
+
for end in ".?!:;…":
|
| 117 |
+
pieces = fetch.split_at_labels([f"Koniec zdania{end}", "Jan Kowalski:", "tekst"])
|
| 118 |
+
self.assertEqual(pieces, [(None, [f"Koniec zdania{end}"]), ("Jan Kowalski", ["tekst"])], end)
|
| 119 |
+
|
| 120 |
+
def test_no_join_when_the_colon_line_is_an_allowlisted_label_itself(self):
|
| 121 |
+
pieces = fetch.split_at_labels(["Zakończyliśmy", "Poseł Jan Kowalski (KO):", "tekst"])
|
| 122 |
+
self.assertEqual(pieces, [(None, ["Zakończyliśmy"]), ("Poseł Jan Kowalski (KO)", ["tekst"])])
|
| 123 |
+
|
| 124 |
+
def test_a_wrapped_line_that_does_not_make_a_label_is_kept(self):
|
| 125 |
+
pieces = fetch.split_at_labels(["Zapis brzmi", "Proponuję brzmienie:", "dalej"])
|
| 126 |
+
self.assertEqual(pieces, [(None, ["Zapis brzmi", "Proponuję brzmienie:", "dalej"])])
|
| 127 |
+
|
| 128 |
+
def test_blank_lines_are_skipped_and_labels_are_nfc(self):
|
| 129 |
+
label = unicodedata.normalize("NFD", "Poseł Paweł Kowalski (KO)")
|
| 130 |
+
pieces = fetch.split_at_labels(["", f" {label}: ", "", " tekst "])
|
| 131 |
+
self.assertEqual(pieces, [(None, []), (unicodedata.normalize("NFC", label), ["tekst"])])
|
| 132 |
+
|
| 133 |
+
def test_consecutive_labels_give_an_empty_piece(self):
|
| 134 |
+
pieces = fetch.split_at_labels(["Poseł Jan Kowalski (KO):", "Poseł Anna Nowak (KO):", "tekst"])
|
| 135 |
+
self.assertEqual(pieces, [(None, []), ("Poseł Jan Kowalski (KO)", []), ("Poseł Anna Nowak (KO)", ["tekst"])])
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class StripPageBlocksTest(unittest.TestCase):
|
| 139 |
+
NO_COUNTS = {"blocks": 0, "rejoined": 0, "fused": 0, "lone_footers": 0}
|
| 140 |
+
|
| 141 |
+
def strip(self, lines):
|
| 142 |
+
return fetch.strip_page_blocks(lines)
|
| 143 |
+
|
| 144 |
+
def test_block_removed_as_a_unit(self):
|
| 145 |
+
out, counts = self.strip(["Zdanie przed.", "12 a.b.", "Pełny Zapis Przebiegu Posiedzenia:",
|
| 146 |
+
"Komisji Finansów Publicznych (nr 12)", "Zdanie po."])
|
| 147 |
+
self.assertEqual(out, ["Zdanie przed.", "Zdanie po."])
|
| 148 |
+
self.assertEqual(counts, {**self.NO_COUNTS, "blocks": 1})
|
| 149 |
+
|
| 150 |
+
def test_word_hyphenated_across_the_block_is_rejoined(self):
|
| 151 |
+
# the shape of 9_ZDR_258_306
|
| 152 |
+
out, counts = self.strip(["Rozwiązania dotyczące upraw-", "56 m.h.", "Pełny Zapis Przebiegu Posiedzenia:",
|
| 153 |
+
"Komisji Zdrowia (Nr 258)", "nienia do zmiany ostatecznej decyzji administracyjnej."])
|
| 154 |
+
self.assertEqual(out, ["Rozwiązania dotyczące uprawnienia do zmiany ostatecznej decyzji administracyjnej."])
|
| 155 |
+
self.assertEqual(counts, {**self.NO_COUNTS, "blocks": 1, "rejoined": 1})
|
| 156 |
+
|
| 157 |
+
def test_hyphen_before_a_capital_is_not_rejoined(self):
|
| 158 |
+
out, counts = self.strip(["upraw-", "56 m.h.", "Pełny Zapis Przebiegu Posiedzenia:", "Komisji Zdrowia (Nr 258)", "Nienia"])
|
| 159 |
+
self.assertEqual(out, ["upraw-", "Nienia"])
|
| 160 |
+
self.assertEqual(counts["rejoined"], 0)
|
| 161 |
+
|
| 162 |
+
def test_title_variants(self):
|
| 163 |
+
for title in ["pełny zapis przebiegu posiedzenia:", "PEŁNY ZAPIS PRZEBIEGU POSIEDZENIA:", "Pełny apis przebiegu posiedzenia:",
|
| 164 |
+
"Pełny Zapis Przebiegu Posiedzenia"]:
|
| 165 |
+
out, counts = self.strip(["Zdanie.", title, "Komisji Finansów (nr 12)", "Dalej."])
|
| 166 |
+
self.assertEqual((out, counts["blocks"]), (["Zdanie.", "Dalej."], 1), title)
|
| 167 |
+
|
| 168 |
+
def test_doubled_title_and_several_committee_lines(self):
|
| 169 |
+
out, counts = self.strip(["Zdanie.", "Pełny Zapis Przebiegu Posiedzenia:", "Pełny Zapis Przebiegu Posiedzenia:",
|
| 170 |
+
"Komisji Finansów (nr 12)", "Komisji Zdrowia (nr 13)", "Dalej."])
|
| 171 |
+
self.assertEqual((out, counts["blocks"]), (["Zdanie.", "Dalej."], 2))
|
| 172 |
+
|
| 173 |
+
def test_committee_name_wrapped_over_lines_or_on_the_title_line(self):
|
| 174 |
+
out, _ = self.strip(["Zdanie.", "Pełny Zapis Przebiegu Posiedzenia:", "Komisji Rolnictwa i", "Rozwoju Wsi (nr 7)", "Dalej."])
|
| 175 |
+
self.assertEqual(out, ["Zdanie.", "Dalej."])
|
| 176 |
+
out, _ = self.strip(["Pełny apis przebiegu posiedzenia: Komisji Finansów (nr 12)", "Dalej."])
|
| 177 |
+
self.assertEqual(out, ["Dalej."])
|
| 178 |
+
|
| 179 |
+
def test_title_without_a_committee_line_is_dropped_alone(self):
|
| 180 |
+
out, counts = self.strip(["Zdanie.", "Pełny Zapis Przebiegu Posiedzenia:", "Dalej bez komisji."])
|
| 181 |
+
self.assertEqual((out, counts["blocks"]), (["Zdanie.", "Dalej bez komisji."], 1))
|
| 182 |
+
|
| 183 |
+
def test_footer_glued_to_a_hyphenated_word_is_repaired(self):
|
| 184 |
+
out, counts = self.strip(["Ten tekst prob.m. 5", "Pełny Zapis Przebiegu Posiedzenia:",
|
| 185 |
+
"Komisji Finansów (nr 12)", "blem jest poważny."])
|
| 186 |
+
self.assertEqual(out, ["Ten tekst problem jest poważny."])
|
| 187 |
+
self.assertEqual(counts, {**self.NO_COUNTS, "blocks": 1, "fused": 1})
|
| 188 |
+
|
| 189 |
+
def test_block_without_its_title_after_a_footer(self):
|
| 190 |
+
out, counts = self.strip(["Zdanie.", "5 a.b.", "Komisji Finansów (nr 12)", "Dalej."])
|
| 191 |
+
self.assertEqual((out, counts["blocks"]), (["Zdanie.", "Dalej."], 1))
|
| 192 |
+
|
| 193 |
+
def test_footer_left_alone_by_a_filtered_title(self):
|
| 194 |
+
out, counts = self.strip(["Zdanie.", "12 m.c.", "Dalej."])
|
| 195 |
+
self.assertEqual((out, counts["lone_footers"], counts["blocks"]), (["Zdanie.", "Dalej."], 1, 0))
|
| 196 |
+
|
| 197 |
+
def test_prose_that_looks_like_a_block_is_kept(self):
|
| 198 |
+
lines = ["Kwota 500 tys. zł.", "Rok 2020 r.", "Zdanie kończy się 12 m.c.", "Komisja Finansów (nr 12) zebrała się.",
|
| 199 |
+
"Komisji Zdrowia (nr 12)", "Pełny Zapis Przebiegu Posiedzenia jest dostępny.",
|
| 200 |
+
"Zdanie o tym, że Pełny Zapis Przebiegu Posiedzenia: jest dostępny.", "Ustawa nr 5 r.", "To 2 r.g."]
|
| 201 |
+
out, counts = self.strip(lines)
|
| 202 |
+
self.assertEqual(out, lines)
|
| 203 |
+
self.assertEqual(counts, self.NO_COUNTS)
|
| 204 |
+
|
| 205 |
+
def test_blank_lines_are_dropped(self):
|
| 206 |
+
self.assertEqual(self.strip(["", " a ", " "])[0], ["a"])
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
class ParsePdfTest(unittest.TestCase):
|
| 210 |
+
"""parse_pdf() and the clean script cut one text at the same lines."""
|
| 211 |
+
|
| 212 |
+
RAW = "\n".join([
|
| 213 |
+
"PEŁNY ZAPIS PRZEBIEGU POSIEDZENIA", "KANCELARIA SEJMU",
|
| 214 |
+
"Komisja Testowa otworzyła posiedzenie.",
|
| 215 |
+
"Poseł Jan Kowalski (KO):", "Panie przewodniczący, dziękuję za głos, mam pytanie o ustawę.",
|
| 216 |
+
"Członek zarządu Fundacji im. Stefana", "Batorego Krzysztof Izdebski:",
|
| 217 |
+
"Odpowiadam: nie ma przeszkód, aby przyjąć tę poprawkę w całości, a upraw-", "56 m.h.",
|
| 218 |
+
"Pełny Zapis Przebiegu Posiedzenia:", "Komisji Zdrowia (Nr 258)", "nienia pozostają bez zmian.",
|
| 219 |
+
"Głos z sali:", "Tak.",
|
| 220 |
+
])
|
| 221 |
+
|
| 222 |
+
def parse(self):
|
| 223 |
+
old = fetch.pdf_text
|
| 224 |
+
fetch.pdf_text = lambda path: self.RAW
|
| 225 |
+
try:
|
| 226 |
+
return fetch.parse_pdf("x.pdf")
|
| 227 |
+
finally:
|
| 228 |
+
fetch.pdf_text = old
|
| 229 |
+
|
| 230 |
+
def test_turns(self):
|
| 231 |
+
kind, header, turns = self.parse()
|
| 232 |
+
self.assertEqual(kind, "pelny_zapis")
|
| 233 |
+
self.assertEqual(header, "Komisja Testowa otworzyła posiedzenie.")
|
| 234 |
+
self.assertEqual(turns, [
|
| 235 |
+
("Poseł Jan Kowalski (KO)", "Panie przewodniczący, dziękuję za głos, mam pytanie o ustawę."),
|
| 236 |
+
("Członek zarządu Fundacji im. Stefana Batorego Krzysztof Izdebski",
|
| 237 |
+
"Odpowiadam: nie ma przeszkód, aby przyjąć tę poprawkę w całości, a uprawnienia pozostają bez zmian.")])
|
| 238 |
+
# "Tak." is shorter than 15 characters
|
| 239 |
+
|
| 240 |
+
def test_clean_cuts_the_stored_text_like_parse_pdf(self):
|
| 241 |
+
_, _, turns = self.parse()
|
| 242 |
+
# what the old pipeline stored: everything after the first label, as one turn of that label
|
| 243 |
+
stored = "\n".join(self.RAW.split("\n")[4:])
|
| 244 |
+
row = {**turn("ASW", 1, 0, "Poseł Jan Kowalski (KO)", stored, "aaa"), "id": "x", "author": "Poseł Jan Kowalski (KO)",
|
| 245 |
+
"token_count": 5}
|
| 246 |
+
pieces, counts = clean.cut_turn(row, {})
|
| 247 |
+
self.assertEqual([(p["author"], p["text"]) for p in pieces if len(p["text"]) >= fetch.MIN_TURN_CHARS], turns)
|
| 248 |
+
self.assertEqual([p["id"] for p in pieces], ["x", "x_1", "x_2"])
|
| 249 |
+
self.assertEqual(counts["blocks"], 1)
|
| 250 |
+
|
| 251 |
+
def test_the_clean_script_uses_the_fetch_detector(self):
|
| 252 |
+
self.assertIs(clean.split_at_labels, fetch.split_at_labels)
|
| 253 |
+
self.assertIs(clean.strip_page_blocks, fetch.strip_page_blocks)
|
| 254 |
+
self.assertIs(clean.classify_speaker, fetch.classify_speaker)
|
| 255 |
|
| 256 |
|
| 257 |
class NormalizeTest(unittest.TestCase):
|
|
|
|
| 309 |
self.assertEqual(row_id(r), row_id(dict(r)))
|
| 310 |
|
| 311 |
|
| 312 |
+
# (label, rule id) pairs the allowlist must keep, and labels it must drop.
|
| 313 |
+
ALLOWED = [
|
| 314 |
+
("Poseł Daniel Milewski (KO)", "mp"),
|
| 315 |
+
("Posłanka Anna Kowalska-Nowak (Lewica)", "mp"),
|
| 316 |
+
("Poseł Jerzy Hardie–Douglas (KO)", "mp"),
|
| 317 |
+
("Poseł Jan de Vries (PiS)", "mp"),
|
| 318 |
+
("Poseł Marek Sowa (KO) – spoza składów Komisji", "mp"),
|
| 319 |
+
("Poseł Jan Kowalski (PiS) - spoza składu Komisji", "mp"),
|
| 320 |
+
("Przewodniczący poseł Jan Kowalski (PiS)", "mp_committee_chair"),
|
| 321 |
+
("Przewodnicząca posłanka Anna Nowak (KO)", "mp_committee_chair"),
|
| 322 |
+
("Wiceprzewodniczący poseł Jan Kowalski (PiS)", "mp_committee_chair"),
|
| 323 |
+
("Przewodnicząca Podkomisji poseł Anna Nowak (KO)", "mp_committee_chair"),
|
| 324 |
+
("Poseł przewodniczący Piotr Adamowicz (KO)", "mp_committee_chair"), # older word order
|
| 325 |
+
("Poseł wiceprzewodniczący Jan Kowalski (PiS)", "mp_committee_chair"),
|
| 326 |
+
# label forms seen in the transcripts that the strict form missed
|
| 327 |
+
("Poseł Jan Kowalski(PiS)", "mp"), # party glued to the name
|
| 328 |
+
("Poseł Krzemiński (KO)", "mp"), # surname only, party present
|
| 329 |
+
("Poseł Grzegorz Napieralski – spoza składu Komisji", "mp"), # no party, outside the committee
|
| 330 |
+
("Poseł Rafał Weber (PiS) – spoza skladu Komisji", "mp"), # typo "skladu"
|
| 331 |
+
("Poseł Kazimierz Smoliński – spoza składu Komisji (PiS)", "mp"), # party after the note
|
| 332 |
+
("Poseł Iwona Śledzińska– Katarasińska (KO)", "mp"), # space only before the hyphen
|
| 333 |
+
("Poseł Jacek Protasiewicz, (KP)", "mp"), # comma before the party
|
| 334 |
+
("Poseł Tadeusz Samborski ((PSL-TD)", "mp"), # doubled parenthesis
|
| 335 |
+
("Poseł wnioskodawca Michał Wypij (PiS)", "mp"),
|
| 336 |
+
("Poseł Sławomir Skwarek (PiS) – przedstawiciel Komisji Edukacji, Nauki i Młodzieży", "mp"),
|
| 337 |
+
("Poseł Maria Kurowska (PiS) reprezentująca Jana Nowaka", "mp"),
|
| 338 |
+
("Przewodniczący poseł Waldemar Sługocki", "mp_committee_chair"), # no party
|
| 339 |
+
("Przewodnicząca poseł Magdalena Sroka (PSL-TD", "mp_committee_chair"), # unclosed parenthesis
|
| 340 |
+
("Przewodniczący poseł Jan Kowalski(PiS)", "mp_committee_chair"),
|
| 341 |
+
("Przewodnicząca Małgorzata Wassermann (PiS)", "mp_committee_chair"), # the party tag stands in for "poseł"
|
| 342 |
+
("Przewodniczący Jan Kowalski (PiS)", "mp_committee_chair"),
|
| 343 |
+
("Przewodniczący Jan Kowalski(PiS)", "mp_committee_chair"),
|
| 344 |
+
("Przewodnicząca Anna Kowalska-Nowak, (KO)", "mp_committee_chair"),
|
| 345 |
+
("Wicemarszałek Sejmu, poseł Monika Wielichowska", "sejm_senate_marshal"),
|
| 346 |
+
("Senator Jan Kowalski (PO)", "senator"),
|
| 347 |
+
("Wicemarszałek Sejmu Krzysztof Bosak (Konfederacja)", "sejm_senate_marshal"),
|
| 348 |
+
("Marszałek Sejmu Szymon Hołownia", "sejm_senate_marshal"),
|
| 349 |
+
("Prezes Rady Ministrów Donald Tusk", "government_member"),
|
| 350 |
+
("Wiceprezes Rady Ministrów, minister obrony narodowej Władysław Kosiniak-Kamysz", "government_member"),
|
| 351 |
+
("Minister zdrowia Izabela Leszczyna", "government_member"),
|
| 352 |
+
("Minister rolnictwa i rozwoju wsi", "government_member"),
|
| 353 |
+
("Minister kultury i dziedzictwa narodowego prof. Piotr Gliński", "government_member"),
|
| 354 |
+
("Minister sprawiedliwości, prokurator generalny Adam Bodnar", "government_member"),
|
| 355 |
+
("Sekretarz stanu w Ministerstwie Zdrowia Marek Kos", "state_secretary"),
|
| 356 |
+
("Podsekretarz stanu w MF Jan Kowalski", "state_secretary"),
|
| 357 |
+
("Sekretarz stanu w MSWiA, pełnomocnik rządu do spraw CPK Jan Kowalski", "state_secretary"),
|
| 358 |
+
("Podsekretarz stanu w MRiRW Krzysztof Cieci\u006f\u0301ra", "state_secretary"), # decomposed ó
|
| 359 |
+
("Sekretarz stanu w KPRM Jan Kowalski", "state_secretary"),
|
| 360 |
+
("Podsekretarz stanu w Ministerstwie Rolnictwa i Rozwoju Wsi, główny konserwator Jan Kowalski", "state_secretary"),
|
| 361 |
+
("Prezes NIK Marian Banaś", "constitutional_organ_head"),
|
| 362 |
+
("Prezes Narodowego Banku Polskiego Adam Glapiński", "constitutional_organ_head"),
|
| 363 |
+
("Prezes TK Bogdan Święczkowski", "constitutional_organ_head"),
|
| 364 |
+
("Prezes NSA Jacek Chlebny", "constitutional_organ_head"),
|
| 365 |
+
("Pierwszy Prezes Sądu Najwyższego Małgorzata Manowska", "constitutional_organ_head"),
|
| 366 |
+
("Rzecznik Praw Obywatelskich Marcin Wiącek", "constitutional_organ_head"),
|
| 367 |
+
("Rzecznik praw dziecka Monika Horna-Cieślak", "constitutional_organ_head"),
|
| 368 |
+
("Przewodniczący KRRiT Maciej Świrski", "constitutional_organ_head"),
|
| 369 |
+
("Przewodniczący Krajowej Rady Sądownictwa Dariusz Zawistowski", "constitutional_organ_head"),
|
| 370 |
+
("Legislator Jan Kowalski", "sejm_legislator"),
|
| 371 |
+
("Legislator z Biura Legislacyjnego Jan Kowalski", "sejm_legislator"),
|
| 372 |
+
("Legislator w Biurze Legislacyjnym Kancelarii Sejmu Jan Kowalski", "sejm_legislator"),
|
| 373 |
+
("Legislator Łukasz Nykiel z Biura Legislacyjnego", "sejm_legislator"),
|
| 374 |
+
("Legislator sejmowy Urszula Sęk", "sejm_legislator"),
|
| 375 |
+
("Legislator z Kancelarii Sejmu Jakub Bennewicz", "sejm_legislator"),
|
| 376 |
+
("Legislator Z Biura Legislacyjnego Piotr Podczaski", "sejm_legislator"),
|
| 377 |
+
("Legislator z Biura Legislacyjego Wojciech Paluch", "sejm_legislator"), # typo "Legislacyjego"
|
| 378 |
+
("Ekspert z BEOS Paweł Daniluk", "sejm_bureau_expert"),
|
| 379 |
+
("Naczelnik wydziału w BAS Zofia Szpringer", "sejm_bureau_expert"),
|
| 380 |
+
("Naczelnik Wydziału Analiz Konstytucyjnych BAS Paweł Bachmat", "sejm_bureau_expert"),
|
| 381 |
+
("Ekspert z Bas Justyna Karaźniewicz", "sejm_bureau_expert"),
|
| 382 |
+
("Ekspert z ds. legislacji Biura Ekspertyz I Oceny Skutków Regulacji Natalia Cabaj", "sejm_bureau_expert"),
|
| 383 |
+
("Ekspert w Biurze Ekspertyz i Ocen Skutków Regulacji Michał Ziółkowski", "sejm_bureau_expert"),
|
| 384 |
+
("Ekspert do Spraw Legislacji Biura Analiz Sejmowych Mateusz Langer", "sejm_bureau_expert"),
|
| 385 |
+
("Ekspert do spraw legislacji w BEOS Natalia Cabaj", "sejm_bureau_expert"),
|
| 386 |
+
("Ekspert z BAS Jan Kowalski", "sejm_bureau_expert"),
|
| 387 |
+
("Dyrektor BAS Jan Kowalski", "sejm_senate_office_head"),
|
| 388 |
+
("Wicedyrektor BEOS Jan Kowalski", "sejm_senate_office_head"),
|
| 389 |
+
("Szef Kancelarii Sejmu Jan Kowalski", "sejm_senate_office_head"),
|
| 390 |
+
("Dyrektor Biura Legislacyjnego Piotr Kędziora", "sejm_senate_office_head"),
|
| 391 |
+
("Wicedyrektor Biura Legislacyjnego Tomasz Osiński", "sejm_senate_office_head"),
|
| 392 |
+
("Wicedyrektor Biura Komisji Sejmowych Anna Osińska", "sejm_senate_office_head"),
|
| 393 |
+
("Komendant Straży Marszałkowskiej Michał Sadoń", "sejm_senate_office_head"),
|
| 394 |
+
("Ekspert Straży Marszałkowskiej Zbigniew Białek", "sejm_senate_office_head"),
|
| 395 |
+
("Dyrektor Biblioteki Sejmowej Wojciech Kulisiewicz", "sejm_senate_office_head"),
|
| 396 |
+
("Dyrektor generalny kierujący Gabinetem Marszałka Sejmu Stanisław Zakroczymski", "sejm_senate_office_head"),
|
| 397 |
+
("Szef KS Jacek Cichocki", "sejm_senate_office_head"), # "KS" = Kancelaria Sejmu, as the label has it
|
| 398 |
+
("Dyrektor BOM KS Katarzyna Karpa-Świderek", "sejm_senate_office_head"),
|
| 399 |
+
("Dyrektor biura KS Artur Kozłowski", "sejm_senate_office_head"),
|
| 400 |
+
("Dyrektor BKSP Jan Morwiński", "sejm_senate_office_head"),
|
| 401 |
+
# forms the first filter missed: feminine titles, committee secretaries, longer office titles
|
| 402 |
+
("Legislatorka Anna Nowak", "sejm_legislator"),
|
| 403 |
+
("Legislatorka z Biura Legislacyjnego Anna Nowak", "sejm_legislator"),
|
| 404 |
+
("Sekretarz Komisji Jan Kowalski", "sejm_committee_secretary"), # Sejm staff (Biuro Komisji Sejmowych)
|
| 405 |
+
("Ministra zdrowia Anna Kowalska", "government_member"),
|
| 406 |
+
("Ministra Anna Kowalska", "government_member"),
|
| 407 |
+
("Szef KPRM Jan Kowalski", "government_member"),
|
| 408 |
+
("Szef Kancelarii Prezesa Rady Ministrów Jan Kowalski", "government_member"),
|
| 409 |
+
("Członek Rady Ministrów Jan Kowalski", "government_member"),
|
| 410 |
+
("Członek Rady Ministrów, minister do spraw europejskich Jan Kowalski", "government_member"),
|
| 411 |
+
("Członek Rady Ministrów do spraw polityki senioralnej Jan Kowalski", "government_member"),
|
| 412 |
+
("Senator RP Jan Kowalski", "senator"),
|
| 413 |
+
("Senatorka Anna Nowak (KO)", "senator"),
|
| 414 |
+
("Wicemarszałkini Sejmu Anna Nowak", "sejm_senate_marshal"),
|
| 415 |
+
("Wicemarszałek Sejmu RP Jan Kowalski", "sejm_senate_marshal"),
|
| 416 |
+
("Sekretarz Stanu w MF Jan Kowalski", "state_secretary"), # capital "Stanu"
|
| 417 |
+
("Podsekretarz stanu w MSWiA, szef Krajowej Administracji Skarbowej Jan Kowalski", "state_secretary"),
|
| 418 |
+
("Sekretarz stanu w MZ, przewodniczący Komitetu Stałego Rady Ministrów Jan Kowalski", "state_secretary"),
|
| 419 |
+
("Specjalistka w BAS Anna Kowalska", "sejm_bureau_expert"),
|
| 420 |
+
("Specjalista w BAS Jan Kowalski", "sejm_bureau_expert"),
|
| 421 |
+
("Ekspertka z BEOS Anna Kowalska", "sejm_bureau_expert"),
|
| 422 |
+
("Ekspert BEOS Ewa Plebanek", "sejm_bureau_expert"),
|
| 423 |
+
("Ekspert ds. legislacji z Biura Ekspertyz i Oceny Skutków Regulacji Kancelarii Sejmu RP Tomasz Esmund", "sejm_bureau_expert"),
|
| 424 |
+
("Ekspert ds. legislacji w Biurze Ekspertyz i Oceny Skutków Regulacji w Kancelarii Sejmu Marcin Fryźlewicz", "sejm_bureau_expert"),
|
| 425 |
+
("Pracownica sekretariatu Komisji w BAS Anna Kowalska", "sejm_bureau_expert"),
|
| 426 |
+
("Zastępca szefa Kancelarii Sejmu Jan Kowalski", "sejm_senate_office_head"),
|
| 427 |
+
("Szefowa Kancelarii Sejmu Anna Nowak", "sejm_senate_office_head"),
|
| 428 |
+
("P.o. dyrektora Biura Analiz Sejmowych Jan Kowalski", "sejm_senate_office_head"),
|
| 429 |
+
("Poseł Anna Kowalska- -Nowak (KO)", "mp"), # a double-barrelled name broken at its hyphen
|
| 430 |
+
("Poseł Anna Kowalska - -Nowak (KO)", "mp"),
|
| 431 |
+
# exact typo labels (EXACT_LABELS), one per entry
|
| 432 |
+
("Poseł Szymon Szynkowski vel sęk (PiS)", "mp"),
|
| 433 |
+
("Przewodniczący poseł Krzysztof TchórzePwski (PiS)", "mp_committee_chair"),
|
| 434 |
+
("Przewodniczący poseł TomaszLatos (PiS)", "mp_committee_chair"),
|
| 435 |
+
("Legislator z Jarosław Lichocki", "sejm_legislator"),
|
| 436 |
+
("Legislator z Konrad Nietrzebka", "sejm_legislator"),
|
| 437 |
+
("Legislator Katarzyna Abramowicz (KO)", "sejm_legislator"),
|
| 438 |
+
("Kamila Gasiuk-Pihowicz (KO)", "mp"), # name and party tag only
|
| 439 |
+
("Ryszard Terlecki (PiS)", "mp"),
|
| 440 |
+
("Agnieszka Maria Kłopotek (PSL=TD)", "mp"),
|
| 441 |
+
("zrzewodniczący poseł Tomasz Ławniczak (PiS)", "mp_committee_chair"), # typos in "Przewodniczący"
|
| 442 |
+
("Pewodniczący poseł Piotr Babinetz (PiS)", "mp_committee_chair"),
|
| 443 |
+
# subcommittee chairs and deputies: the MPs only ("poseł"/"posłanka" before the name, or an exact label)
|
| 444 |
+
("Przewodniczący podkomisji Antoni Macierewicz", "mp_committee_chair"), # exact: MON subcommittee, he is an MP
|
| 445 |
+
("Przewodniczący Podkomisji ds. ponownego zbadania wypadku lotniczego Antoni Macierewicz", "mp_committee_chair"),
|
| 446 |
+
("Przewodniczący Podkomisji d.s. Ponownego Zbadania Wypadku Lotniczego poseł Antoni Macierewicz (PiS)", "mp_committee_chair"),
|
| 447 |
+
("Przewodniczący Podkomisji poseł Jan Kowalski", "mp_committee_chair"),
|
| 448 |
+
("Przewodniczący podkomisji do spraw zdrowia dzieci poseł Jan Kowalski (PiS)", "mp_committee_chair"),
|
| 449 |
+
("Przewodnicząca Podkomisji posłanka Anna Nowak", "mp_committee_chair"),
|
| 450 |
+
("Przewodnicząca posłanka Anna Nowak", "mp_committee_chair"),
|
| 451 |
+
("Pierwszy zastępca przewodniczącego Podkomisji poseł Jan Kowalski (PiS)", "mp_committee_chair"),
|
| 452 |
+
("Zastępca przewodniczącego Podkomisji poseł Jan Kowalski", "mp_committee_chair"),
|
| 453 |
+
("Drugi zastępca przewodniczącego Podkomisji poseł Jan Kowalski", "mp_committee_chair"),
|
| 454 |
+
("Pierwsza zastępczyni przewodniczącej Podkomisji posłanka Anna Nowak", "mp_committee_chair"),
|
| 455 |
+
("Zastępczyni przewodniczącej Podkomisji poseł Anna Nowak (KO)", "mp_committee_chair"),
|
| 456 |
+
# secretaries and undersecretaries of state, the rank in any position
|
| 457 |
+
("Sekretarz stanu w MSiT Gut-Mostowy", "state_secretary"), # exact: a surname alone
|
| 458 |
+
("Pełnomocnik rządu do spraw równego traktowania, sekretarz stanu w MRiPS Anna Schmidt", "state_secretary"),
|
| 459 |
+
("Pełnomocnik rządu do spraw równego traktowania, sekretarz stanu w Ministerstwie Rodziny i Polityki Społecznej Anna Schmidt", "state_secretary"),
|
| 460 |
+
("Pełnomocnik rządu ds. strategicznej infrastruktury energetycznej, sekretarz stanu w MP Wojciech Wrochna", "state_secretary"),
|
| 461 |
+
("Pełnomocnik rządu do spraw X, sekretarz stanu w MP Jan Kowalski", "state_secretary"),
|
| 462 |
+
("Zastępca szefa KPRM podsekretarz stanu Rafał Siemianowski", "state_secretary"),
|
| 463 |
+
("Zastępca szefa Kancelarii Prezesa Rady Ministrów podsekretarz stanu Rafał Siemianowski", "state_secretary"),
|
| 464 |
+
("Wiceprzewodnicząca Komitetu do spraw Pożytku Publicznego, sekretarz stanu w KPRM Adriana Porowska", "state_secretary"),
|
| 465 |
+
("Sekretarz stanu, wiceprzewodnicząca Komitetu do Spraw Pożytku Publicznego Adriana Porowska", "state_secretary"),
|
| 466 |
+
("Szef Krajowej Administracji Skarbowej, sekretarz stanu w Ministerstwie Finansów Marcin Łoboda", "state_secretary"),
|
| 467 |
+
("Podsekretarz stanu, Główny Rzecznik Dyscypliny Finansów Publicznych w Ministerstwie Finansów Piotr Patkowski", "state_secretary"),
|
| 468 |
+
("Anna Radwan-Röhrenschef podsekretarz stanu w Ministerstwie Spraw Zagranicznych", "state_secretary"), # rank after the name
|
| 469 |
+
("Sekretarza stanu w MKiDN Szymon Giżyński", "state_secretary"), # genitive
|
| 470 |
+
("Sekretarz Stanu W MSZ Szymon Szynkowski Vel Sęk", "state_secretary"), # "Vel" capitalised
|
| 471 |
+
("Sekretarz stanu w ministerstwie Klimatu i Środowiska Jacek Ozdoba", "state_secretary"), # lower-case "ministerstwie"
|
| 472 |
+
("Sekretarz stanu w Ministerstwie Rozwoju, Przedsiębiorczości i Technologii Iwona Michałek", "state_secretary"),
|
| 473 |
+
("PodPodsekretarz stanu w MKiDN Marek Krawczyk", "state_secretary"), # exact typo label
|
| 474 |
+
# committee secretaries of the Sejm committees (the committee name is the list of Sejm committees)
|
| 475 |
+
("Sekretarz Komisji Spraw Zagranicznych Jan Kowalski", "sejm_committee_secretary"),
|
| 476 |
+
("Sekretarz Komisji Edukacji, Nauki i Młodzieży Agnieszka Kalinowska-Wójcik", "sejm_committee_secretary"),
|
| 477 |
+
("Sekretarz Komisji do Spraw Unii Europejskiej Agata Jackiewicz", "sejm_committee_secretary"),
|
| 478 |
+
("Sekretarz Komisji z Biura Spraw Międzynarodowych Agata Jackiewicz", "sejm_committee_secretary"),
|
| 479 |
+
("Starszy sekretarz Komisji Anna Pilarska", "sejm_committee_secretary"),
|
| 480 |
+
("Starszy sekretarz Komisji Zdrowia Monika Żołnierowicz-Kasprzyk", "sejm_committee_secretary"),
|
| 481 |
+
("Dyrektor Biura Obsługi Posłów Robert Pietrula", "sejm_senate_office_head"),
|
| 482 |
+
]
|
| 483 |
+
DROPPED = [
|
| 484 |
+
"Głos z sali",
|
| 485 |
+
"Głos z gości",
|
| 486 |
+
"Poseł do Parlamentu Europejskiego Jan Kowalski (PSL)",
|
| 487 |
+
"Poseł PE Tomasz Buczek",
|
| 488 |
+
"Poseł Jan Kowalski", # no party: not shown to be an MP of this Sejm
|
| 489 |
+
"Poseł Krzemiński", # surname only needs a party tag
|
| 490 |
+
"Poseł",
|
| 491 |
+
"Poseł (PiS)", # no name
|
| 492 |
+
"Posłanka (KO)",
|
| 493 |
+
"Poseł Jan Kowalski – spoza składu Komisji i inni",
|
| 494 |
+
"Poseł Jan Kowalski (PiS) reprezentująca\nwtrącenie",
|
| 495 |
+
"Poseł elekt Jan Kowalski (PiS)",
|
| 496 |
+
"Poseł na Sejm VIII kadencji Jan Klawiter",
|
| 497 |
+
"Poseł z delegacji Słowenii Jan Kowalski",
|
| 498 |
+
"Poseł Komisji Spraw Zagranicznych Izby Reprezentantów Japonii Kei Takagi",
|
| 499 |
+
"Poseł do PE Jan Kowalski (PiS)",
|
| 500 |
+
"Poseł do Parlamentu Europejskiego Jan Kowalski",
|
| 501 |
+
"Posłanka do PE Anna Kowalska (KO)",
|
| 502 |
+
"Poseł jan Kowalski (PiS)",
|
| 503 |
+
"Poseł Jan Kowalski (PiS) i inni",
|
| 504 |
+
"Przewodniczący poseł Jan Kowalski (PiS)\nwtrącenie",
|
| 505 |
+
"Przewodniczący Jan Kowalski",
|
| 506 |
+
"Przewodnicząca Małgorzata Wassermann", # bare chair without a party tag: not an MP by the label
|
| 507 |
+
"Przewodnicząca Małgorzata Wassermann (PiS)\nwtrącenie",
|
| 508 |
+
"Przewodnicząca Małgorzata Wassermann (PiS) i inni",
|
| 509 |
+
"Przewodniczący (PiS)", # no name
|
| 510 |
+
"Przewodniczący podkomisji Jan Kowalski (PiS)", # "podkomisji" needs "poseł" before the name
|
| 511 |
+
"Przewodniczący Komisji Spraw Zagranicznych Eduskunty Mika Nikko (Partia Finów)", # foreign MP
|
| 512 |
+
"Przewodniczący Komisji Nadzoru Finansowego Jacek Jastrzębski",
|
| 513 |
+
"Przewodniczący KRRiTV Witold Kołodziejski",
|
| 514 |
+
"Przewodniczący Państwowej Komisji Wyborczej Sylwester Marciniak",
|
| 515 |
+
"Przewodniczący poseł",
|
| 516 |
+
"Przewodniczący poseł do PE Jan Kowalski",
|
| 517 |
+
"Wicemarszałek województwa Jan Kowalski, poseł",
|
| 518 |
+
"Przewodniczący związku zawodowego Jan Kowalski",
|
| 519 |
+
"Sekretarz stanu w Kancelarii Prezydenta RP Jan Kowalski",
|
| 520 |
+
"Sekretarz stanu w BPM Jan Kowalski",
|
| 521 |
+
"Poseł przewodniczący Jan Kowalski", # no party
|
| 522 |
+
"Poseł przewodniczący Jan Kowalski i Anna Nowak",
|
| 523 |
+
"Sekretarz stanu w MF Jan Kowalski ze Związku Pracodawców", # not a ministry word
|
| 524 |
+
"Sekretarz stanu Sebastian Kaleta", # no body named
|
| 525 |
+
"Minister Jan Kowalski wypowiedź",
|
| 526 |
+
"Minister pełnomocny Jan Kowalski",
|
| 527 |
+
"Wiceprezes NIK Jan Kowalski",
|
| 528 |
+
"Prezes UOKiK Tomasz Chróstny",
|
| 529 |
+
"Prezes SN kierujący pracą Izby Karnej Jan Kowalski",
|
| 530 |
+
"Marszałek województwa Jan Kowalski",
|
| 531 |
+
"Legislator Klubu Parlamentarnego Lewica Dariusz Standerski",
|
| 532 |
+
"Legislator w Departamencie Prawnym Ministerstwa Zdrowia Michel Ryba",
|
| 533 |
+
"Ekspert zewnętrzny BEOS Jan Kowalski",
|
| 534 |
+
"Ekspert z BAS-u Jan Kowalski",
|
| 535 |
+
"Ekspert zewnętrzny Straży Marszałkowskiej Jan Kowalski",
|
| 536 |
+
"Ekspert Straży Granicznej Jan Kowalski",
|
| 537 |
+
"Ekspert Straży Marszałkowskiej Jan Kowalski i Anna Nowak",
|
| 538 |
+
"Naczelnik wydziału departamentu MRiT Małgorzata Skwarek-Kołtunowicz",
|
| 539 |
+
"Naczelnik wydziału w Ministerstwie Zdrowia Jan Kowalski",
|
| 540 |
+
"Dyrektor Biblioteki Narodowej Jan Kowalski",
|
| 541 |
+
"Dyrektor BN Tomasz Makowski",
|
| 542 |
+
"Dyrektor BOM Jan Kowalski", # "KS" is required
|
| 543 |
+
"Dyrektor BF KSM Jan Kowalski",
|
| 544 |
+
"Szef KSRP Jan Kowalski",
|
| 545 |
+
"Szef UOKiK Jan Kowalski",
|
| 546 |
+
"Dyrektor Biura Koła Poselskiego Jan Kowalski",
|
| 547 |
+
"Dyrektor Biura Komisji Europejskiej Jan Kowalski",
|
| 548 |
+
"Szef Kancelarii Prezydenta RP Jan Kowalski",
|
| 549 |
+
"Doradca marszałka Sejmu Jan Kowalski",
|
| 550 |
+
"Legislator z Ministerstwa Zdrowia Jan Kowalski",
|
| 551 |
+
"Legislator Katarzyna Abramowicz (PiS)", # only the one shipped label is an alias
|
| 552 |
+
"Legislator Jan Kowalski (KO)", # club legislators carry a club tag
|
| 553 |
+
"Legislator z Ministerstwa Zdrowia", # why "Legislator z NAME" is not a rule
|
| 554 |
+
"Legislator z Jan Kowalski",
|
| 555 |
+
"Legislator z Jarosław Lichocki i inni",
|
| 556 |
+
"Poseł Szymon Szynkowski vel sęk", # near-misses of the exact typo labels
|
| 557 |
+
"Przewodniczący poseł TomaszLatos",
|
| 558 |
+
"Ekspert Konfederacji Lewiatan Jan Kowalski",
|
| 559 |
+
"Dyrektor departamentu MF Jan Kowalski",
|
| 560 |
+
"Doradca Komisji Maciej Szczepański",
|
| 561 |
+
"Przedstawiciel Fundacji Jan Kowalski",
|
| 562 |
+
# guests and every other speaker the new label detector cuts out of the previous turn
|
| 563 |
+
"Świadek prof. dr hab. Robert Flisiak",
|
| 564 |
+
"Świadek nr 3",
|
| 565 |
+
"Tłumacz",
|
| 566 |
+
"Członek zarządu Fundacji im. Stefana Batorego Krzysztof Izdebski",
|
| 567 |
+
"Wójt Gminy Jan Kowalski",
|
| 568 |
+
"Burmistrz Jan Kowalski",
|
| 569 |
+
"Zastępca Wójta Gminy Jan Kowalski",
|
| 570 |
+
"Kandydat na szefa Kancelarii Sejmu Marek Siwiec",
|
| 571 |
+
"Kandydat na stanowisko szefa Kancelarii Sejmu Jacek Cichocki",
|
| 572 |
+
# near-misses of the forms added above
|
| 573 |
+
"Sekretarz Komisji",
|
| 574 |
+
"Sekretarz Komisji Kowalski",
|
| 575 |
+
"Sekretarz Komisji Zakładowej Jan Kowalski", # works council, not a Sejm committee
|
| 576 |
+
"Sekretarz Komisji Wspólnej Jan Kowalski",
|
| 577 |
+
"Sekretarz Komisji Jan Kowalski i Anna Nowak",
|
| 578 |
+
"Legislatorka Klubu Parlamentarnego Lewica Anna Nowak",
|
| 579 |
+
"LegislatorMaria Iwaszkiewicz",
|
| 580 |
+
"Zastępca szefa KPRM Jan Kowalski",
|
| 581 |
+
"Senator, prezes ZG ZOSPRP Waldemar Pawlak",
|
| 582 |
+
"Przewodniczący KSRM w KPRM Maciej Berek",
|
| 583 |
+
"Pracownik sekretariatu Komisji w BAS Jan Kowalski",
|
| 584 |
+
"Ekspert w Dziale Monitoringu Prawnego i Ekspertyz Biura Związku Powiatów Polskich Adrian Pokrywczyński",
|
| 585 |
+
"Specjalista w Biurze Związku Powiatów Polskich Jan Kowalski",
|
| 586 |
+
"Główny specjalista w departamencie MF Jan Kowalski", # ministry staff
|
| 587 |
+
"Wicedyrektor BA Jan Kowalski", # without "KS"
|
| 588 |
+
"Szef BBN Jan Kowalski",
|
| 589 |
+
"Ryszard Terlecki (KO)", # near-miss of the exact label
|
| 590 |
+
"Ryszard Terlecki",
|
| 591 |
+
# subcommittee: the deputy chair of the MON subcommittee is no MP, a bare label proves nothing
|
| 592 |
+
"Pierwszy zastępca przewodniczącego Podkomisji Kazimierz Nowaczyk",
|
| 593 |
+
"Pierwszy zastępca przewodniczącego Podkomisji d.s. Ponownego Zbadania Wypadku Lotniczego Kazimierz Nowaczyk",
|
| 594 |
+
"Przewodniczący Podkomisji Kazimierz Nowaczyk",
|
| 595 |
+
"Zastępca przewodniczącego Podkomisji Jan Kowalski",
|
| 596 |
+
"Zastępczyni przewodniczącej Podkomisji Anna Nowak (KO)",
|
| 597 |
+
"Zastępca przewodniczącego Komisji poseł Jan Kowalski (PiS)", # a standing committee's deputy is not in scope
|
| 598 |
+
"Zastępca przewodniczącego Krajowej Rady Regionalnych Izb Obrachunkowych Grzegorz Czarnocki",
|
| 599 |
+
"Przewodniczący Podkomisji poseł",
|
| 600 |
+
"Przewodniczący Podkomisji posłanka",
|
| 601 |
+
"Przewodniczący podkomisji Antoni Macierewicz (PiS)", # near-miss of the exact label
|
| 602 |
+
"Przewodniczący podkomisji Antoni Macierewicz i Jan Kowalski",
|
| 603 |
+
# state secretaries: a rank without a government body, the presidential office, former and prose labels
|
| 604 |
+
"Sekretarz stanu Jan Kowalski",
|
| 605 |
+
"Sekretarz stanu w KPRP Jan Kowalski",
|
| 606 |
+
"Sekretarz stanu w KP RP Jan Kowalski",
|
| 607 |
+
"Sekretarz stanu w Kancelarii Prezydenta Rzeczypospolitej Polskiej Jan Kowalski",
|
| 608 |
+
"Pełnomocnik rządu do spraw równego traktowania Anna Schmidt", # no rank
|
| 609 |
+
"Pełnomocnik rządu ds. strategicznej infrastruktury energetycznej Wojciech Wrochna",
|
| 610 |
+
"Zastępca szefa Kancelarii Prezesa Rady Ministrów Rafał Siemianowski",
|
| 611 |
+
"Pełnomocnik Prezydenta, sekretarz stanu w KPRP Jan Kowalski",
|
| 612 |
+
"Były sekretarz stanu w MF Jan Kowalski",
|
| 613 |
+
"Sekretarz stanu w MF Jan Kowalski: dzień dobry", # prose after a colon
|
| 614 |
+
"Przewodniczący poseł Paweł Kowal (KO): Sekretarz stanu w MSZ Jan Kowalski", # two labels run together
|
| 615 |
+
"Sekretarz stan w MSZ Jan Kowalski", # typo of the rank
|
| 616 |
+
"Sekretarz stanu w MSZ Jan Kowalski i Anna Nowak",
|
| 617 |
+
# committee secretaries: only the Sejm committees, never works councils, joint bodies or foreign ones
|
| 618 |
+
"Sekretarz Komisji Zakładowej NSZZ Solidarność Jan Kowalski",
|
| 619 |
+
"Sekretarz Komisji Międzyzakładowej Jan Kowalski",
|
| 620 |
+
"Sekretarz Komisji Wspólnej Rządu i Samorządu Terytorialnego Jan Kowalski",
|
| 621 |
+
"Sekretarz Komisji Wspólnej Rządu i Samorządu Jan Kowalski",
|
| 622 |
+
"Sekretarz Komisji Rady Młodzieżowej Jan Kowalski",
|
| 623 |
+
"Sekretarz Rady Młodzieżowej Jan Kowalski",
|
| 624 |
+
"Sekretarz Komisji z Biura Rady Młodzieżowej Jan Kowalski",
|
| 625 |
+
"Sekretarz Komisji Spraw Zagranicznych Eduskunty Mika Nikko", # the committee of the Finnish parliament
|
| 626 |
+
"Sekretarz Komisji Spraw Zagranicznych Jan Kowalski i Anna Nowak",
|
| 627 |
+
"Sekretarz Komisji (poza mikrofonem)",
|
| 628 |
+
"Starszy sekretarz Komisji Zakładowej Anna Pilarska",
|
| 629 |
+
"Dyrektor Biura Obsługi Pełnomocnika Rządu Jan Kowalski",
|
| 630 |
+
"Dyrektor Biura Obsługi Posłów Jan Kowalski i Anna Nowak",
|
| 631 |
+
"",
|
| 632 |
+
]
|
| 633 |
+
|
| 634 |
+
|
| 635 |
+
class SpeakerAllowlistTest(unittest.TestCase):
|
| 636 |
+
def test_official_speakers_are_kept_by_the_expected_rule(self):
|
| 637 |
+
for label, rule in ALLOWED:
|
| 638 |
+
self.assertEqual(classify_speaker(label), rule, label)
|
| 639 |
+
|
| 640 |
+
def test_everything_else_is_dropped(self):
|
| 641 |
+
for label in DROPPED:
|
| 642 |
+
self.assertIsNone(classify_speaker(label), label)
|
| 643 |
+
|
| 644 |
+
def test_rule_ids_are_unique_and_every_rule_is_exercised(self):
|
| 645 |
+
ids = [rule_id for rule_id, _ in SPEAKER_RULES]
|
| 646 |
+
self.assertEqual(len(ids), len(set(ids)))
|
| 647 |
+
self.assertEqual({rule for _, rule in ALLOWED}, set(ids))
|
| 648 |
+
|
| 649 |
+
def test_exact_labels_name_a_rule_and_no_rule_already_takes_them(self):
|
| 650 |
+
ids = {rule_id for rule_id, _ in SPEAKER_RULES}
|
| 651 |
+
self.assertTrue(fetch.EXACT_LABELS)
|
| 652 |
+
for label, rule in fetch.EXACT_LABELS.items():
|
| 653 |
+
self.assertIn(rule, ids, label)
|
| 654 |
+
self.assertEqual(label, unicodedata.normalize("NFC", label), label)
|
| 655 |
+
# a label a rule takes does not belong here: drop the stale alias
|
| 656 |
+
self.assertFalse(any(pattern.fullmatch(label) for _, pattern in SPEAKER_RULES), label)
|
| 657 |
+
|
| 658 |
+
def test_match_is_anchored_at_both_ends(self):
|
| 659 |
+
# text before or after an allowed label must not pass
|
| 660 |
+
for label, _ in ALLOWED:
|
| 661 |
+
self.assertIsNone(classify_speaker("Gość: " + label), label)
|
| 662 |
+
if "przedstawiciel Komisji" not in label and "reprezentując" not in label: # free-text notes
|
| 663 |
+
self.assertIsNone(classify_speaker(label + " i inni"), label)
|
| 664 |
+
|
| 665 |
+
|
| 666 |
+
class BuildAllowlistTest(unittest.TestCase):
|
| 667 |
+
"""build() on a synthetic cache: guests are dropped after the dedup and counted."""
|
| 668 |
+
|
| 669 |
+
def build(self, rows):
|
| 670 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 671 |
+
cache = Path(tmp) / "sejm_cache"
|
| 672 |
+
(cache / "parsed").mkdir(parents=True)
|
| 673 |
+
(cache / "parsed" / "turns_10.jsonl").write_text(
|
| 674 |
+
"".join(json.dumps(r, ensure_ascii=False) + "\n" for r in rows), encoding="utf-8")
|
| 675 |
+
old = fetch.CACHE
|
| 676 |
+
fetch.CACHE = cache
|
| 677 |
+
try:
|
| 678 |
+
fetch.build(terms=(10,), outdir=tmp)
|
| 679 |
+
finally:
|
| 680 |
+
fetch.CACHE = old
|
| 681 |
+
import pyarrow.parquet as pq
|
| 682 |
+
|
| 683 |
+
root = Path(tmp) / "data" / SOURCE
|
| 684 |
+
table = pq.read_table(root / f"{SOURCE}.parquet")
|
| 685 |
+
attribution = [json.loads(line) for line in
|
| 686 |
+
(root / f"{SOURCE}.attribution.jsonl").read_text(encoding="utf-8").splitlines()]
|
| 687 |
+
return table.to_pylist(), attribution, json.loads((root / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 688 |
+
|
| 689 |
+
def test_only_official_turns_survive_and_stats_add_up(self):
|
| 690 |
+
text = "Szanowni państwo, to jest dostatecznie długa wypowiedź na potrzeby testu."
|
| 691 |
+
rows = [
|
| 692 |
+
turn("ASW", 1, 0, "Przewodniczący poseł Jan Kowalski (PiS)", text + " 0", "aaa"),
|
| 693 |
+
turn("ASW", 1, 1, "Ekspert Konfederacji Lewiatan Adam Nowak", text + " 1", "aaa"),
|
| 694 |
+
turn("ASW", 1, 2, "Głos z sali", text + " 2", "aaa"),
|
| 695 |
+
turn("ASW", 1, 3, "Podsekretarz stanu w MF Ewa Zielińska", text + " 3", "aaa"),
|
| 696 |
+
turn("ASW", 1, 4, "Podsekretarz stanu w MF Ewa Zielińska", text + " 3", "aaa"), # exact duplicate
|
| 697 |
+
turn("ASW", 2, 0, "Przedstawiciel Fundacji Jan Kowalski", text + " 4", "bbb"), # sitting without official turns
|
| 698 |
+
turn("ŁAC", 1, 0, "Przewodniczący poseł Jan Kowalski (PiS)", text + " 0", "aaa"), # joint sitting
|
| 699 |
+
]
|
| 700 |
+
out, attribution, stats = self.build(rows)
|
| 701 |
+
self.assertEqual([r["author"] for r in out], [
|
| 702 |
+
"Przewodniczący poseł Jan Kowalski (PiS)", "Podsekretarz stanu w MF Ewa Zielińska"])
|
| 703 |
+
# no marker, no renumbering: the ids keep the original turn_idx
|
| 704 |
+
self.assertEqual([r["id"] for r in out], [
|
| 705 |
+
"sejm_committee_transcripts_10_ASW_1_0", "sejm_committee_transcripts_10_ASW_1_3"])
|
| 706 |
+
self.assertEqual([a["id"] for a in attribution], [r["id"] for r in out])
|
| 707 |
+
self.assertTrue(all(a["speaker"] == r["author"] for a, r in zip(attribution, out)))
|
| 708 |
+
self.assertEqual((stats["rows_raw_extracted"], stats["kept"], stats["rejected"]), (7, 2, 5))
|
| 709 |
+
self.assertEqual((stats["rejected_joint_sitting_dup"], stats["rejected_exact_dup"],
|
| 710 |
+
stats["rejected_not_official_speaker"]), (1, 1, 3))
|
| 711 |
+
self.assertEqual((stats["sittings"], stats["unique_speaker_labels"]), (1, 2))
|
| 712 |
+
self.assertEqual(stats["characters"], sum(len(r["text"]) for r in out))
|
| 713 |
+
|
| 714 |
+
def test_unknown_label_is_dropped(self):
|
| 715 |
+
text = "Wypowiedź o nieznanej roli mówcy, dostatecznie długa dla testu."
|
| 716 |
+
out, _, stats = self.build([turn("ASW", 1, 0, "Kosmonauta Jan Kowalski", text, "aaa"),
|
| 717 |
+
turn("ASW", 1, 1, "Poseł Jan Kowalski (KO)", text, "aaa")])
|
| 718 |
+
self.assertEqual([r["author"] for r in out], ["Poseł Jan Kowalski (KO)"])
|
| 719 |
+
self.assertEqual(stats["rejected_not_official_speaker"], 1)
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
class RoleLabelTest(unittest.TestCase):
|
| 723 |
+
GIVEN = {"Jan", "Anna", "Maria"}
|
| 724 |
+
|
| 725 |
+
def test_role_is_the_label_without_the_name(self):
|
| 726 |
+
for label, role in [
|
| 727 |
+
("Poseł Jan Maria Kowalski (PiS)", "Poseł"),
|
| 728 |
+
("Sekretarz stanu w MF Anna Nowak", "Sekretarz stanu w MF"),
|
| 729 |
+
("Prezes NIK Marian Banaś", "Prezes NIK"),
|
| 730 |
+
("Legislator Jan de Vries", "Legislator"),
|
| 731 |
+
("Głos z sali", "Głos z sali"), # the last token is not a name
|
| 732 |
+
("Legislator", "Legislator"),
|
| 733 |
+
("Poseł Jan Kowalski (Polska 2050)", "Poseł"),
|
| 734 |
+
("Poseł Jan Kowalski (KO) – spoza składu Komisji", "Poseł – spoza składu Komisji"),
|
| 735 |
+
("Przewodniczący poseł Anna Nowak-Kowalska (KO)", "Przewodniczący poseł"),
|
| 736 |
+
("Ekspert (BAS) Jan Kowalski", "Ekspert (BAS)"), # a parenthesis inside a role is not a party
|
| 737 |
+
]:
|
| 738 |
+
self.assertEqual(clean.role_of(label, self.GIVEN), role, label)
|
| 739 |
+
|
| 740 |
+
def test_given_names_come_from_mp_labels(self):
|
| 741 |
+
labels = ["Poseł Jan Maria Kowalski (PiS)", "Przewodnicząca posłanka Anna Nowak (KO)", "Prezes NIK Marian Banaś"]
|
| 742 |
+
self.assertEqual(clean.given_names(labels), {"Jan", "Maria", "Anna"})
|
| 743 |
+
|
| 744 |
+
def test_roles_table_keeps_decisions_apart_and_sorts_by_characters(self):
|
| 745 |
+
rows = clean.roles_table({
|
| 746 |
+
"Poseł Jan Kowalski (PiS)": (2, 100, "mp"),
|
| 747 |
+
"Poseł Jan Maria Anna Kowalski (PiS)": (1, 400, None), # same role, other decision
|
| 748 |
+
"Prezes NIK Marian Banaś": (1, 50, "constitutional_organ_head"),
|
| 749 |
+
})
|
| 750 |
+
self.assertEqual(rows, [["Poseł", "exclude", "", 1, 400, 1],
|
| 751 |
+
["Poseł", "include", "mp", 2, 100, 1],
|
| 752 |
+
["Prezes NIK", "include", "constitutional_organ_head", 1, 50, 1]])
|
| 753 |
+
|
| 754 |
+
|
| 755 |
+
class CleanScriptTest(unittest.TestCase):
|
| 756 |
+
"""clean_sejm_committee_transcripts.build() on a small pinned input."""
|
| 757 |
+
|
| 758 |
+
TEXT = "Wypowiedź na potrzeby testu, dostatecznie długa, aby miała sens."
|
| 759 |
+
|
| 760 |
+
SPEAKERS = ["Poseł Jan Kowalski (KO)", "Głos z sali", "Ekspert Fundacji Adam Nowak",
|
| 761 |
+
"Minister zdrowia Ewa Zielińska", "Poseł Jan Kowalski (KO)"]
|
| 762 |
+
|
| 763 |
+
def make_input(self, directory, entries=None):
|
| 764 |
+
"""Write the input files: `entries` is [(speaker, text)], by default the five turns above.
|
| 765 |
+
|
| 766 |
+
The stats claim four rows were rejected before (3 joint-sitting duplicates, 1 exact duplicate)."""
|
| 767 |
+
import pyarrow as pa
|
| 768 |
+
import pyarrow.parquet as pq
|
| 769 |
+
|
| 770 |
+
if entries is None:
|
| 771 |
+
entries = [(speaker, self.TEXT + str(idx)) for idx, speaker in enumerate(self.SPEAKERS)]
|
| 772 |
+
rows, attribution = [], []
|
| 773 |
+
for idx, (speaker, text) in enumerate(entries):
|
| 774 |
+
r = turn("ASW", 1 + idx // 3, idx % 3, speaker, text, f"sha{1 + idx // 3}") # the hash is per sitting
|
| 775 |
+
rid = row_id(r)
|
| 776 |
+
rows.append({"id": rid, "text": r["text"], "source": SOURCE, "added": "2026-09-18",
|
| 777 |
+
"created": r["date"], "token_count": 10 + idx, "license": LICENSE, "author": speaker})
|
| 778 |
+
attribution.append({k: r[k] for k in ("term", "committee_code", "committee_name", "sitting_num", "date",
|
| 779 |
+
"turn_idx", "speaker", "content_sha1", "source_url")} | {"id": rid})
|
| 780 |
+
schema = pa.schema([(f, pa.int64() if f == "token_count" else pa.string()) for f in FIELDS])
|
| 781 |
+
pq.write_table(pa.Table.from_pylist(rows, schema=schema), directory / f"{SOURCE}.parquet", compression="zstd")
|
| 782 |
+
(directory / f"{SOURCE}.attribution.jsonl").write_text(
|
| 783 |
+
"".join(json.dumps(a, ensure_ascii=False, sort_keys=True) + "\n" for a in attribution), encoding="utf-8")
|
| 784 |
+
stats = {"rows_raw_extracted": len(rows) + 4, "rejected": 4, "rejected_joint_sitting_dup": 3, "rejected_exact_dup": 1,
|
| 785 |
+
**fetch.shard_stats(rows, attribution), "added": "2026-09-18"}
|
| 786 |
+
(directory / f"{SOURCE}.stats.json").write_text(json.dumps(stats), encoding="utf-8")
|
| 787 |
+
return rows
|
| 788 |
+
|
| 789 |
+
def run_build(self, directory):
|
| 790 |
+
pins = {name: hashlib.sha256((directory / name).read_bytes()).hexdigest() for name in clean.INPUT_SHA256}
|
| 791 |
+
old = clean.INPUT_SHA256
|
| 792 |
+
clean.INPUT_SHA256 = pins
|
| 793 |
+
try:
|
| 794 |
+
return clean.build(directory, directory)
|
| 795 |
+
finally:
|
| 796 |
+
clean.INPUT_SHA256 = old
|
| 797 |
+
|
| 798 |
+
def test_filter_stats_and_roles_table(self):
|
| 799 |
+
import pyarrow.parquet as pq
|
| 800 |
+
|
| 801 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 802 |
+
directory = Path(tmp)
|
| 803 |
+
self.make_input(directory)
|
| 804 |
+
stats = self.run_build(directory)
|
| 805 |
+
kept = pq.read_table(directory / f"{SOURCE}.parquet").to_pylist()
|
| 806 |
+
self.assertEqual([r["author"] for r in kept], [
|
| 807 |
+
"Poseł Jan Kowalski (KO)", "Minister zdrowia Ewa Zielińska", "Poseł Jan Kowalski (KO)"])
|
| 808 |
+
self.assertEqual([r["token_count"] for r in kept], [10, 13, 14])
|
| 809 |
+
attribution = [json.loads(line) for line in
|
| 810 |
+
(directory / f"{SOURCE}.attribution.jsonl").read_text(encoding="utf-8").splitlines()]
|
| 811 |
+
self.assertEqual([a["id"] for a in attribution], [r["id"] for r in kept])
|
| 812 |
+
self.assertEqual((stats["kept"], stats["rejected"], stats["rejected_not_official_speaker"]), (3, 6, 2))
|
| 813 |
+
self.assertEqual(stats["rows_split_out"], 0)
|
| 814 |
+
self.assertEqual(stats["kept"] + stats["rejected"], stats["rows_raw_extracted"] + stats["rows_split_out"])
|
| 815 |
+
self.assertEqual((stats["tokens"], stats["unique_speaker_labels"], stats["sittings"]), (37, 2, 2))
|
| 816 |
+
removed = stats["speaker_allowlist"]["removed"]
|
| 817 |
+
self.assertEqual((removed["turns"], removed["tokens"], removed["speaker_labels"]), (2, 23, 2))
|
| 818 |
+
self.assertEqual(stats["speaker_allowlist"]["kept_by_rule"]["mp"]["turns"], 2)
|
| 819 |
+
self.assertEqual(set(stats["speaker_allowlist"]["input_sha256"]), set(clean.INPUT_SHA256))
|
| 820 |
+
with (directory / clean.ROLES_CSV).open(encoding="utf-8", newline="") as stream:
|
| 821 |
+
table = list(csv.DictReader(stream))
|
| 822 |
+
self.assertEqual({(r["role"], r["decision"]) for r in table}, {
|
| 823 |
+
("Poseł", "include"), ("Minister zdrowia", "include"),
|
| 824 |
+
("Głos z sali", "exclude"), ("Ekspert Fundacji", "exclude")})
|
| 825 |
+
self.assertEqual(sum(int(r["turns"]) for r in table), 5)
|
| 826 |
+
|
| 827 |
+
def test_turns_are_cut_at_labels_and_every_piece_is_classified(self):
|
| 828 |
+
import pyarrow.parquet as pq
|
| 829 |
+
|
| 830 |
+
entries = [
|
| 831 |
+
("Poseł Jan Kowalski (KO)", "Pierwsze zdanie posła jest dość długie.\nŚwiadek prof. dr hab. Robert Flisiak:\n"
|
| 832 |
+
"Odpowiedź świadka jest również długa.\nPoseł Anna Nowak (KO):\nReplika posłanki, także dostatecznie długa."),
|
| 833 |
+
("Minister zdrowia Ewa Zielińska", self.TEXT), # nothing to cut: keeps its stored token count
|
| 834 |
+
("Minister zdrowia Ewa Zielińska", "Rozwiązania dotyczące upraw-\n56 m.h.\nPełny Zapis Przebiegu Posiedzenia:\n"
|
| 835 |
+
"Komisji Zdrowia (Nr 258)\nnienia do zmiany decyzji administracyjnej."),
|
| 836 |
+
("Poseł Jan Kowalski (KO)", "Dłuższy tekst posła numer cztery.\nGłos z sali:\nTak."), # "Tak." is too short
|
| 837 |
+
]
|
| 838 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 839 |
+
directory = Path(tmp)
|
| 840 |
+
self.make_input(directory, entries)
|
| 841 |
+
stats = self.run_build(directory)
|
| 842 |
+
kept = pq.read_table(directory / f"{SOURCE}.parquet").to_pylist()
|
| 843 |
+
attribution = [json.loads(line) for line in
|
| 844 |
+
(directory / f"{SOURCE}.attribution.jsonl").read_text(encoding="utf-8").splitlines()]
|
| 845 |
+
with (directory / clean.ROLES_CSV).open(encoding="utf-8", newline="") as stream:
|
| 846 |
+
roles = list(csv.DictReader(stream))
|
| 847 |
+
base = "sejm_committee_transcripts_10_ASW_"
|
| 848 |
+
self.assertEqual([(r["id"], r["author"], r["text"]) for r in kept], [
|
| 849 |
+
(base + "1_0", "Poseł Jan Kowalski (KO)", "Pierwsze zdanie posła jest dość długie."),
|
| 850 |
+
(base + "1_0_2", "Poseł Anna Nowak (KO)", "Replika posłanki, także dostatecznie długa."), # k counts the dropped piece 1
|
| 851 |
+
(base + "1_1", "Minister zdrowia Ewa Zielińska", self.TEXT),
|
| 852 |
+
(base + "1_2", "Minister zdrowia Ewa Zielińska", "Rozwiązania dotyczące uprawnienia do zmiany decyzji administracyjnej."),
|
| 853 |
+
(base + "2_0", "Poseł Jan Kowalski (KO)", "Dłuższy tekst posła numer cztery."),
|
| 854 |
+
])
|
| 855 |
+
# the stored count survives only where the text is the stored text; the rest is counted again
|
| 856 |
+
self.assertEqual([r["token_count"] for r in kept],
|
| 857 |
+
[11 if r["text"] == self.TEXT else fetch.count_tokens([r["text"]])[0] for r in kept])
|
| 858 |
+
# the sidecar: the speaker is the label, everything else comes from the input turn
|
| 859 |
+
self.assertEqual([a["id"] for a in attribution], [r["id"] for r in kept])
|
| 860 |
+
self.assertEqual([a["speaker"] for a in attribution], [r["author"] for r in kept])
|
| 861 |
+
self.assertEqual([a["turn_idx"] for a in attribution], [0, 0, 1, 2, 0])
|
| 862 |
+
self.assertEqual([a["content_sha1"] for a in attribution], ["sha1", "sha1", "sha1", "sha1", "sha2"])
|
| 863 |
+
self.assertTrue(all(a["committee_code"] == "ASW" for a in attribution))
|
| 864 |
+
# 4 turns -> 7 pieces: 1 too short, 1 not official, 5 kept
|
| 865 |
+
self.assertEqual(stats["rows_split_out"], 3)
|
| 866 |
+
self.assertEqual((stats["kept"], stats["rejected_too_short"], stats["rejected_not_official_speaker"]), (5, 1, 1))
|
| 867 |
+
self.assertEqual(stats["rejected"], 4 + 1 + 1)
|
| 868 |
+
self.assertEqual(stats["kept"] + stats["rejected"], stats["rows_raw_extracted"] + stats["rows_split_out"])
|
| 869 |
+
self.assertEqual(stats["tokens"], sum(r["token_count"] for r in kept))
|
| 870 |
+
self.assertEqual(stats["page_blocks"], {"removed": 1, "hyphenated_words_rejoined": 1, "glued_footers_repaired": 0,
|
| 871 |
+
"stray_footers_removed": 0})
|
| 872 |
+
removed = stats["speaker_allowlist"]["removed"]
|
| 873 |
+
self.assertEqual((removed["turns"], removed["tokens"], removed["speaker_labels"]), (
|
| 874 |
+
1, fetch.count_tokens(["Odpowiedź świadka jest również długa."])[0], 1))
|
| 875 |
+
# the roles table counts pieces, kept and dropped
|
| 876 |
+
self.assertEqual(sum(int(r["turns"]) for r in roles), 6)
|
| 877 |
+
self.assertIn(("Świadek prof. dr hab.", "exclude"), {(r["role"], r["decision"]) for r in roles})
|
| 878 |
+
|
| 879 |
+
def test_a_cut_piece_equal_to_the_previous_piece_is_an_exact_duplicate(self):
|
| 880 |
+
import pyarrow.parquet as pq
|
| 881 |
+
|
| 882 |
+
text = "Powtórzona wypowiedź posła, dostatecznie długa."
|
| 883 |
+
entries = [("Poseł Jan Kowalski (KO)", "Wstęp posła, dostatecznie długi.\nPoseł Jan Kowalski (KO):\n" + text),
|
| 884 |
+
("Poseł Jan Kowalski (KO)", text)]
|
| 885 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 886 |
+
directory = Path(tmp)
|
| 887 |
+
self.make_input(directory, entries)
|
| 888 |
+
stats = self.run_build(directory)
|
| 889 |
+
kept = pq.read_table(directory / f"{SOURCE}.parquet").to_pylist()
|
| 890 |
+
self.assertEqual([r["id"] for r in kept], ["sejm_committee_transcripts_10_ASW_1_0", "sejm_committee_transcripts_10_ASW_1_0_1"])
|
| 891 |
+
self.assertEqual(stats["rejected_exact_dup"], 1 + 1) # one in the input stats, one new
|
| 892 |
+
self.assertEqual(stats["kept"] + stats["rejected"], stats["rows_raw_extracted"] + stats["rows_split_out"])
|
| 893 |
+
|
| 894 |
+
def test_duplicate_ids_after_cutting_are_refused(self):
|
| 895 |
+
old = clean.cut_turn
|
| 896 |
+
clean.cut_turn = lambda row, attribution: ([{**row, **attribution, "id": "same"}], {})
|
| 897 |
+
try:
|
| 898 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 899 |
+
directory = Path(tmp)
|
| 900 |
+
self.make_input(directory)
|
| 901 |
+
with self.assertRaises(SystemExit):
|
| 902 |
+
self.run_build(directory)
|
| 903 |
+
finally:
|
| 904 |
+
clean.cut_turn = old
|
| 905 |
+
|
| 906 |
+
def test_unpinned_input_is_refused(self):
|
| 907 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 908 |
+
directory = Path(tmp)
|
| 909 |
+
self.make_input(directory)
|
| 910 |
+
with self.assertRaises(SystemExit):
|
| 911 |
+
clean.build(directory, directory) # the synthetic files are not the pinned release
|
| 912 |
+
|
| 913 |
+
def test_stats_that_do_not_describe_the_parquet_are_refused(self):
|
| 914 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 915 |
+
directory = Path(tmp)
|
| 916 |
+
self.make_input(directory)
|
| 917 |
+
path = directory / f"{SOURCE}.stats.json"
|
| 918 |
+
stats = json.loads(path.read_text(encoding="utf-8"))
|
| 919 |
+
stats["tokens"] += 1
|
| 920 |
+
path.write_text(json.dumps(stats), encoding="utf-8")
|
| 921 |
+
with self.assertRaises(SystemExit):
|
| 922 |
+
self.run_build(directory)
|
| 923 |
+
|
| 924 |
+
|
| 925 |
class ShippedShardTest(unittest.TestCase):
|
| 926 |
def test_canonical_schema_and_stats_consistency(self):
|
| 927 |
import pyarrow.parquet as pq
|
|
|
|
| 935 |
self.assertEqual(len(rows), stats["kept"])
|
| 936 |
self.assertEqual(sum(r["token_count"] for r in rows), stats["tokens"])
|
| 937 |
self.assertEqual(sum(len(r["text"]) for r in rows), stats["characters"])
|
| 938 |
+
self.assertEqual(stats["kept"] + stats["rejected"], stats["rows_raw_extracted"] + stats["rows_split_out"])
|
| 939 |
self.assertTrue(all(r["token_count"] > 0 and r["text"].strip() for r in rows))
|
| 940 |
+
self.assertEqual(len({r["id"] for r in rows}), len(rows))
|
| 941 |
+
self.assertEqual([a["speaker"] for a in attribution], [r["author"] for r in rows])
|
| 942 |
self.assertTrue(all(r["source"] == SOURCE and r["license"] == LICENSE and r["author"] for r in rows))
|
| 943 |
self.assertTrue(all(r["created"] == "" or len(r["created"]) == 10 for r in rows))
|
| 944 |
self.assertEqual(len(attribution), stats["kept"])
|
|
|
|
| 947 |
self.assertEqual(stats["date_min"], min(a["date"] for a in attribution if a["date"]))
|
| 948 |
self.assertEqual(stats["date_max"], max(a["date"] for a in attribution if a["date"]))
|
| 949 |
|
| 950 |
+
def test_only_official_speakers_ship_and_the_stats_say_so(self):
|
| 951 |
+
import pyarrow.parquet as pq
|
| 952 |
+
|
| 953 |
+
rows = pq.read_table(DATA / f"{SOURCE}.parquet").to_pylist()
|
| 954 |
+
stats = json.loads((DATA / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 955 |
+
outside = {r["author"] for r in rows if classify_speaker(r["author"]) is None}
|
| 956 |
+
self.assertEqual(outside, set())
|
| 957 |
+
self.assertFalse([r for r in rows if "Głos z" in r["author"]])
|
| 958 |
+
self.assertEqual(len({r["author"] for r in rows}), stats["unique_speaker_labels"])
|
| 959 |
+
self.assertEqual(stats["rejected"], stats["rejected_joint_sitting_dup"] + stats["rejected_exact_dup"]
|
| 960 |
+
+ stats["rejected_too_short"] + stats["rejected_not_official_speaker"])
|
| 961 |
+
self.assertGreater(stats["rows_split_out"], 0)
|
| 962 |
+
allowlist = stats["speaker_allowlist"]
|
| 963 |
+
self.assertEqual(allowlist["removed"]["turns"], stats["rejected_not_official_speaker"])
|
| 964 |
+
self.assertEqual(set(allowlist["kept_by_rule"]), {rule_id for rule_id, _ in SPEAKER_RULES})
|
| 965 |
+
self.assertEqual(sum(v["turns"] for v in allowlist["kept_by_rule"].values()), stats["kept"])
|
| 966 |
+
self.assertEqual(sum(v["characters"] for v in allowlist["kept_by_rule"].values()), stats["characters"])
|
| 967 |
+
self.assertEqual(sum(v["speaker_labels"] for v in allowlist["kept_by_rule"].values()),
|
| 968 |
+
stats["unique_speaker_labels"])
|
| 969 |
+
|
| 970 |
+
def test_no_label_line_and_no_page_block_is_left_inside_a_turn(self):
|
| 971 |
+
import pyarrow.parquet as pq
|
| 972 |
+
|
| 973 |
+
rows = pq.read_table(DATA / f"{SOURCE}.parquet").to_pylist()
|
| 974 |
+
# a label line inside a kept row is a guest's (or another speaker's) words in an official's turn:
|
| 975 |
+
# cutting the stored text again must find no label, allowlisted or not
|
| 976 |
+
with_label = [r["id"] for r in rows if len(fetch.split_at_labels(r["text"].split("\n"))) > 1]
|
| 977 |
+
self.assertEqual(with_label[:5], [])
|
| 978 |
+
# no line is a page-break title line. The phrase itself stays where prose quotes it ("... w pełnym
|
| 979 |
+
# zapisie przebiegu posiedzenia ..."), so the check is per line, not per row.
|
| 980 |
+
titled = [r["id"] for r in rows if any(fetch._after_title(line) is not None for line in r["text"].split("\n"))]
|
| 981 |
+
self.assertEqual(titled[:5], [])
|
| 982 |
+
|
| 983 |
+
def test_guests_inside_the_two_known_turns_are_gone(self):
|
| 984 |
+
import pyarrow.parquet as pq
|
| 985 |
+
|
| 986 |
+
by_id = {r["id"]: r["text"] for r in pq.read_table(DATA / f"{SOURCE}.parquet").to_pylist()}
|
| 987 |
+
spc = by_id[f"{SOURCE}_10_SPC_62_14"] # held "Członek zarządu Fundacji im. Stefana Batorego Krzysztof Izdebski:"
|
| 988 |
+
skgk = by_id[f"{SOURCE}_10_SKGK_3_24"] # held "Świadek prof. dr hab. Robert Flisiak:"
|
| 989 |
+
self.assertNotIn("Izdebski:", spc)
|
| 990 |
+
self.assertNotIn("Fundacji im. Stefana Batorego", spc)
|
| 991 |
+
self.assertNotIn("Flisiak:", skgk)
|
| 992 |
+
self.assertNotIn("Świadek", skgk)
|
| 993 |
+
|
| 994 |
+
def test_speaker_roles_table_matches_the_shard(self):
|
| 995 |
+
stats = json.loads((DATA / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 996 |
+
with (DATA / clean.ROLES_CSV).open(encoding="utf-8", newline="") as stream:
|
| 997 |
+
reader = csv.reader(stream)
|
| 998 |
+
self.assertEqual(next(reader), clean.ROLES_HEADER)
|
| 999 |
+
table = [dict(zip(clean.ROLES_HEADER, row)) for row in reader]
|
| 1000 |
+
rule_ids = {rule_id for rule_id, _ in SPEAKER_RULES}
|
| 1001 |
+
included = [row for row in table if row["decision"] == "include"]
|
| 1002 |
+
excluded = [row for row in table if row["decision"] == "exclude"]
|
| 1003 |
+
self.assertEqual({row["decision"] for row in table}, {"include", "exclude"})
|
| 1004 |
+
self.assertEqual({row["rule"] for row in included} - rule_ids, set())
|
| 1005 |
+
self.assertEqual({row["rule"] for row in excluded}, {""})
|
| 1006 |
+
for field, key in [("turns", "kept"), ("characters", "characters"), ("speaker_labels", "unique_speaker_labels")]:
|
| 1007 |
+
self.assertEqual(sum(int(row[field]) for row in included), stats[key], field)
|
| 1008 |
+
removed = stats["speaker_allowlist"]["removed"]
|
| 1009 |
+
self.assertEqual(sum(int(row["turns"]) for row in excluded), removed["turns"])
|
| 1010 |
+
self.assertEqual(sum(int(row["characters"]) for row in excluded), removed["characters"])
|
| 1011 |
+
self.assertEqual(sum(int(row["speaker_labels"]) for row in excluded), removed["speaker_labels"])
|
| 1012 |
+
|
| 1013 |
|
| 1014 |
if __name__ == "__main__":
|
| 1015 |
unittest.main()
|