Datasets:
parliamentary: rebuild from IPI PAN's PPC TEI dump, official speakers only (v0.2.6 rights audit) (#108)
Browse files- parliamentary: rebuild from IPI PAN's PPC TEI dump, official speakers only (v0.2.6 rights audit, v2#54) (2c5d9a3f948f51e303c04b875bef4a3177b7c9be)
- parliamentary: split dropped-document counts into sittings and interpellations (0efe64b6bd675288c534648cc0e20da563fa7bda)
- parliamentary: keep unusual names that belong to a member (v2#54, decision 1A) (8496674f2f62d4cc142f092e32e7ae830a36591b)
- data/parliamentary/parliamentary.attribution.jsonl +3 -0
- data/parliamentary/parliamentary.md +215 -32
- data/parliamentary/parliamentary.parquet +2 -2
- data/parliamentary/parliamentary.speaker-roles.csv +0 -0
- data/parliamentary/parliamentary.stats.json +154 -12
- data/sejm_api/sejm_api.md +2 -1
- data/sejm_committee_transcripts/sejm_committee_transcripts.md +3 -3
- data/sejm_interpellations/sejm_interpellations.md +3 -3
- src/clean_sejm_committee_transcripts.py +10 -5
- src/fetch_parliamentary.py +667 -0
- src/fetch_sejm_api.py +11 -25
- src/fetch_sejm_committee_transcripts.py +4 -3
- src/sejm_api_common.py +4 -0
- src/sources.py +40 -6
- src/test_parliamentary_contract.py +582 -0
- src/test_sejm_api_contract.py +6 -4
- src/test_sejm_committee_transcripts_contract.py +17 -0
data/parliamentary/parliamentary.attribution.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e907c4a0b27bf728f2ba246473ba665b8704e1c529d8e549c0ba796bf18895e9
|
| 3 |
+
size 154021484
|
data/parliamentary/parliamentary.md
CHANGED
|
@@ -1,43 +1,226 @@
|
|
| 1 |
-
# parliamentary
|
| 2 |
|
| 3 |
-
Polish Parliamentary Corpus (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
##
|
| 6 |
-
- **Source (upstream):** http://clip.ipipan.waw.pl/PPC
|
| 7 |
-
- **Domain:** political/spoken
|
| 8 |
-
- **Language:** Polish (pl)
|
| 9 |
-
- **License:** `public-domain (official documents)`
|
| 10 |
-
- **Created (range):** 1991-01-01, 2019-12-31
|
| 11 |
-
- **Added:** 2026-06-15
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
##
|
| 17 |
-
Pulled from SpeakLeash's public redistribution (`speakleash-ds-pub`, key `PPC_corpus`) of the upstream source above. SpeakLeash credited as intermediate aggregator; upstream license/attribution preserved.
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
| `public-domain (official documents)` | 324,622 |
|
| 29 |
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
-
|
| 37 |
-
|
| 38 |
-
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Polish Parliamentary Corpus (Sejm and Senate, 1919-2025) - official parliamentary materials
|
| 2 |
|
| 3 |
+
The Sejm and Senate part of IPI PAN's Polish Parliamentary Corpus (PPC), rebuilt from its
|
| 4 |
+
speaker-labelled TEI dump: plenary and committee sittings **limited to statements by official
|
| 5 |
+
speakers** (MPs and senators, members of the government, heads of constitutional organs, Sejm and
|
| 6 |
+
Senate staff; see "Speaker allowlist"), and Sejm interpellations, questions and the government's
|
| 7 |
+
replies kept whole:
|
| 8 |
+
**348,475 records / 1,606,998,487 `cl100k_base` tokens / 4,370,190,797 characters**
|
| 9 |
+
(43,734 sittings, 304,741 interpellation records), 1919-2025. The Sejm from term 9 (2019-) is not
|
| 10 |
+
here: `sejm_api`, `sejm_committee_transcripts` and `sejm_interpellations` cover it.
|
| 11 |
|
| 12 |
+
## Origin and license
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
- Origin: Polish Parliamentary Corpus, Institute of Computer Science, Polish Academy of Sciences
|
| 15 |
+
(IPI PAN), <https://clip.ipipan.waw.pl/PPC>: the per-term TEI dump of 2025-05-21,
|
| 16 |
+
`https://kdp.ipipan.waw.pl/static/ppcdump-tei/<term>-tei.zip`, 28 zips, 26,409,547,075 bytes,
|
| 17 |
+
downloaded 2026-10-07 and pinned by size and SHA-256 in `src/fetch_parliamentary.py`. The texts
|
| 18 |
+
are the stenographic reports, committee transcripts and interpellations published by the
|
| 19 |
+
Chancelleries of the Sejm and the Senate (each TEI header names the publisher). Each record's
|
| 20 |
+
`ppc_path` in `parliamentary.attribution.jsonl` pins its document in the dump.
|
| 21 |
+
- Credit: the speaker turns, speaker labels, roles and dates that this source is cut and filtered
|
| 22 |
+
by come from IPI PAN's TEI markup. Cite Maciej Ogrodniczuk (2018), "Polish Parliamentary
|
| 23 |
+
Corpus", Proceedings of the LREC 2018 Workshop ParlaCLARIN: Creating and Using Parliamentary
|
| 24 |
+
Corpora. PPC's CC BY licence covers its annotations; none of the linguistic annotation layers is
|
| 25 |
+
shipped, and the speaker labels in the attribution sidecar are credited here.
|
| 26 |
+
- License: official parliamentary materials are excluded from copyright by
|
| 27 |
+
[art. 4(2) of the Polish Copyright Act](https://eli.gov.pl/api/acts/DU/2025/24/text/O/D20250024.pdf);
|
| 28 |
+
reuse is governed by the
|
| 29 |
+
[Polish Open Data and Reuse of PSI Act](https://eli.gov.pl/api/acts/DU/2023/1524/text.html).
|
| 30 |
+
IPI PAN's PPC page states that the parliamentary data is public domain. Asked for its basis, IPI
|
| 31 |
+
PAN answered (e-mail, 2026-10-07) that it is public information made available by statute (the
|
| 32 |
+
Open Data Act and the Access to Public Information Act), with no agreement with the
|
| 33 |
+
Chancelleries. Record license: `public-domain (official documents)`. No Creative Commons grant is
|
| 34 |
+
claimed for the text. Not lawyer-signed-off; whether statements of guests at sittings are
|
| 35 |
+
official documents under art. 4(2) is open (polish-dynaword-v2#54), so they are left out.
|
| 36 |
|
| 37 |
+
## What the texts are
|
|
|
|
| 38 |
|
| 39 |
+
- **Genre**: stenographic reports of plenary sittings; transcripts and bulletins of committee
|
| 40 |
+
sittings; interpellations and questions ("zapytania") of MPs with the government's replies.
|
| 41 |
+
- **Register**: parliamentary Polish as recorded and edited by the stenographers - speeches,
|
| 42 |
+
debate with interruptions, chair announcements, read-out documents - and, in the
|
| 43 |
+
interpellations, formal letters to and from ministers. The texts of 1919-1989 were digitised from
|
| 44 |
+
the printed reports (the dump does not say how; each header names an `.odt` original): samples
|
| 45 |
+
read clean, interwar spelling is kept ("zależnem"), and some speaker labels carry typos ("Poeł",
|
| 46 |
+
"Marszalek"). Not machine-translated.
|
| 47 |
+
- **Time span**:
|
| 48 |
|
| 49 |
+
| Period | House | Kind | Records | Characters | Dates |
|
| 50 |
+
|---|---|---|---:|---:|---|
|
| 51 |
+
| 1919-1939 | Sejm | plenary | 1,021 | 156,362,281 | 1919-02-10 - 1939-09-02 |
|
| 52 |
+
| 1919-1939 | Senat | plenary | 323 | 43,495,751 | 1922-11-28 - 1939-09-02 |
|
| 53 |
+
| 1944-1946 | Krajowa Rada Narodowa | plenary | 6 | 1,093,152 | 1944-12-31 - 1946-09-23 |
|
| 54 |
+
| 1947-1989 | Sejm | plenary | 460 | 111,637,467 | 1947-02-04 - 1989-05-30 |
|
| 55 |
+
| 1947-1989 | Sejm | committee | 2,433 | 62,299,011 | 1965-09-17 - 1989-05-29 |
|
| 56 |
+
| 1989-1991 | Sejm | plenary | 79 | 47,102,915 | 1989-07-04 - 1991-10-25 |
|
| 57 |
+
| 1989-1991 | Senat | plenary | 61 | 18,104,530 | 1989-07-04 - 1991-10-24 |
|
| 58 |
+
| 1991-2019 | Sejm | plenary | 2,093 | 927,132,603 | 1991-11-25 - 2019-10-16 |
|
| 59 |
+
| 1991-2019 | Sejm | committee | 31,362 | 1,177,690,020 | 1993-05-23 - 2019-10-16 (one sitting dated 1988, see caveats) |
|
| 60 |
+
| 1997-2019 | Sejm | interpellations | 304,741 | 1,335,155,122 | terms 3-7 undated (1997-10-20 - 2015-11-11 by term); term 8 2015-11-17 - 2019-04-04 |
|
| 61 |
+
| 1991-2025 | Senat | plenary | 1,375 | 346,591,211 | 1991-11-26 - 2025-04-24 |
|
| 62 |
+
| 2015-2025 | Senat | committee | 4,521 | 143,526,734 | 2015-11-13 - 2025-04-24 |
|
| 63 |
|
| 64 |
+
Interpellation records: 114,126 interpellations (259,034,011 characters), 114,472 replies to
|
| 65 |
+
them (692,623,596), 38,051 questions (65,680,680) and 38,092 replies to questions (317,816,835).
|
| 66 |
+
20,447 distinct speaker labels are kept.
|
|
|
|
| 67 |
|
| 68 |
+
## Collection and normalization
|
| 69 |
|
| 70 |
+
Every step lives in `src/fetch_parliamentary.py`; the shard is reproducible from the pinned dump
|
| 71 |
+
(`--download` fetches it and refuses a zip whose size or SHA-256 differs).
|
| 72 |
|
| 73 |
+
- **Scope**: every term of the dump except `2019-2023/sejm/` and `2023-2027/sejm/` (5,940
|
| 74 |
+
documents), which the `sejm_*` sources cover; the Senate of 2019-2025 is kept. The Sejm part ends
|
| 75 |
+
with the sitting of 2019-10-16; `sejm_api` checks that its own material starts after the end of
|
| 76 |
+
term 8 (`PARLIAMENTARY_SEJM_END` = 2019-11-11 in `src/sejm_api_common.py`).
|
| 77 |
+
- **Records**: one record per sitting document (a sitting day, as the dump splits it) or per
|
| 78 |
+
interpellation, question or reply. A sitting's text is its kept utterances (`<u>`) joined by
|
| 79 |
+
newlines, without speaker labels; a dropped turn leaves no marker. The attribution sidecar lists
|
| 80 |
+
per record the kept speaker labels (`speakers`), `kept_characters` and `dropped_characters`, and
|
| 81 |
+
the header's `system`, `house`, `type`, `term_no` and `date`. An interpellation's text is its
|
| 82 |
+
paragraphs; its header names the author (298,185 records carry an `author`; sittings carry none).
|
| 83 |
+
- **Dates**: `created` is the sitting or letter date. The dump writes 175 sittings over several
|
| 84 |
+
days as one date string ("1938-11-28 i 29", "1952-07-31 i 08-01"); they get the range
|
| 85 |
+
"first, last". The 226,062 interpellation records of terms 3-7 carry no date in the dump and get
|
| 86 |
+
their term's range (e.g. "1997-10-20, 2001-10-18"); the sidecar's `date` keeps the dump's string
|
| 87 |
+
(empty for those).
|
| 88 |
+
- **Speaker allowlist** (sittings only, plenary and committee): every speaker in a sitting's
|
| 89 |
+
header is classified once, by its role followed by a placeholder name ("Jan Maria Kowalski"),
|
| 90 |
+
against the anchored rules `SPEAKER_RULES` of `src/fetch_sejm_committee_transcripts.py` (the
|
| 91 |
+
`sejm_committee_transcripts` allowlist) and then `PPC_RULES` in `src/fetch_parliamentary.py`.
|
| 92 |
+
A turn is kept only if its speaker matches a rule; a speaker no rule recognises is dropped (fail
|
| 93 |
+
closed). A person's own name that is not a 1-3 token name ("Piotr van der Coghen", "Jan Bury s.
|
| 94 |
+
Antoniego", "Artur Płokszto z Litwy") is kept only if it is, or starts with, the name of an MP,
|
| 95 |
+
senator or marshal of the same term zip (the chairs' member check, below; 349 persons kept, 673
|
| 96 |
+
dropped). PPC's removal of party tags sometimes leaves a cut tag as one more surname part ("(niez"; 1,850 persons), which is ignored. PPC strips
|
| 97 |
+
the party tags that the base allowlist keys MPs on, so it matches only 3,804 characters of
|
| 98 |
+
bare `mp` turns; the PPC rules close that gap. Kept, by rule (characters of utterance text,
|
| 99 |
+
turns; `parliamentary.speaker-roles.csv` lists every role with its decision):
|
| 100 |
|
| 101 |
+
| Rule | Keeps | Characters | Turns |
|
| 102 |
+
|---|---|---:|---:|
|
| 103 |
+
| `mp_no_party` | "Poseł/Posłanka NAME", with "Sprawozdawca", "Sekretarz", "Wiceprzewodniczący"; "Sekretarz poseł NAME"; the typo "Poeł" | 1,694,953,227 | 4,477,657 |
|
| 104 |
+
| `state_secretary` | secretaries and undersecretaries of state in a ministry or the Chancellery of the Prime Minister (base rule) | 325,593,817 | 614,984 |
|
| 105 |
+
| `senator` | "Senator NAME" (base rule) | 315,926,447 | 883,499 |
|
| 106 |
+
| `marshal_no_house` | the chamber's own marshal and deputy marshals without "Sejmu"/"Senatu", "Marszałek Senior"; never a voivodeship marshal | 190,540,640 | 2,407,101 |
|
| 107 |
+
| `mp_committee_chair` | committee chairs who are MPs (base rule) | 158,002,628 | 1,038,553 |
|
| 108 |
+
| `government_member` | the Prime Minister, deputy PMs, ministers (base rule) | 87,399,387 | 175,562 |
|
| 109 |
+
| `committee_chair_named` | a committee chair or deputy chair named in the label, only if the name is an MP's, senator's or marshal's of that term (see below) | 46,499,132 | 439,802 |
|
| 110 |
+
| `government_historic` | "Prezydent Ministrów" (1919-21), "Prezes Rady Ministrów", "Wicepremier", ministers under historic names ("Minister Skarbu", "Minister Wyznań Religijnych i Oświecenia Publicznego", "Minister Przemysłu Chemicznego"), "Kierownik Ministerstwa ...", "Minister - Szef Urzędu Rady Ministrów" | 41,519,929 | 78,012 |
|
| 111 |
+
| `state_secretary_historic` | secretaries of state of historic ministries and of the Urząd Rady Ministrów (the Prime Minister's office before KPRM) | 36,177,142 | 72,609 |
|
| 112 |
+
| `constitutional_organ_head` | RPO, RPD, Prezes NIK, NBP, TK, NSA, Pierwszy Prezes SN, KRRiT, KRS, Prokurator Generalny (base rule) | 34,642,977 | 55,742 |
|
| 113 |
+
| `legislative_petitions_staff` | the Sejm's "Przedstawiciel Biura Legislacyjnego", Senate legislators and experts of the Biuro Legislacyjne, petitions staff of the Senate | 32,427,046 | 97,234 |
|
| 114 |
+
| `sejm_legislator` | Biuro Legislacyjne legislators (base rule) | 20,914,344 | 73,630 |
|
| 115 |
+
| `senator_no_party` | "Senator/Senatorka NAME" with "Sekretarz", "Sprawozdawca", "RP" | 10,344,087 | 43,480 |
|
| 116 |
+
| `stage_direction` | the stenographers' bracketed directions ("(Oklaski)", "(Początek posiedzenia o godz. 10)") | 8,281,651 | 471,173 |
|
| 117 |
+
| `mp_surname_1919_1939` | "P. Nowicki" in the Sejm of 1919-39 (not before an office) | 6,505,299 | 12,467 |
|
| 118 |
+
| `sejm_senate_office_head` | heads of the Sejm and Senate offices (base rule) | 5,579,703 | 13,761 |
|
| 119 |
+
| `sejm_bureau_expert` | BAS and BEOS experts (base rule) | 3,373,664 | 5,918 |
|
| 120 |
+
| `sejm_senate_marshal` | "Marszałek Sejmu/Senatu" (base rule) | 2,502,494 | 9,317 |
|
| 121 |
+
| `senator_surname_1919_1939` | "S. Karnicka" in the Senate of 1922-39 | 1,792,371 | 2,567 |
|
| 122 |
+
| `komentarz_continuation` | an unbracketed stenographer's line continuing a kept speaker in the same turn block | 548,873 | 28,611 |
|
| 123 |
+
| `sejm_committee_secretary` | "Sekretarz Komisji ... NAME" (base rule) | 543,439 | 8,392 |
|
| 124 |
+
| `mp` | MP labels with a party tag (base rule) | 3,804 | 13 |
|
| 125 |
+
|
| 126 |
+
Evidence for the PPC rules (also in the code comments and on polish-dynaword-v2#54): "P. X" and
|
| 127 |
+
"S. X" are announced as MPs and senators in the same texts ("Głos ma poseł Nowicki" before "P.
|
| 128 |
+
Nowicki", "Głos ma s. Karnicka"); "P." before an office in 1919-39 is "Pan" and is cut before the
|
| 129 |
+
label is classified (12 persons), and "P." in the Senate (17k characters) stays out. A marshal
|
| 130 |
+
without "Sejmu"/"Senatu" in a sitting of the Sejm or Senate is that chamber's marshal; labels
|
| 131 |
+
naming a voivodeship, sejmik or board are excluded. A chair's name, and any name that is not a 1-3
|
| 132 |
+
token name, is checked against the MPs, senators and marshals of the same term zip (headers of the
|
| 133 |
+
dropped 2019-2023 Sejm included). Case, punctuation, soft hyphens and one-letter tokens are
|
| 134 |
+
ignored, two parts run together are split ("JanuszPalikot"), and a name that starts with a
|
| 135 |
+
member's counts ("Jan Bury s. Antoniego"). A member's name of 4 tokens or with a particle ("Piotr
|
| 136 |
+
van der Coghen") is taken only from the header of a plenary sitting. Chairs who are not members,
|
| 137 |
+
such as a foreign or ministry committee's chair, are dropped (876 persons, 6,691,887 characters).
|
| 138 |
+
The historic ministry words were taken from the label census of the whole dump (2026-10-07).
|
| 139 |
+
|
| 140 |
+
Dropped, by reason (characters of utterance text):
|
| 141 |
+
|
| 142 |
+
| Reason | Characters | What it is |
|
| 143 |
+
|---|---:|---|
|
| 144 |
+
| `speaker:unmatched` | 601,219,281 | a named speaker whose role matches no rule (117,972 persons) |
|
| 145 |
+
| `speaker:no_role` | 84,057,911 | a name without a role in the header (12,222 persons): MP or guest cannot be told |
|
| 146 |
+
| `komentarz_colon` | 24,479,841 | a stenographer's line with ": ", i.e. an interjection ("Głos z sali: ...") |
|
| 147 |
+
| `komentarz_unattributed` | 9,757,058 | an unbracketed stenographer's line with no speaker before it in its turn block |
|
| 148 |
+
| `speaker:role_only_unmatched` | 9,322,256 | a role without a name that matches no rule (8,525 persons) |
|
| 149 |
+
| `inline_speaker` | 8,416,268 | text after a speaker line inside a turn whose label is not kept (see caveats) |
|
| 150 |
+
| `speaker:chair_not_member` | 6,691,887 | a named chair who is not an MP or senator of that term |
|
| 151 |
+
| `speaker:bad_name` | 3,074,332 | a name that is not 1-3 tokens and not a member's (673 persons: ambassadors, witnesses, "Dr NAME, Uniwersytet ...", foreign MPs "Poseł Artur Płokszto z Litwy") |
|
| 152 |
+
| `speaker:free_unmatched` | 1,782,824 | a free-text header label that no rule keeps |
|
| 153 |
+
| `komentarz_continuation_dropped` | 1,548,523 | a stenographer's line continuing a dropped speaker |
|
| 154 |
+
| `inline_label_line` | 352,435 | the speaker lines inside turns themselves |
|
| 155 |
+
|
| 156 |
+
The allowlist keeps 3,024,072,101 of 3,774,774,717 characters of utterance text (80.1%). The
|
| 157 |
+
largest dropped roles: the role-less names above (84.06M), bare "Podsekretarz stanu" (27.39M,
|
| 158 |
+
65,361 turns) and "Sekretarz stanu" (6.70M) without a ministry - the President's Chancellery uses
|
| 159 |
+
the same titles, so they cannot be told apart and fail closed -, "Dyrektor" (16.82M),
|
| 160 |
+
"Wiceminister" (11.80M, 31,147 turns; not in the allowlist), "Prezes" (9.49M), "Wiceprezes NIK"
|
| 161 |
+
(5.32M), "Sprawozdawca" without "poseł" (4.64M), "Ekspert Komisji" (3.07M), candidates for
|
| 162 |
+
ambassador (2.91M), representatives of citizens' legislative initiatives (2.35M), the secretaries
|
| 163 |
+
of state of the President's Chancellery (2.21M) and witnesses of investigative committees
|
| 164 |
+
(0.91M). Also out: the RCL, ministry departments, heads of agencies other than the constitutional
|
| 165 |
+
organs, MEPs and the heads of state ("Naczelnik Państwa", "Prezydent RP").
|
| 166 |
+
- **Stage directions** (the "komentarz" speaker): a bracketed direction is kept; any other
|
| 167 |
+
komentarz line is kept only as the continuation of a kept speaker in the same turn block; a line
|
| 168 |
+
with ": " (an interjection from the floor) is always dropped.
|
| 169 |
+
- **Speaker lines inside turns**: a `<u>` that ends with ":" and reads as a speaker label switches
|
| 170 |
+
the speaker until the next speaker change. Such a label is kept only if it matches a rule other
|
| 171 |
+
than `committee_chair_named` and either names a speaker that the zip's headers keep or puts a
|
| 172 |
+
title ("ob.", "ks.", "gen.") before the name; this guards against roles that swallow words of a
|
| 173 |
+
name ("Minister Spraw Zagranicznych Ukrainy Borys Tarasiuk", "Marszałek Polski Józef
|
| 174 |
+
Piłsudski"). 8,910 such lines: 315 kept by name, 62 by title, 333 refused by the guard, 8,200
|
| 175 |
+
matching no rule.
|
| 176 |
+
- **PII (which scrubber ran)**: the pattern pass `redact()` of
|
| 177 |
+
`src/fetch_sejm_committee_transcripts.py` - e-mail -> `[ADRES_EMAIL]`, checksum-valid PESEL, NIP,
|
| 178 |
+
REGON (9 and 14 digits) and IBAN candidates -> `[DANE_NUMERY]`, labelled phone/fax ->
|
| 179 |
+
`[DANE_KONTAKTOWE]`. Counted in the shipped shard: **12,733 redactions** (6,859
|
| 180 |
+
`[DANE_KONTAKTOWE]`, 5,414 `[ADRES_EMAIL]`, 460 `[DANE_NUMERY]`). This is **not**
|
| 181 |
+
[SlayerLab/NERGAL](https://huggingface.co/SlayerLab/NERGAL): interpellations quote citizens' cases
|
| 182 |
+
by name, so the shard must be re-run through NERGAL before it is admitted to a release.
|
| 183 |
+
- **Short documents**: 440 sittings keep no turn and 164 interpellation records have no text; 37
|
| 184 |
+
sittings and 583 interpellation records have under 200 characters after the filter and the PII
|
| 185 |
+
pass. All are dropped; a dropped sitting's turns stay counted under their rule above.
|
| 186 |
+
- **Dedup**: none within the source or against other sources. This source is the reference set
|
| 187 |
+
that `src/clean_sejm_api_2011_2022.py` deduplicates `sejm_api_2011_2022` against.
|
| 188 |
+
|
| 189 |
+
## Inclusion argument and caveats
|
| 190 |
+
|
| 191 |
+
What this adds: a century of Polish parliamentary language - interwar, PRL and post-1989 plenary
|
| 192 |
+
debate, Sejm committee work since 1965, the Senate since 1922, and 1.34B characters of
|
| 193 |
+
interpellations and ministerial replies. 1.61B tokens.
|
| 194 |
+
|
| 195 |
+
Changes against the shard shipped up to v0.2.5 (SpeakLeash's unlabelled `PPC_corpus`: 324,622
|
| 196 |
+
records / 4,492,746,014 characters / 1,646,835,986 tokens, no authors): rebuilt from IPI PAN's
|
| 197 |
+
labelled dump; guests and other non-official speakers removed from the sittings; 1919-1989 and the
|
| 198 |
+
Senate of 2019-2025 added; the Sejm from 2019 left to the `sejm_*` sources; interpellation authors
|
| 199 |
+
recorded; multi-day and undated records dated.
|
| 200 |
+
|
| 201 |
+
Caveats: the allowlist is the conservative reading of art. 4(2), and it reads the printed role
|
| 202 |
+
label, not the person: a name slot accepts any 1-3 token name, and only committee chairs and longer
|
| 203 |
+
or unusual names are checked against the members of the term. Officials whose name is damaged (OCR "Teresa
|
| 204 |
+
MaIczewska", "Krzysztof Michałkiewicz:", the typo "Piotr Van der Koghen") fail that check: about
|
| 205 |
+
0.13M characters in a hand review of the 0.39M characters of such names whose role a rule keeps.
|
| 206 |
+
Officials the rules miss are dropped with the guests:
|
| 207 |
+
bare "Podsekretarz stanu"/"Sekretarz stanu" (34.09M characters), "Wiceminister" (11.80M) and the
|
| 208 |
+
role-less names (84.06M, possibly including MPs; a member check like the chairs' could recover
|
| 209 |
+
those).
|
| 210 |
+
The speaker-line check inside turns errs towards dropping: on a character-weighted sample of 80
|
| 211 |
+
refused lines (seed 20261007), 47 were guests, 28 were prose or headings ending with a colon (the
|
| 212 |
+
secretary's "Dekrety przedstawione przez Ministerstwo Skarbu:" in 1919, "Koreferat przedstawił
|
| 213 |
+
poseł X (PZPR)") and 5 were officials whose label the rules miss, so about two fifths of the
|
| 214 |
+
8,416,268 characters dropped after such lines is official text lost. A guest's label that does not
|
| 215 |
+
stand alone in its utterance is not detected and stays inside the previous turn (not measured).
|
| 216 |
+
Dates: one term-3 committee sitting (`199701-sjm-nusxx-00004-01`) is dated 1988-07-02 in the dump
|
| 217 |
+
and kept as dated; the 226,062 undated interpellation records carry their term's range, not a day.
|
| 218 |
+
The dump's Sejm interpellations end on 2019-04-04 and the dump has none of term 9, so Sejm
|
| 219 |
+
interpellations from April 2019 to the start of `sejm_interpellations` are in no source.
|
| 220 |
+
Quotations of statutes, prints and citizens' letters are embedded and not filtered (near-dedup
|
| 221 |
+
against `dziennik_ustaw` and a benchmark-overlap check remain targets). PII treatment is
|
| 222 |
+
pattern-based (see above). Not lawyer-signed-off. Training benefit is an untested hypothesis.
|
| 223 |
+
|
| 224 |
+
Limitations: records are sitting documents, not turns; the order of kept turns is preserved, and
|
| 225 |
+
`ppc_path` in `parliamentary.attribution.jsonl` links each record to the TEI document with the full
|
| 226 |
+
sitting. Figures: `parliamentary.stats.json`.
|
data/parliamentary/parliamentary.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:5f21252ee65425a77cdd48bdb964171fb06cd6cf0c59c0b882be995d84dcec7c
|
| 3 |
+
size 1520421405
|
data/parliamentary/parliamentary.speaker-roles.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/parliamentary/parliamentary.stats.json
CHANGED
|
@@ -1,16 +1,158 @@
|
|
| 1 |
{
|
| 2 |
-
"
|
| 3 |
-
"
|
| 4 |
-
"
|
| 5 |
-
"
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
},
|
| 13 |
-
"authors_with_value": 0,
|
| 14 |
"license": "public-domain (official documents)",
|
| 15 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"added": "2026-06-15",
|
| 3 |
+
"authors_with_value": 298185,
|
| 4 |
+
"chars": 4370190797,
|
| 5 |
+
"chars_by_category": {
|
| 6 |
+
"II RP|Sejm|Posiedzenie plenarne": 156362281,
|
| 7 |
+
"II RP|Senat|Posiedzenie plenarne": 43495751,
|
| 8 |
+
"III RP|Sejm|Interpelacja": 259034011,
|
| 9 |
+
"III RP|Sejm|Komisja": 1177690020,
|
| 10 |
+
"III RP|Sejm|Odpowiedź na interpelację": 692623596,
|
| 11 |
+
"III RP|Sejm|Odpowiedź na zapytanie": 317816835,
|
| 12 |
+
"III RP|Sejm|Posiedzenie plenarne": 937187974,
|
| 13 |
+
"III RP|Sejm|Uroczyste Spotkanie": 12071,
|
| 14 |
+
"III RP|Sejm|Uroczyste zgromadzenie posłów i senatorów": 8185,
|
| 15 |
+
"III RP|Sejm|Wspólne posiedzenie Sejmu i Senatu": 28091,
|
| 16 |
+
"III RP|Sejm|Zapytanie": 65680680,
|
| 17 |
+
"III RP|Sejm|Zgromadzenie Narodowe": 3480455,
|
| 18 |
+
"III RP|Sejm|Zgromadzenie posłów i senatorów": 61564,
|
| 19 |
+
"III RP|Senat|Komisja": 143526734,
|
| 20 |
+
"III RP|Senat|Posiedzenie plenarne": 346591211,
|
| 21 |
+
"PRL/III RP|Sejm|Posiedzenie plenarne": 33058418,
|
| 22 |
+
"PRL/III RP|Senat|Posiedzenie plenarne": 17650518,
|
| 23 |
+
"PRL|Krajowa Rada Narodowa|Posiedzenie Plenarne": 1093152,
|
| 24 |
+
"PRL|Sejm|Komisja": 62299011,
|
| 25 |
+
"PRL|Sejm|Posiedzenie plenarne": 112036227,
|
| 26 |
+
"PRL|Senat|Posiedzenie plenarne": 454012
|
| 27 |
+
},
|
| 28 |
+
"created_max": "2025-04-24",
|
| 29 |
+
"created_max_by_house": {
|
| 30 |
+
"Krajowa Rada Narodowa": "1946-09-23",
|
| 31 |
+
"Sejm": "2019-10-16",
|
| 32 |
+
"Senat": "2025-04-24"
|
| 33 |
+
},
|
| 34 |
+
"created_min": "1919-02-10",
|
| 35 |
+
"created_min_by_house": {
|
| 36 |
+
"Krajowa Rada Narodowa": "1944-12-31",
|
| 37 |
+
"Sejm": "1919-02-10",
|
| 38 |
+
"Senat": "1922-11-28"
|
| 39 |
+
},
|
| 40 |
+
"date_max_by_house": {
|
| 41 |
+
"Krajowa Rada Narodowa": "1946-09-23",
|
| 42 |
+
"Sejm": "2019-10-16",
|
| 43 |
+
"Senat": "2025-04-24"
|
| 44 |
+
},
|
| 45 |
+
"date_min_by_house": {
|
| 46 |
+
"Krajowa Rada Narodowa": "1944-12-31",
|
| 47 |
+
"Sejm": "1919-02-10",
|
| 48 |
+
"Senat": "1922-11-28"
|
| 49 |
+
},
|
| 50 |
+
"docs_by_category": {
|
| 51 |
+
"II RP|Sejm|Posiedzenie plenarne": 1021,
|
| 52 |
+
"II RP|Senat|Posiedzenie plenarne": 323,
|
| 53 |
+
"III RP|Sejm|Interpelacja": 114126,
|
| 54 |
+
"III RP|Sejm|Komisja": 31362,
|
| 55 |
+
"III RP|Sejm|Odpowiedź na interpelację": 114472,
|
| 56 |
+
"III RP|Sejm|Odpowiedź na zapytanie": 38092,
|
| 57 |
+
"III RP|Sejm|Posiedzenie plenarne": 2070,
|
| 58 |
+
"III RP|Sejm|Uroczyste Spotkanie": 1,
|
| 59 |
+
"III RP|Sejm|Uroczyste zgromadzenie posłów i senatorów": 3,
|
| 60 |
+
"III RP|Sejm|Wspólne posiedzenie Sejmu i Senatu": 3,
|
| 61 |
+
"III RP|Sejm|Zapytanie": 38051,
|
| 62 |
+
"III RP|Sejm|Zgromadzenie Narodowe": 25,
|
| 63 |
+
"III RP|Sejm|Zgromadzenie posłów i senatorów": 8,
|
| 64 |
+
"III RP|Senat|Komisja": 4521,
|
| 65 |
+
"III RP|Senat|Posiedzenie plenarne": 1375,
|
| 66 |
+
"PRL/III RP|Sejm|Posiedzenie plenarne": 61,
|
| 67 |
+
"PRL/III RP|Senat|Posiedzenie plenarne": 60,
|
| 68 |
+
"PRL|Krajowa Rada Narodowa|Posiedzenie Plenarne": 6,
|
| 69 |
+
"PRL|Sejm|Komisja": 2433,
|
| 70 |
+
"PRL|Sejm|Posiedzenie plenarne": 461,
|
| 71 |
+
"PRL|Senat|Posiedzenie plenarne": 1
|
| 72 |
+
},
|
| 73 |
+
"drop_prefixes": [
|
| 74 |
+
"2019-2023/sejm/",
|
| 75 |
+
"2023-2027/sejm/"
|
| 76 |
+
],
|
| 77 |
+
"dropped_chars": {
|
| 78 |
+
"inline_label_line": 352435,
|
| 79 |
+
"inline_speaker": 8416268,
|
| 80 |
+
"komentarz_colon": 24479841,
|
| 81 |
+
"komentarz_continuation_dropped": 1548523,
|
| 82 |
+
"komentarz_unattributed": 9757058,
|
| 83 |
+
"speaker:bad_name": 3074332,
|
| 84 |
+
"speaker:chair_not_member": 6691887,
|
| 85 |
+
"speaker:free_unmatched": 1782824,
|
| 86 |
+
"speaker:no_role": 84057911,
|
| 87 |
+
"speaker:role_only_unmatched": 9322256,
|
| 88 |
+
"speaker:unmatched": 601219281
|
| 89 |
+
},
|
| 90 |
+
"dropped_docs": {
|
| 91 |
+
"empty_interpellation": 164,
|
| 92 |
+
"empty_sitting": 440,
|
| 93 |
+
"prefix_sejm_2019_2027": 5940,
|
| 94 |
+
"short_interpellation": 583,
|
| 95 |
+
"short_sitting": 37
|
| 96 |
+
},
|
| 97 |
+
"dump": "2025-05-21",
|
| 98 |
+
"inline_labels": {
|
| 99 |
+
"free": 315,
|
| 100 |
+
"free_guard": 333,
|
| 101 |
+
"free_titled": 62,
|
| 102 |
+
"free_unmatched": 8200
|
| 103 |
+
},
|
| 104 |
+
"kept": 348475,
|
| 105 |
+
"kept_chars_by_rule": {
|
| 106 |
+
"committee_chair_named": 46499132,
|
| 107 |
+
"constitutional_organ_head": 34642977,
|
| 108 |
+
"government_historic": 41519929,
|
| 109 |
+
"government_member": 87399387,
|
| 110 |
+
"komentarz_continuation": 548873,
|
| 111 |
+
"legislative_petitions_staff": 32427046,
|
| 112 |
+
"marshal_no_house": 190540640,
|
| 113 |
+
"mp": 3804,
|
| 114 |
+
"mp_committee_chair": 158002628,
|
| 115 |
+
"mp_no_party": 1694953227,
|
| 116 |
+
"mp_surname_1919_1939": 6505299,
|
| 117 |
+
"sejm_bureau_expert": 3373664,
|
| 118 |
+
"sejm_committee_secretary": 543439,
|
| 119 |
+
"sejm_legislator": 20914344,
|
| 120 |
+
"sejm_senate_marshal": 2502494,
|
| 121 |
+
"sejm_senate_office_head": 5579703,
|
| 122 |
+
"senator": 315926447,
|
| 123 |
+
"senator_no_party": 10344087,
|
| 124 |
+
"senator_surname_1919_1939": 1792371,
|
| 125 |
+
"stage_direction": 8281651,
|
| 126 |
+
"state_secretary": 325593817,
|
| 127 |
+
"state_secretary_historic": 36177142
|
| 128 |
+
},
|
| 129 |
+
"komentarz": {
|
| 130 |
+
"komentarz_colon": 24479841,
|
| 131 |
+
"komentarz_continuation": 548873,
|
| 132 |
+
"komentarz_continuation_dropped": 1548523,
|
| 133 |
+
"komentarz_unattributed": 9757058,
|
| 134 |
+
"stage_direction": 8281651
|
| 135 |
},
|
|
|
|
| 136 |
"license": "public-domain (official documents)",
|
| 137 |
+
"licenses": {
|
| 138 |
+
"public-domain (official documents)": 348475
|
| 139 |
+
},
|
| 140 |
+
"persons": {
|
| 141 |
+
"bad_name": 673,
|
| 142 |
+
"bad_name_member": 349,
|
| 143 |
+
"chair_not_member": 876,
|
| 144 |
+
"commentary": 44211,
|
| 145 |
+
"free_titled": 191,
|
| 146 |
+
"free_unmatched": 351,
|
| 147 |
+
"no_role": 12222,
|
| 148 |
+
"role_only": 5836,
|
| 149 |
+
"role_only_unmatched": 8525,
|
| 150 |
+
"structured": 598820,
|
| 151 |
+
"unmatched": 117972
|
| 152 |
+
},
|
| 153 |
+
"persons_p2_fallback": 3127,
|
| 154 |
+
"persons_p_strip": 12,
|
| 155 |
+
"redactions": 12733,
|
| 156 |
+
"sejm_coverage_end": "2019-11-11",
|
| 157 |
+
"tokens": 1606998487
|
| 158 |
}
|
data/sejm_api/sejm_api.md
CHANGED
|
@@ -42,7 +42,8 @@ source. No unverified upstream Creative Commons license is asserted.
|
|
| 42 |
|
| 43 |
## Temporal novelty and deduplication
|
| 44 |
|
| 45 |
-
`parliamentary` ends
|
|
|
|
| 46 |
record is dated on or after `2023-01-01`, so its date range does not overlap it.
|
| 47 |
Exact duplicate speech texts within the contribution are removed using
|
| 48 |
SHA-1 fingerprints; this is not a claim of global cross-domain near-deduplication.
|
|
|
|
| 42 |
|
| 43 |
## Temporal novelty and deduplication
|
| 44 |
|
| 45 |
+
The Sejm material of `parliamentary` ends with term 8 (`2019-11-11`; its
|
| 46 |
+
Senate material is not compared: this source is Sejm-only). Every contributed
|
| 47 |
record is dated on or after `2023-01-01`, so its date range does not overlap it.
|
| 48 |
Exact duplicate speech texts within the contribution are removed using
|
| 49 |
SHA-1 fingerprints; this is not a claim of global cross-domain near-deduplication.
|
data/sejm_committee_transcripts/sejm_committee_transcripts.md
CHANGED
|
@@ -32,9 +32,9 @@ heads of constitutional organs, Sejm and Senate staff; see "Speaker allowlist"):
|
|
| 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:
|
| 36 |
-
committee working register
|
| 37 |
-
|
| 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).
|
|
|
|
| 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: the
|
| 36 |
+
committee working register of terms 9-10, which neither `parliamentary` (Sejm
|
| 37 |
+
committees up to term 8) nor the plenary-only `sejm_api` contains. 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).
|
data/sejm_interpellations/sejm_interpellations.md
CHANGED
|
@@ -77,10 +77,10 @@ diacritic ratio, exact sha1).
|
|
| 77 |
|
| 78 |
## Why include it
|
| 79 |
|
| 80 |
-
The corpus already has spoken Sejm (`parliamentary`, `sejm_api`)
|
|
|
|
| 81 |
the written Q&A register for the current term: longer, formal, ministry-voiced
|
| 82 |
-
replies that do not appear in the speech shards
|
| 83 |
-
question/answer pair is a document type the corpus otherwise lacks entirely.
|
| 84 |
Caveats for downstream users: single term (10th, 2023-11-15 – 2026-09-03), and
|
| 85 |
interpellations quote constituency casework that can name private citizens (see
|
| 86 |
Privacy below — a NERGAL pass is a release gate).
|
|
|
|
| 77 |
|
| 78 |
## Why include it
|
| 79 |
|
| 80 |
+
The corpus already has spoken Sejm (`parliamentary`, `sejm_api`) and the
|
| 81 |
+
interpellations of terms 3-8 (in `parliamentary`, up to 2019-04-04). This adds
|
| 82 |
the written Q&A register for the current term: longer, formal, ministry-voiced
|
| 83 |
+
replies that do not appear in the speech shards.
|
|
|
|
| 84 |
Caveats for downstream users: single term (10th, 2023-11-15 – 2026-09-03), and
|
| 85 |
interpellations quote constituency casework that can name private citizens (see
|
| 86 |
Privacy below — a NERGAL pass is a release gate).
|
src/clean_sejm_committee_transcripts.py
CHANGED
|
@@ -116,12 +116,17 @@ def role_of(label: str, given: set[str]) -> str:
|
|
| 116 |
return " ".join(tokens[:cut]) + suffix
|
| 117 |
|
| 118 |
|
| 119 |
-
def roles_table(label_stats: dict
|
| 120 |
-
"""CSV rows from {
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
groups: dict[tuple[str, str, str], list[int]] = defaultdict(lambda: [0, 0, 0])
|
| 123 |
-
for
|
| 124 |
-
group = groups[(
|
| 125 |
group[0] += turns
|
| 126 |
group[1] += characters
|
| 127 |
group[2] += 1
|
|
|
|
| 116 |
return " ".join(tokens[:cut]) + suffix
|
| 117 |
|
| 118 |
|
| 119 |
+
def roles_table(label_stats: dict, roles: dict | None = None) -> list[list]:
|
| 120 |
+
"""CSV rows from {key: (turns, characters, rule or None)}, biggest first.
|
| 121 |
+
|
| 122 |
+
`roles` maps each key to its role; without it the keys are speaker labels and the role is the
|
| 123 |
+
label without the person's name (role_of)."""
|
| 124 |
+
if roles is None:
|
| 125 |
+
given = given_names(label_stats)
|
| 126 |
+
roles = {label: role_of(label, given) for label in label_stats}
|
| 127 |
groups: dict[tuple[str, str, str], list[int]] = defaultdict(lambda: [0, 0, 0])
|
| 128 |
+
for key, (turns, characters, rule) in label_stats.items():
|
| 129 |
+
group = groups[(roles[key], "include" if rule else "exclude", rule or "")]
|
| 130 |
group[0] += turns
|
| 131 |
group[1] += characters
|
| 132 |
group[2] += 1
|
src/fetch_parliamentary.py
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""parliamentary: the Polish Parliamentary Corpus (PPC) rebuilt from IPI PAN's speaker-labelled TEI dump.
|
| 2 |
+
|
| 3 |
+
Upstream: the per-term TEI zips that the PPC page (https://clip.ipipan.waw.pl/PPC) links, dump of 2025-05-21
|
| 4 |
+
(https://kdp.ipipan.waw.pl/static/ppcdump-tei/<term>-tei.zip), pinned below by size and SHA-256. It replaces
|
| 5 |
+
the earlier unlabelled copy of PPC taken from SpeakLeash (`PPC_corpus`), whose committee transcripts mixed
|
| 6 |
+
guests' statements with the official speakers' (polish-dynaword-v2#54, option C).
|
| 7 |
+
|
| 8 |
+
Scope (polish-dynaword-v2#54, decided 2026-10-07: "1A / 2A but document / 3 A / 4A / 5 A"):
|
| 9 |
+
- 1A: every term of the dump, 1919-2025, except the Sejm of 2019-2023 and 2023-2027 (DROP_PREFIXES), which
|
| 10 |
+
sejm_api, sejm_committee_transcripts and sejm_interpellations cover. Kept: the Sejm and Senate of the
|
| 11 |
+
Second Republic, the Krajowa Rada Narodowa and the Sejm of the PRL, the Sejm and Senate since 1989 and the
|
| 12 |
+
Senate of 2019-2025.
|
| 13 |
+
- 2A: in sittings (plenary and committee) only turns by MPs and senators, members of the government, heads
|
| 14 |
+
of constitutional organs and Sejm/Senate staff are kept: the sejm_committee_transcripts allowlist
|
| 15 |
+
(classify_speaker) plus PPC_RULES below, each with its evidence. Everything else is dropped, among it
|
| 16 |
+
committee guests, witnesses of investigative committees, the President's Chancellery (KPRP), heads of
|
| 17 |
+
agencies other than the constitutional organs, the Government Legislation Centre (RCL), ministry
|
| 18 |
+
departments and the heads of state ("Naczelnik Państwa", "Prezydent RP").
|
| 19 |
+
- 3A: the allowlist applies to plenary sittings too.
|
| 20 |
+
- 4A: interpellations, questions and the government's replies are kept whole (no speaker filter).
|
| 21 |
+
- 5A: this source stays the dedup reference of sejm_api_2011_2022 (clean_sejm_api_2011_2022.py re-pins it).
|
| 22 |
+
|
| 23 |
+
Speakers. A sitting's header lists its speakers (<person>): role (roleName), forenames and surnames. PPC
|
| 24 |
+
strips the party tags that the base allowlist keys MPs on, so a person is classified by role + a placeholder
|
| 25 |
+
name ("Jan Maria Kowalski"), never by its own name: a role that swallows words of a name ("Minister Spraw
|
| 26 |
+
Zagranicznych Ukrainy" + a name) then fails because the placeholder no longer fits a 2-3 token name. The
|
| 27 |
+
person's own name that is not a 1-3 token name ("bad_name": "Piotr Van der Coghen", "Jan Bury s. Antoniego",
|
| 28 |
+
"Artur Płokszto z Litwy") is kept only if it is, or starts with, the name of an MP, senator or marshal of the
|
| 29 |
+
same zip (is_member, the check a named committee chair gets). Labels that are free text (persName
|
| 30 |
+
without parts, and speaker lines inside a turn, "Poseł Kowalski:") are classified as they stand but kept
|
| 31 |
+
only when the name closing them belongs to a speaker the header keeps in the same zip (absorption guard).
|
| 32 |
+
|
| 33 |
+
Stage directions (the "komentarz" speaker): a bracketed direction ("(Oklaski)") is kept; any other
|
| 34 |
+
komentarz turn is kept only as the continuation of a kept speaker in the same turn block; a komentarz that
|
| 35 |
+
contains ": " (an interjection "Głos z sali: ...") is always dropped.
|
| 36 |
+
|
| 37 |
+
Usage: python3 src/fetch_parliamentary.py [--dump DIR] [--out DIR] [--download] [--workers N]
|
| 38 |
+
"""
|
| 39 |
+
from __future__ import annotations
|
| 40 |
+
|
| 41 |
+
import argparse
|
| 42 |
+
import datetime
|
| 43 |
+
import functools
|
| 44 |
+
import json
|
| 45 |
+
import os
|
| 46 |
+
import re
|
| 47 |
+
import shutil
|
| 48 |
+
import sys
|
| 49 |
+
import unicodedata
|
| 50 |
+
import urllib.request
|
| 51 |
+
import xml.etree.ElementTree as ET
|
| 52 |
+
import zipfile
|
| 53 |
+
from collections import Counter, defaultdict
|
| 54 |
+
from concurrent.futures import ProcessPoolExecutor
|
| 55 |
+
from pathlib import Path
|
| 56 |
+
|
| 57 |
+
from clean_sejm_committee_transcripts import role_of, roles_table, write_roles
|
| 58 |
+
from fetch_sejm_committee_transcripts import (
|
| 59 |
+
_GOVERNMENT_BODY, _MINISTRY_ABBREVIATION, _MINISTRY_WORDS, _NAME, _NOT_STATE_SECRETARY,
|
| 60 |
+
_LO, _OFFICE_WORD, _STATE_OFFICE, _STATE_PREFIX, _STATE_RANK, _STATE_SECRETARY_WORDS, _TOK, _UP, FIELDS, LICENSE,
|
| 61 |
+
classify_speaker, count_tokens, is_label, redact,
|
| 62 |
+
)
|
| 63 |
+
from sejm_api_common import MIN_CHARS, PARLIAMENTARY_SEJM_END, sha256_file, write_json
|
| 64 |
+
|
| 65 |
+
SOURCE = "parliamentary"
|
| 66 |
+
ADDED = "2026-06-15"
|
| 67 |
+
DUMP_URL = "https://kdp.ipipan.waw.pl/static/ppcdump-tei/{term}-tei.zip"
|
| 68 |
+
# (term, bytes, sha256) of the 2025-05-21 dump, as downloaded on 2026-10-07.
|
| 69 |
+
MANIFEST = (
|
| 70 |
+
("1919-1922", 218013940, "6be0273eccd20989add49e1ca106c5724b64c89c38f9a20f92e97c0dfca1011e"),
|
| 71 |
+
("1922-1927", 333034736, "2fcfa873fb45e5f6647889f6fe7417990b3aab6824ebc839f22699a139a15fa0"),
|
| 72 |
+
("1928-1930", 107456995, "2816f20b487636e2a879298dfa2fe15d7226641ed8a7f5df3d93fd09985bf9b6"),
|
| 73 |
+
("1930-1935", 200928182, "be98a5636958b01be0a0197a6905e812045a282889378b3541839dbfeb1e025f"),
|
| 74 |
+
("1935-1938", 126925493, "ce3440542eb757e7decf43e16d8a3f0266ee329f35df28bd180867b936de5f94"),
|
| 75 |
+
("1938-1939", 29077576, "d3d115b3298b43d5df405bb8a3ab39ef247c2806af27289f857d71695d9711d6"),
|
| 76 |
+
("1943-1947", 575193, "e15f69b186107cd545ad6f1b099fec89a0993a504f02a275b297da9bcf59ba80"),
|
| 77 |
+
("1947-1952", 75320036, "0d9f1d60cdf8e6f425f6b5f86d655eb1ca9a5ec935cc6e51696d74ae5506aced"),
|
| 78 |
+
("1952-1956", 32602235, "8e5c0be0092bb94b57f8e6fb51ad2b88f434d28f0619b7b55a308b4f587b0730"),
|
| 79 |
+
("1957-1961", 76796260, "be2297b8de8ba5f95b7ed88172b3123bcf81d07c4f8611d1f334ba309e01ded3"),
|
| 80 |
+
("1961-1965", 39972140, "839599ae0ca23ccebd142a94ddaf41b047e29dc86d7606cc56b094c61775646b"),
|
| 81 |
+
("1965-1969", 60609250, "ce81e6ed59e4f1a6b67feab64230ed9d29e795a5e5000dd73181505d93074360"),
|
| 82 |
+
("1969-1972", 16901879, "18c6eddef1941d859b16b7e2ad72383e23953ee571a593a19610d01c657206cd"),
|
| 83 |
+
("1972-1976", 70960374, "f6d2ba032f47db38cb5ac8ccf8c72299ea43543f52fe70f9e8102fedf103ed4c"),
|
| 84 |
+
("1976-1980", 82719414, "2ccd2cc4e4b8bdc627c393419244988f0842c03523e1c4b8ce85f59aeb414f7d"),
|
| 85 |
+
("1980-1985", 305014407, "ec844f2968fb091ccbb1efaf9cc2730900b37aad4208e16876fe785926cd103b"),
|
| 86 |
+
("1985-1989", 283699561, "94eb7a73f0e688582001d0687e4aeaa87f0d55258715caba07b570a02c431ff6"),
|
| 87 |
+
("1989-1991", 322944949, "16aadc2ef1813d1a695049571da3c5af540655e2a82698f955fe382846d4cbbf"),
|
| 88 |
+
("1991-1993", 290833981, "1ceebebde162dcc7e26994de8420518809d67c33cd92220a4fb01ef703f00c7d"),
|
| 89 |
+
("1993-1997", 2083076422, "e7cd0805b1c2156de66335af389e59d72d728ba59eceeb331168ea162c654ad3"),
|
| 90 |
+
("1997-2001", 2596857801, "d9f71ce6899cf29746abceef0c8f4eb990c36e1a59c7c4677c131a65fede7cd9"),
|
| 91 |
+
("2001-2005", 3029260742, "6a4e409c7173b1f607dec87c932f69a2f6a254cc4fb28905de09f9b26c30b9b9"),
|
| 92 |
+
("2005-2007", 1504583970, "eb0670e07302b03417073fddc2b7d6f253d646f7f05b8d4c0a044837d42950ea"),
|
| 93 |
+
("2007-2011", 3613775393, "239a2d617440d9a1b47dc6d26c53d80d6399579bebb688887406e4ff31f62c92"),
|
| 94 |
+
("2011-2015", 4119031719, "7b0f823562137e4d07dbaa3ef7ff1519f6f36d79350a5e319aef64ae3dcabccf"),
|
| 95 |
+
("2015-2019", 3909365702, "79ef4c1845c37c3c08d569daf8066ba6b130d9ad6f7d1000db5a937fdfbfe5e6"),
|
| 96 |
+
("2019-2023", 2086326237, "21d987b939728c08fa9d08df37fb3851f321b49b5da0102c59ef5e7eb2629932"),
|
| 97 |
+
("2023-2027", 792882488, "61716f169d4378b158a54fb3f6c93c4ee69b876fab04811807d16bd0c435578c"),
|
| 98 |
+
)
|
| 99 |
+
DROP_PREFIXES = ("2019-2023/sejm/", "2023-2027/sejm/") # 1A: the sejm_* sources cover the Sejm from term 9
|
| 100 |
+
# Interpellations of terms 3-7 carry no date: `created` is the term (Sejm terms, first to last day).
|
| 101 |
+
UNDATED_TERM_RANGES = {
|
| 102 |
+
"3": "1997-10-20, 2001-10-18", "4": "2001-10-19, 2005-10-18", "5": "2005-10-19, 2007-11-04",
|
| 103 |
+
"6": "2007-11-05, 2011-11-07", "7": "2011-11-08, 2015-11-11",
|
| 104 |
+
}
|
| 105 |
+
T = "{http://www.tei-c.org/ns/1.0}"
|
| 106 |
+
XID = "{http://www.w3.org/XML/1998/namespace}id"
|
| 107 |
+
PLACEHOLDER = " Jan Maria Kowalski" # P3: role + a 3-token name stands in for the person's own name
|
| 108 |
+
PLACEHOLDER_2 = " Jan Kowalski" # P2: only for committee secretaries, whose rule takes exactly two tokens
|
| 109 |
+
COMMENTARY = "komentarz"
|
| 110 |
+
REDACTION_TAGS = re.compile(r"\[(?:ADRES_EMAIL|DANE_NUMERY|DANE_KONTAKTOWE)\]")
|
| 111 |
+
_DATE_PART = re.compile(r"(?:(\d{4})-)?(?:(\d{2})-)?(\d{2})")
|
| 112 |
+
|
| 113 |
+
# ------------------------------------------------------------------ PPC rules (2A)
|
| 114 |
+
# Chars below are the census of the whole dump (2026-10-07, utterance text of the label, all terms).
|
| 115 |
+
# Historic ministry words ("Minister Skarbu", "Minister Wyznań Religijnych i Oświecenia Publicznego",
|
| 116 |
+
# "Minister Przemysłu Chemicznego") and "RP" ("Minister Finansów RP") on top of the base list.
|
| 117 |
+
_PPC_MINISTRY_WORDS = _MINISTRY_WORDS + "|" + "|".join((
|
| 118 |
+
"RP skarbu państwa transportu opieki budownictwa przekształceń własnościowych ochrony zasobów naturalnych "
|
| 119 |
+
"przestrzennej gospodarczej współpracy zagranicą handlu wewnętrznego usług inwestycji łączności "
|
| 120 |
+
"regionalnego wyznań religijnych oświecenia publicznego reform rolnych żywnościowej oświaty wychowania "
|
| 121 |
+
"komunikacji wojskowych sztuki płac socjalnych chemicznego lekkiego hutnictwa terenowej poczt telegrafów "
|
| 122 |
+
"socjalnej rynku energetyki zagranicznego spożywczego skupu materiałów budowlanych górnictwa maszynowego "
|
| 123 |
+
"robót publicznych aprowizacji techniki kombatantów mieszkalnictwa pomocy postępu naukowo-technicznego "
|
| 124 |
+
"ciężkiego węglowego leśnictwa komunalnej").split())
|
| 125 |
+
# Titles that may stand before a name ("Poseł ks. Kowalski", "Minister gen. Sikorski", "Poseł p. Kowalski").
|
| 126 |
+
_HON = r"(?: (?:ks\.?|gen\.|dr\.?|p\.|ob\.|prof\.|inż\.|mgr))*"
|
| 127 |
+
_PERSON = rf",?{_HON} (?:{_NAME}|{_TOK})"
|
| 128 |
+
# A free label whose name follows a title ("Poseł ob. Ochab", "Prezes Rady Ministrów ob. Osóbka-Morawski"): the
|
| 129 |
+
# title marks where the name starts, so the role before it can take the placeholder like a header person's.
|
| 130 |
+
# The Krajowa Rada Narodowa (1943-47) has only such labels, no structured persons for the name guard.
|
| 131 |
+
_TITLED = re.compile(rf"(?P<role>.+ (?:ks\.?|gen\.|dr\.?|p\.|ob\.|prof\.|inż\.|mgr)) (?P<name>{_NAME}|{_TOK})") # a full name or a lone surname, optionally after a comma
|
| 132 |
+
_MINISTER = rf"Minist(?:er|ra)(?:[ ,–-]+(?i:{_PPC_MINISTRY_WORDS}))*"
|
| 133 |
+
_PREMIER = r"(?:Wice)?[Pp]rezes (?:Rady Ministrów|RM)|Prezydent Ministrów|Wicepremier"
|
| 134 |
+
# No marker of the President's Chancellery, of local government or of other bodies sharing a word.
|
| 135 |
+
_NOT_SURNAME_ONLY = (r"(?!.*(?:Minist|Prezes|Premier|Wicepremier|Marsza|Sekretarz|Podsekretarz|Poseł|Senator"
|
| 136 |
+
r"|[Rr]eferent|Przewodnicz|Sprawozd|Kierown|Dyrekt|Genera|Prokur))")
|
| 137 |
+
_SENATE_UNIT = (r"(?:Biurze Legislacyjnym|Dziale Petycji i Korespondencji w Biurze "
|
| 138 |
+
r"(?:Analiz, Dokumentacji i Korespondencji|Analiz i Petycji|Komunikacji Społecznej))")
|
| 139 |
+
_SENATE_STAFF = (r"(?:Główn[ya] |Starsz[ya] )?(?:Legislator(?:ka)?|Ekspert(?:ka)?(?: do [Ss]praw "
|
| 140 |
+
r"(?:Legislacji|Oceny Skutków Regulacji))?|[Ss]pecjalist(?:a|ka)) w " + _SENATE_UNIT)
|
| 141 |
+
_PPC_STATE_BODY = (rf"(?:[ ,–-]+(?:(?i:{_STATE_SECRETARY_WORDS}|{_PPC_MINISTRY_WORDS}|urzędzie|urzędu)"
|
| 142 |
+
rf"|{_MINISTRY_ABBREVIATION}|URM))*")
|
| 143 |
+
_CHAIR_OF = r"(?: (?:Komisji|Podkomisji)(?: [^\W\d_]+,?){0,12})?"
|
| 144 |
+
# The base deputy chair with a capital "Przewodniczącego" too (Senate committees 2015-2023, 2.89M chars).
|
| 145 |
+
_PPC_CHAIR_DEPUTY = r"(?:(?:[Pp]ierwsz[ya]|[Dd]rug[ia]) )?[Zz]astęp(?:ca|czyni) [Pp]rzewodnicząc(?:ego|ej)"
|
| 146 |
+
|
| 147 |
+
# (rule id, pattern matched with fullmatch, (system, house) the rule is limited to; None = any). After the
|
| 148 |
+
# base allowlist; first match wins.
|
| 149 |
+
PPC_RULES = [
|
| 150 |
+
# MPs without a party tag (PPC drops it): "Poseł Jan Kowalski", "Poseł Sprawozdawca Jan Kowalski",
|
| 151 |
+
# "Posłanka Wiceprzewodnicząca Anna Nowak", "Sekretarz poseł Jan Kowalski", "Sprawozdawca p. Kowalski",
|
| 152 |
+
# "Przewodniczący poseł ob. Szwalbe" (KRN, 32.6k chars), "Sekretarz Poseł Jan Kowalski" (1993-2019, 1.97M),
|
| 153 |
+
# the typo "Poeł Jan Kowalski" (707k).
|
| 154 |
+
# A "Poseł" label is an MP's by its own words; in 1919-39 often surname-only ("Poseł Nowicki").
|
| 155 |
+
("mp_no_party", re.compile(
|
| 156 |
+
rf"(?:[Pp]oseł|[Pp]osłanka|Poeł)(?: (?:[Ss]prawozdawca|[Ww]nioskodawca|[Ss]ekretarz|(?:[Ww]ice)?[Pp]rzewodnicząc[ya]))?{_PERSON}"
|
| 157 |
+
rf"|(?:Sekretarz|Sprawozdawca|(?:[Ww]ice)?[Pp]rzewodnicząc[ya])(?: [Pp]oseł| [Pp]osłanka| p\.){_PERSON}"), (None, None)),
|
| 158 |
+
# The Sejm of 1919-39 prints MPs as "P. Nowicki" (6.77M chars). Checked: the plenary text announces the
|
| 159 |
+
# same people as MPs ("Głos ma poseł Nowicki" before "P. Nowicki"). Not when the label names an office.
|
| 160 |
+
("mp_surname_1919_1939", re.compile(rf"P\.{_HON} {_NOT_SURNAME_ONLY}(?:{_NAME}|{_TOK})"), ("II RP", "Sejm")),
|
| 161 |
+
("senator_no_party", re.compile(
|
| 162 |
+
rf"(?:Senator|Senatorka)(?: (?:[Ss]ekretarz|[Ss]prawozdawca|RP))?{_PERSON}"), (None, None)),
|
| 163 |
+
# The Senate of 1922-39 prints senators as "S. Karnicka" (1.51M chars), announced as "Głos ma s. Karnicka".
|
| 164 |
+
# ("P." in the Senate, 17k chars, is "Pan" and stays out.)
|
| 165 |
+
("senator_surname_1919_1939", re.compile(rf"S\.{_HON} {_NOT_SURNAME_ONLY}(?:{_NAME}|{_TOK})"), ("II RP", "Senat")),
|
| 166 |
+
# The chamber's own marshals without "Sejmu"/"Senatu" ("Marszałek", "Wicemarszałek Jan Kowalski",
|
| 167 |
+
# "Marszałek Senior", the 1919 typo "Marszalek poseł Ferdynand Radziwiłł"), never a voivodeship marshal.
|
| 168 |
+
("marshal_no_house", re.compile(
|
| 169 |
+
r"(?!.*(?i:wojew|sejmik|zarząd|SSWW))(?:Wicemarszałkini|(?:Wice)?[Mm]arsza[łl]ek)(?:[- ][Ss]enior)?"
|
| 170 |
+
r"(?: (?:Sejmu|Senatu)(?: (?:RP|Rzeczypospolitej Polskiej|Ustawodawczego|PRL))?)?(?: poseł)?,?"
|
| 171 |
+
rf"{_HON}(?: (?:{_NAME}|{_TOK}))?"), (None, None)),
|
| 172 |
+
# Members of the government before 1989 and since, under their historic titles: "Prezes Rady Ministrów,
|
| 173 |
+
# Minister Spraw Wewnętrznych Jan Kowalski", "Prezydent Ministrów" (1919-21), "Wicepremier", "Kierownik
|
| 174 |
+
# Ministerstwa Skarbu", "Minister - Szef Urzędu Rady Ministrów", "Minister - Członek Rady Ministrów".
|
| 175 |
+
("government_historic", re.compile(
|
| 176 |
+
rf"(?:{_PREMIER})(?:,? (?:i )?{_MINISTER})?{_PERSON}|{_MINISTER}{_PERSON}"
|
| 177 |
+
rf"|Kierownik Ministerstwa(?:[ ,–-]+(?i:{_PPC_MINISTRY_WORDS}))+{_PERSON}"
|
| 178 |
+
rf"|Minist(?:er|ra) ?[—–-] ?(?:[Ss]zef Urzędu Rady Ministrów|Kierownik|Członek Rady Ministrów)(?: {_OFFICE_WORD}){{0,14}}{_PERSON}"
|
| 179 |
+
rf"|Szef Urzędu Rady Ministrów{_PERSON}"), (None, None)),
|
| 180 |
+
# Secretaries/undersecretaries of state as in the base rule, with the historic ministry words and the
|
| 181 |
+
# Urząd Rady Ministrów (the PM's chancellery before KPRM) as a government body. The President's
|
| 182 |
+
# Chancellery stays out (_NOT_STATE_SECRETARY).
|
| 183 |
+
("state_secretary_historic", re.compile(
|
| 184 |
+
rf"(?!.*{_NOT_STATE_SECRETARY})(?=.*(?:{_GOVERNMENT_BODY}|Urzęd\w* Rady Ministrów|URM))"
|
| 185 |
+
rf"(?:(?:{_STATE_PREFIX})?{_STATE_RANK}{_PPC_STATE_BODY}(?:{_STATE_OFFICE} {_NAME}|{_PERSON})"
|
| 186 |
+
rf"|{_NAME} {_STATE_RANK}{_PPC_STATE_BODY})"), (None, None)),
|
| 187 |
+
# Sejm and Senate legislative and petitions staff. Evidence (chars): Senate "Główny Legislator w Biurze
|
| 188 |
+
# Legislacyjnym w Kancelarii Senatu" 10.79M, "Ekspert do spraw Legislacji" 1.59M, "Główny Ekspert" 771k,
|
| 189 |
+
# "Starszy Legislator" 466k, petitions specialists ~3.6M, "Kancelarii Senatu" without "w" 100k, OSR 77k;
|
| 190 |
+
# Sejm "Przedstawiciel Biura Legislacyjnego KS" 4.87M (named 3.88M), "Przedstawicielka" 1.49M + 733k,
|
| 191 |
+
# "Kancelarii Sejmu" forms 325k + 81k, "Legislator w BL KS" 79k.
|
| 192 |
+
("legislative_petitions_staff", re.compile(
|
| 193 |
+
rf"Przedstawiciel(?:ka)? Biura Legislacyjnego (?:KS|Kancelarii (?:Sejmu|Senatu))(?:,? {_NAME})?"
|
| 194 |
+
rf"|Dyrektor Biura Legislacyjnego Kancelarii Sejmu, {_NAME}"
|
| 195 |
+
rf"|Legislator(?:ka)? w BL KS {_NAME}"
|
| 196 |
+
rf"|{_SENATE_STAFF}(?: w)? Kancelarii Senatu {_NAME}"
|
| 197 |
+
rf"|Kierownik Działu Petycji i Korespondencji w Biurze Komunikacji Społecznej w Kancelarii Senatu {_NAME}"),
|
| 198 |
+
(None, None)),
|
| 199 |
+
# The same Senate staff without "Kancelarii Senatu" (102k chars), only in the Senate's own transcripts.
|
| 200 |
+
("legislative_petitions_staff", re.compile(rf"{_SENATE_STAFF} {_NAME}"), (None, "Senat")),
|
| 201 |
+
# A committee chair named in the label: kept only if the same forenames and surnames are an MP or a
|
| 202 |
+
# senator in the same term (chair_is_member); a foreign or ministry committee's chair is not.
|
| 203 |
+
("committee_chair_named", re.compile(
|
| 204 |
+
rf"(?:Wice)?[Pp]rzewodnicząc[ya]{_CHAIR_OF}(?: obradom)?{_PERSON}|{_PPC_CHAIR_DEPUTY}{_CHAIR_OF}{_PERSON}"),
|
| 205 |
+
(None, None)),
|
| 206 |
+
]
|
| 207 |
+
MEMBER_RULES = {"mp", "senator", "sejm_senate_marshal", "mp_committee_chair", "mp_no_party",
|
| 208 |
+
"mp_surname_1919_1939", "senator_no_party", "senator_surname_1919_1939", "marshal_no_house"}
|
| 209 |
+
STAGE_DIRECTION = re.compile(r"\(.*\)\.?")
|
| 210 |
+
# A plenary header name that _NAME refuses but that still makes its MP a member: 2-4 tokens, a particle that
|
| 211 |
+
# may take "der" ("Piotr Van der Coghen"), no lowercase word ("Artur Płokszto z Litwy").
|
| 212 |
+
_LONG_NAME = re.compile(rf"{_TOK}(?: (?:(?:[Vv]el|de|von|van)(?: der)? )?{_TOK}){{1,3}}")
|
| 213 |
+
_CAMEL = re.compile(rf"(?<=[{_LO}])(?=[{_UP}][{_LO}])") # two parts run together: "JanuszPalikot"
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def _classify(label, system, house):
|
| 217 |
+
rule = classify_speaker(label)
|
| 218 |
+
if rule:
|
| 219 |
+
return rule
|
| 220 |
+
for rule_id, pattern, (only_system, only_house) in PPC_RULES:
|
| 221 |
+
if only_system in (None, system) and only_house in (None, house) and pattern.fullmatch(label):
|
| 222 |
+
return rule_id
|
| 223 |
+
return None
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
@functools.lru_cache(maxsize=None)
|
| 227 |
+
def classify_label(label, system, house):
|
| 228 |
+
"""(rule id or None, whether a leading "P. " was cut) of a PPC speaker label in NFC.
|
| 229 |
+
|
| 230 |
+
In 1919-39 "P." also stands for "Pan" before an office ("P. Minister Skarbu ..."): when nothing
|
| 231 |
+
matches, the label is classified again without it."""
|
| 232 |
+
label = unicodedata.normalize("NFC", label)
|
| 233 |
+
rule = _classify(label, system, house)
|
| 234 |
+
if rule is None and system == "II RP" and label.startswith("P. "):
|
| 235 |
+
rule = _classify(label[3:], system, house)
|
| 236 |
+
return rule, rule is not None
|
| 237 |
+
return rule, False
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def sitting_days(date):
|
| 241 |
+
"""ISO days of a <date>: "1938-11-28", or a multi-day sitting as the dump writes it ("1938-11-28 i 29",
|
| 242 |
+
"1990-09-12, 13 i 14", "1952-07-31 i 08-01", "1989-07-28, 29, 31 i 1989-08-01"); a short part takes the
|
| 243 |
+
year and month of the part before it. Anything else raises."""
|
| 244 |
+
days, year, month = [], None, None
|
| 245 |
+
for part in re.split(r",\s*|\s+i\s+", date):
|
| 246 |
+
match = _DATE_PART.fullmatch(part)
|
| 247 |
+
if not match or (year is None and not match[1]) or (match[1] and not match[2]):
|
| 248 |
+
raise ValueError(f"unexpected date {date!r}")
|
| 249 |
+
year, month = match[1] or year, match[2] or month
|
| 250 |
+
days.append(datetime.date(int(year), int(month), int(match[3])).isoformat())
|
| 251 |
+
return days
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def collapse(text):
|
| 255 |
+
return " ".join(text.split())
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def note(bibl, kind):
|
| 259 |
+
element = bibl.find(f"{T}note[@type='{kind}']")
|
| 260 |
+
return collapse(element.text or "") if element is not None else ""
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
# ------------------------------------------------------------------ speakers
|
| 264 |
+
class Speakers:
|
| 265 |
+
"""The speakers of one zip: per-person verdicts, plus the names the free-label guard trusts."""
|
| 266 |
+
|
| 267 |
+
def __init__(self, stats):
|
| 268 |
+
self.stats = stats
|
| 269 |
+
self.members = set() # name_key() of every MP/senator/marshal, any doc of the zip
|
| 270 |
+
self.kept_names = set() # "Forename Surname" of every kept structured person
|
| 271 |
+
self.kept_labels = set()
|
| 272 |
+
|
| 273 |
+
def structured(self, person, system, house):
|
| 274 |
+
"""(label, role, rule or None, reason, key) of a header person (rule None: dropped)."""
|
| 275 |
+
pn = person.find(f"{T}persName")
|
| 276 |
+
label = collapse(" ".join(pn.itertext())) if pn is not None else ""
|
| 277 |
+
if person.get(XID) == COMMENTARY:
|
| 278 |
+
return COMMENTARY, COMMENTARY, None, "commentary", None
|
| 279 |
+
if not label:
|
| 280 |
+
return label, "(no role)", None, "no_label", None
|
| 281 |
+
parts = {child.tag for child in pn}
|
| 282 |
+
if collapse(pn.text or "") or not parts or parts - {f"{T}roleName", f"{T}forename", f"{T}surname"}:
|
| 283 |
+
return label, None, None, "free", None # classified by free(), after every structured person
|
| 284 |
+
role = collapse(" ".join(collapse(e.text or "") for e in pn.findall(f"{T}roleName")))
|
| 285 |
+
forenames = tuple(collapse(e.text or "") for e in pn.findall(f"{T}forename"))
|
| 286 |
+
# PPC's party strip leaves a cut tag as one more surname ("Czerniawski", "(niez"; 1,850 persons):
|
| 287 |
+
# a surname part starting with "(" is never a name.
|
| 288 |
+
surnames = tuple(s for e in pn.findall(f"{T}surname") if (s := collapse(e.text or "")) and not s.startswith("("))
|
| 289 |
+
name = " ".join(forenames + surnames)
|
| 290 |
+
if not name:
|
| 291 |
+
# A role alone ("Marszałek", "Przedstawiciel Związku Harcerstwa Polskiego"): it must match both
|
| 292 |
+
# as it stands and with the placeholder name, so a role ending in capitalised words is no name.
|
| 293 |
+
rule, stripped = classify_label(role + PLACEHOLDER, system, house)
|
| 294 |
+
if rule and classify_label(role, system, house)[0]:
|
| 295 |
+
return label, role, rule, "role_only", None
|
| 296 |
+
return label, role, None, "role_only_unmatched", None
|
| 297 |
+
if not role:
|
| 298 |
+
return label, "(no role)", None, "no_role", None
|
| 299 |
+
rule, stripped = classify_label(role + PLACEHOLDER, system, house)
|
| 300 |
+
self.stats["persons_p_strip"] += stripped
|
| 301 |
+
if rule is None and re.fullmatch(rf"{_TOK} {_TOK}", name) \
|
| 302 |
+
and classify_label(role + PLACEHOLDER_2, system, house)[0] == "sejm_committee_secretary":
|
| 303 |
+
rule = "sejm_committee_secretary"
|
| 304 |
+
self.stats["persons_p2_fallback"] += 1
|
| 305 |
+
if not re.fullmatch(rf"{_NAME}|{_TOK}", name): # the rule stands only if scan_headers finds a member
|
| 306 |
+
return label, role, rule, "bad_name", (forenames, surnames)
|
| 307 |
+
return label, role, rule, "structured" if rule else "unmatched", (forenames, surnames)
|
| 308 |
+
|
| 309 |
+
def free(self, label, system, house):
|
| 310 |
+
"""Rule of a free-text label (a header persName without parts, a speaker line inside a turn).
|
| 311 |
+
|
| 312 |
+
Kept only when it matches a rule other than committee_chair_named (which needs a structured name)
|
| 313 |
+
and either names a speaker the zip's headers keep (the label itself, or its last 1-3 tokens as a
|
| 314 |
+
name) or has a title before the name (_TITLED) and its role takes the placeholder. Guards against
|
| 315 |
+
"Minister Spraw Zagranicznych Ukrainy Borys Tarasiuk", "Marszałek Polski Józef Piłsudski", where a
|
| 316 |
+
role absorbs words that the rules take for a name."""
|
| 317 |
+
rule = classify_label(label, system, house)[0]
|
| 318 |
+
if rule is None or rule == "committee_chair_named":
|
| 319 |
+
return None, "free_unmatched"
|
| 320 |
+
tokens = label.split()
|
| 321 |
+
if label in self.kept_labels or any(" ".join(tokens[-k:]) in self.kept_names for k in (1, 2, 3)):
|
| 322 |
+
return rule, "free"
|
| 323 |
+
titled = _TITLED.fullmatch(label)
|
| 324 |
+
if titled and classify_label(titled["role"] + PLACEHOLDER, system, house)[0] == rule:
|
| 325 |
+
return rule, "free_titled"
|
| 326 |
+
return None, "free_guard"
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
def name_key(key):
|
| 330 |
+
"""Casefolded name tokens of a (forenames, surnames) key, without punctuation and one-letter tokens."""
|
| 331 |
+
name = _CAMEL.sub(" ", " ".join(key[0] + key[1]).replace("\xad", ""))
|
| 332 |
+
tokens = (t.strip(":;,.\\/()–-") for t in name.casefold().split())
|
| 333 |
+
return tuple(t for t in tokens if len(t) > 1)
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
def is_member(key, members):
|
| 337 |
+
"""The name is a member's, or starts with one ("Jan Bury s. Antoniego", "Jerzy Eysymontt niez")."""
|
| 338 |
+
tokens = name_key(key)
|
| 339 |
+
return tokens in members or any(tokens[:n] in members for n in range(len(tokens) - 1, 1, -1))
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def chair_is_member(rule, key, members):
|
| 343 |
+
"""A role-only chair ("Przewodniczący Komisji Spraw Zagranicznych", key None) has no name to check."""
|
| 344 |
+
return rule != "committee_chair_named" or (key is not None and is_member(key, members))
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
# ------------------------------------------------------------------ documents
|
| 348 |
+
def doc_meta(z, d):
|
| 349 |
+
header = ET.fromstring(z.read(d + "header.xml"))
|
| 350 |
+
bibl = header.find(f".//{T}sourceDesc/{T}bibl")
|
| 351 |
+
date_el = bibl.find(f"{T}date")
|
| 352 |
+
date = collapse(date_el.text or "") if date_el is not None else ""
|
| 353 |
+
meta = {k: note(bibl, k) for k in ("system", "house", "type", "termNo")}
|
| 354 |
+
if date:
|
| 355 |
+
try:
|
| 356 |
+
days = sitting_days(date) # a sitting over several days (21 shapes in 1922-1991) is a range
|
| 357 |
+
except ValueError as error:
|
| 358 |
+
raise ValueError(f"{d}: {error}") from error
|
| 359 |
+
created = min(days) if len(set(days)) == 1 else f"{min(days)}, {max(days)}"
|
| 360 |
+
elif meta["termNo"] in UNDATED_TERM_RANGES and "/interpelacje/" in d:
|
| 361 |
+
created = UNDATED_TERM_RANGES[meta["termNo"]]
|
| 362 |
+
else:
|
| 363 |
+
raise ValueError(f"{d}: no date and no term range for term {meta['termNo']!r}")
|
| 364 |
+
authors = "; ".join(collapse(" ".join(a.itertext())) for a in bibl.findall(f"{T}author"))
|
| 365 |
+
return header, meta | {"date": date, "created": created, "author": authors}
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
def interpellation_text(z, d):
|
| 369 |
+
root = ET.fromstring(z.read(d + "text_structure.xml"))
|
| 370 |
+
return "\n".join(t for p in root.iter(f"{T}p") if (t := collapse("".join(p.itertext()))))
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def sitting_text(z, d, meta, persons, speakers, acc):
|
| 374 |
+
"""Kept utterances of a sitting joined by "\\n", the labels of their speakers, dropped characters.
|
| 375 |
+
|
| 376 |
+
`persons` maps an utterance's @who to [label, role, rule, reason, key]. The loop runs per body child (a <div> turn
|
| 377 |
+
block, or a lone <u>): a komentarz continues the speaker before it in the same block only."""
|
| 378 |
+
system, house = meta["system"], meta["house"]
|
| 379 |
+
kept, labels, dropped = [], {}, 0
|
| 380 |
+
body = ET.fromstring(z.read(d + "text_structure.xml")).find(f".//{T}body")
|
| 381 |
+
|
| 382 |
+
def count(label, role, rule, text, keep):
|
| 383 |
+
nonlocal dropped
|
| 384 |
+
stat = acc["labels"][(role, label, rule if keep else None)]
|
| 385 |
+
stat[0] += 1
|
| 386 |
+
stat[1] += len(text)
|
| 387 |
+
if keep:
|
| 388 |
+
kept.append(text)
|
| 389 |
+
labels.setdefault(label, None)
|
| 390 |
+
acc["stats"]["kept_chars_by_rule"][rule] += len(text)
|
| 391 |
+
else:
|
| 392 |
+
dropped += len(text)
|
| 393 |
+
|
| 394 |
+
for block in body:
|
| 395 |
+
current = None # (label, role, rule) of the turn going on
|
| 396 |
+
switch = None # (who, label, role, rule) of a speaker line inside a turn
|
| 397 |
+
for u in ([block] if block.tag == f"{T}u" else block.iter(f"{T}u")):
|
| 398 |
+
who = (u.get("who") or "").lstrip("#")
|
| 399 |
+
text = collapse("".join(u.itertext()))
|
| 400 |
+
if not text:
|
| 401 |
+
continue
|
| 402 |
+
if switch and who not in (COMMENTARY, switch[0]):
|
| 403 |
+
switch = None
|
| 404 |
+
line = text[:-1].strip()
|
| 405 |
+
if text.endswith(":") and (is_label(line) or classify_label(line, system, house)[0]):
|
| 406 |
+
rule, reason = speakers.free(line, system, house)
|
| 407 |
+
acc["stats"]["inline_labels"][reason] += 1
|
| 408 |
+
current = (line, role_of(line, set()), rule)
|
| 409 |
+
switch = (who, *current)
|
| 410 |
+
acc["stats"]["dropped_chars"]["inline_label_line"] += len(text)
|
| 411 |
+
dropped += len(text)
|
| 412 |
+
continue
|
| 413 |
+
if who == COMMENTARY:
|
| 414 |
+
if ": " in text:
|
| 415 |
+
kind, keep = "komentarz_colon", False
|
| 416 |
+
elif STAGE_DIRECTION.fullmatch(text):
|
| 417 |
+
kind, keep = "stage_direction", True
|
| 418 |
+
elif current is None:
|
| 419 |
+
kind, keep = "komentarz_unattributed", False
|
| 420 |
+
else:
|
| 421 |
+
kind, keep = ("komentarz_continuation", True) if current[2] else ("komentarz_continuation_dropped", False)
|
| 422 |
+
acc["stats"]["komentarz"][kind] += len(text)
|
| 423 |
+
if not keep:
|
| 424 |
+
acc["stats"]["dropped_chars"][kind] += len(text)
|
| 425 |
+
count(COMMENTARY, COMMENTARY, kind, text, keep)
|
| 426 |
+
continue
|
| 427 |
+
if switch:
|
| 428 |
+
speaker = switch[1:]
|
| 429 |
+
elif who in persons:
|
| 430 |
+
speaker = persons[who][:3]
|
| 431 |
+
else:
|
| 432 |
+
speaker = ("<unknown>", "(unknown who)", None)
|
| 433 |
+
acc["stats"]["dropped_chars"]["unknown_who"] += len(text)
|
| 434 |
+
current = speaker
|
| 435 |
+
label, role, rule = speaker
|
| 436 |
+
if not rule and who in persons and not switch:
|
| 437 |
+
acc["stats"]["dropped_chars"]["speaker:" + persons[who][3]] += len(text)
|
| 438 |
+
elif not rule and switch:
|
| 439 |
+
acc["stats"]["dropped_chars"]["inline_speaker"] += len(text)
|
| 440 |
+
count(label, role, rule, text, bool(rule))
|
| 441 |
+
return kept, list(labels), dropped
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
def scan_headers(z, docs, speakers, stats):
|
| 445 |
+
"""Pass 1: the verdict on every person of the zip's sittings, and the zip's member set.
|
| 446 |
+
|
| 447 |
+
Headers of docs under DROP_PREFIXES count too: a chair of 2019-2023 is checked against that term's MPs.
|
| 448 |
+
A member rule makes its person a member; with a name _NAME refuses only in a plenary sitting, where a
|
| 449 |
+
"Poseł" is an MP, and only for a _LONG_NAME (a committee's "Poseł ... z Litwy" is a foreign guest)."""
|
| 450 |
+
raw = {}
|
| 451 |
+
for d in docs:
|
| 452 |
+
if "/interpelacje/" in d:
|
| 453 |
+
continue
|
| 454 |
+
header, meta = doc_meta(z, d)
|
| 455 |
+
persons = {}
|
| 456 |
+
for person in header.iter(f"{T}person"):
|
| 457 |
+
label, role, rule, reason, key = speakers.structured(person, meta["system"], meta["house"])
|
| 458 |
+
persons[person.get(XID)] = [label, role, rule, reason, key]
|
| 459 |
+
if rule in MEMBER_RULES and (reason == "structured" or (
|
| 460 |
+
reason == "bad_name" and "/posiedzenia/" in d and _LONG_NAME.fullmatch(" ".join(key[0] + key[1])))):
|
| 461 |
+
speakers.members.add(name_key(key))
|
| 462 |
+
raw[d] = (meta, persons)
|
| 463 |
+
for d, (meta, persons) in raw.items():
|
| 464 |
+
for record in persons.values():
|
| 465 |
+
label, role, rule, reason, key = record
|
| 466 |
+
if rule and reason == "bad_name":
|
| 467 |
+
if is_member(key, speakers.members):
|
| 468 |
+
record[3] = "bad_name_member"
|
| 469 |
+
else:
|
| 470 |
+
record[2] = rule = None
|
| 471 |
+
if rule and not chair_is_member(rule, key, speakers.members):
|
| 472 |
+
record[2], record[3] = None, "chair_not_member"
|
| 473 |
+
if record[2]:
|
| 474 |
+
speakers.kept_labels.add(label)
|
| 475 |
+
if key:
|
| 476 |
+
speakers.kept_names.add(" ".join(key[0] + key[1]))
|
| 477 |
+
for d, (meta, persons) in raw.items():
|
| 478 |
+
for record in persons.values():
|
| 479 |
+
if record[3] == "free":
|
| 480 |
+
record[2], record[3] = speakers.free(record[0], meta["system"], meta["house"])
|
| 481 |
+
record[1] = role_of(record[0], set())
|
| 482 |
+
if not d.startswith(DROP_PREFIXES):
|
| 483 |
+
stats["persons"][record[3]] += 1
|
| 484 |
+
return raw
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def process_zip(job):
|
| 488 |
+
"""Pass 1 + pass 2 over one zip; writes <out>/parts/<term>.parquet and .jsonl, returns the tallies."""
|
| 489 |
+
term, size, sha, dump, out = job
|
| 490 |
+
import pyarrow as pa
|
| 491 |
+
import pyarrow.parquet as pq
|
| 492 |
+
|
| 493 |
+
path = Path(dump) / f"{term}-tei.zip"
|
| 494 |
+
if path.stat().st_size != size or sha256_file(path) != sha:
|
| 495 |
+
raise SystemExit(f"{path} does not match the pinned size/SHA-256; rerun with --download")
|
| 496 |
+
stats = {k: Counter() for k in ("dropped_docs", "dropped_chars", "kept_chars_by_rule", "komentarz",
|
| 497 |
+
"inline_labels", "persons", "chars_by_category", "docs_by_category")}
|
| 498 |
+
stats |= {"kept": 0, "chars": 0, "tokens": 0, "authors_with_value": 0, "persons_p_strip": 0,
|
| 499 |
+
"persons_p2_fallback": 0, "redactions": 0, "date_min": {}, "date_max": {}, "created_min": {},
|
| 500 |
+
"created_max": {}}
|
| 501 |
+
acc = {"stats": stats, "labels": defaultdict(lambda: [0, 0])}
|
| 502 |
+
speakers = Speakers(stats)
|
| 503 |
+
schema = pa.schema([(f, pa.int64() if f == "token_count" else pa.string()) for f in FIELDS])
|
| 504 |
+
parts = Path(out) / "parts"
|
| 505 |
+
with zipfile.ZipFile(path) as z:
|
| 506 |
+
names = set(z.namelist())
|
| 507 |
+
docs = sorted(n[:-len("header.xml")] for n in names if n.endswith("/header.xml"))
|
| 508 |
+
raw = scan_headers(z, docs, speakers, stats)
|
| 509 |
+
writer = pq.ParquetWriter(parts / f"{term}.parquet", schema, compression="zstd")
|
| 510 |
+
attribution = open(parts / f"{term}.jsonl", "w", encoding="utf-8")
|
| 511 |
+
batch = []
|
| 512 |
+
|
| 513 |
+
def flush():
|
| 514 |
+
for (row, _), tokens in zip(batch, count_tokens([row["text"] for row, _ in batch])):
|
| 515 |
+
row["token_count"] = tokens
|
| 516 |
+
stats["tokens"] += tokens
|
| 517 |
+
if batch:
|
| 518 |
+
writer.write_table(pa.Table.from_pylist([r for r, _ in batch], schema=schema))
|
| 519 |
+
for _, line in batch:
|
| 520 |
+
attribution.write(json.dumps(line, ensure_ascii=False, sort_keys=True) + "\n")
|
| 521 |
+
batch.clear()
|
| 522 |
+
|
| 523 |
+
for d in docs:
|
| 524 |
+
if d.startswith(DROP_PREFIXES):
|
| 525 |
+
stats["dropped_docs"]["prefix_sejm_2019_2027"] += 1
|
| 526 |
+
continue
|
| 527 |
+
if d + "text_structure.xml" not in names:
|
| 528 |
+
stats["dropped_docs"]["no_text_structure"] += 1
|
| 529 |
+
continue
|
| 530 |
+
kind = "interpellation" if "/interpelacje/" in d else "sitting"
|
| 531 |
+
if kind == "interpellation":
|
| 532 |
+
_, meta = doc_meta(z, d)
|
| 533 |
+
text, speakers_kept, dropped = interpellation_text(z, d), [], 0
|
| 534 |
+
else:
|
| 535 |
+
meta, persons = raw[d]
|
| 536 |
+
lines, speakers_kept, dropped = sitting_text(z, d, meta, persons, speakers, acc)
|
| 537 |
+
text = "\n".join(lines)
|
| 538 |
+
category = f"{meta['system']}|{meta['house']}|{meta['type']}"
|
| 539 |
+
if not text:
|
| 540 |
+
stats["dropped_docs"][f"empty_{kind}"] += 1
|
| 541 |
+
continue
|
| 542 |
+
before = len(REDACTION_TAGS.findall(text))
|
| 543 |
+
text, _ = redact(text)
|
| 544 |
+
if len(text) < MIN_CHARS: # its turns stay counted under their rule: dropped_chars is the allowlist's
|
| 545 |
+
stats["dropped_docs"][f"short_{kind}"] += 1
|
| 546 |
+
continue
|
| 547 |
+
stats["redactions"] += len(REDACTION_TAGS.findall(text)) - before
|
| 548 |
+
docid = d.rstrip("/").rsplit("/", 1)[1]
|
| 549 |
+
row = {"id": f"{SOURCE}_{docid}", "text": text, "source": SOURCE, "added": ADDED,
|
| 550 |
+
"created": meta["created"], "token_count": 0, "license": LICENSE, "author": meta["author"]}
|
| 551 |
+
line = {"id": row["id"], "ppc_path": d.rstrip("/"), "term": term, "system": meta["system"],
|
| 552 |
+
"house": meta["house"], "type": meta["type"], "term_no": meta["termNo"], "date": meta["date"],
|
| 553 |
+
"created": meta["created"], "speakers": speakers_kept, "kept_characters": len(text),
|
| 554 |
+
"dropped_characters": dropped, "author": meta["author"]}
|
| 555 |
+
batch.append((row, line))
|
| 556 |
+
stats["kept"] += 1
|
| 557 |
+
stats["chars"] += len(text)
|
| 558 |
+
stats["authors_with_value"] += bool(meta["author"])
|
| 559 |
+
stats["docs_by_category"][category] += 1
|
| 560 |
+
stats["chars_by_category"][category] += len(text)
|
| 561 |
+
house, first, last = meta["house"], meta["created"].split(", ")[0], meta["created"].split(", ")[-1]
|
| 562 |
+
for key, value, pick in (("created_min", first, min), ("created_max", last, max)) + (
|
| 563 |
+
(("date_min", first, min), ("date_max", last, max)) if meta["date"] else ()):
|
| 564 |
+
stats[key][house] = pick(stats[key].get(house, value), value)
|
| 565 |
+
if len(batch) >= 500:
|
| 566 |
+
flush()
|
| 567 |
+
flush()
|
| 568 |
+
writer.close()
|
| 569 |
+
attribution.close()
|
| 570 |
+
return term, stats, dict(acc["labels"])
|
| 571 |
+
|
| 572 |
+
|
| 573 |
+
# ------------------------------------------------------------------ download, merge
|
| 574 |
+
def download(dump):
|
| 575 |
+
"""Fetch any zip that is missing or the wrong size; a fresh download must match its SHA-256."""
|
| 576 |
+
dump.mkdir(parents=True, exist_ok=True)
|
| 577 |
+
for term, size, sha in MANIFEST:
|
| 578 |
+
path = dump / f"{term}-tei.zip"
|
| 579 |
+
if path.exists() and path.stat().st_size == size:
|
| 580 |
+
continue
|
| 581 |
+
part = path.with_name(path.name + ".part")
|
| 582 |
+
request = urllib.request.Request(DUMP_URL.format(term=term), headers={"User-Agent": "polish-dynaword"})
|
| 583 |
+
with urllib.request.urlopen(request, timeout=120) as response, open(part, "wb") as fh:
|
| 584 |
+
shutil.copyfileobj(response, fh, 1 << 20)
|
| 585 |
+
if part.stat().st_size != size or sha256_file(part) != sha:
|
| 586 |
+
raise SystemExit(f"{part}: size or SHA-256 differs from the 2025-05-21 dump")
|
| 587 |
+
os.replace(part, path)
|
| 588 |
+
|
| 589 |
+
|
| 590 |
+
def merge(out, results):
|
| 591 |
+
"""Concatenate the per-zip parts in MANIFEST order; sum the tallies."""
|
| 592 |
+
import pyarrow.parquet as pq
|
| 593 |
+
|
| 594 |
+
root, parts = Path(out) / "data" / SOURCE, Path(out) / "parts"
|
| 595 |
+
root.mkdir(parents=True, exist_ok=True)
|
| 596 |
+
ids, writer = set(), None
|
| 597 |
+
with open(root / f"{SOURCE}.attribution.jsonl", "w", encoding="utf-8") as attribution:
|
| 598 |
+
for term, _, _ in MANIFEST:
|
| 599 |
+
table = pq.read_table(parts / f"{term}.parquet")
|
| 600 |
+
for rid in table.column("id").to_pylist():
|
| 601 |
+
if rid in ids:
|
| 602 |
+
raise SystemExit(f"duplicate id {rid}")
|
| 603 |
+
ids.add(rid)
|
| 604 |
+
if writer is None:
|
| 605 |
+
writer = pq.ParquetWriter(root / f"{SOURCE}.parquet", table.schema, compression="zstd")
|
| 606 |
+
writer.write_table(table)
|
| 607 |
+
with open(parts / f"{term}.jsonl", encoding="utf-8") as fh:
|
| 608 |
+
shutil.copyfileobj(fh, attribution)
|
| 609 |
+
writer.close()
|
| 610 |
+
|
| 611 |
+
labels, total = defaultdict(lambda: [0, 0, None]), defaultdict(Counter)
|
| 612 |
+
scalars, extremes = Counter(), {k: {} for k in ("date_min", "date_max", "created_min", "created_max")}
|
| 613 |
+
for term, stats, label_stats in results:
|
| 614 |
+
for key, (turns, chars) in label_stats.items():
|
| 615 |
+
labels[key][0] += turns
|
| 616 |
+
labels[key][1] += chars
|
| 617 |
+
labels[key][2] = key[2]
|
| 618 |
+
for k, v in stats.items():
|
| 619 |
+
if isinstance(v, Counter):
|
| 620 |
+
total[k].update(v)
|
| 621 |
+
elif k in extremes:
|
| 622 |
+
pick = min if k.endswith("_min") else max
|
| 623 |
+
for house, date in v.items():
|
| 624 |
+
extremes[k][house] = pick(extremes[k].get(house, date), date)
|
| 625 |
+
else:
|
| 626 |
+
scalars[k] += v
|
| 627 |
+
rows = roles_table({key: tuple(v) for key, v in labels.items()}, {key: key[0] for key in labels})
|
| 628 |
+
write_roles(root / f"{SOURCE}.speaker-roles.csv", rows)
|
| 629 |
+
|
| 630 |
+
if scalars["kept"] != len(ids):
|
| 631 |
+
raise SystemExit(f"{len(ids)} rows written, {scalars['kept']} counted")
|
| 632 |
+
stats = {
|
| 633 |
+
"license": LICENSE, "licenses": {LICENSE: scalars["kept"]},
|
| 634 |
+
"created_min": min(extremes["created_min"].values()), "created_max": max(extremes["created_max"].values()),
|
| 635 |
+
**{f"{k}_by_house": dict(sorted(v.items())) for k, v in extremes.items()},
|
| 636 |
+
"added": ADDED, "dump": "2025-05-21", "drop_prefixes": list(DROP_PREFIXES),
|
| 637 |
+
"sejm_coverage_end": PARLIAMENTARY_SEJM_END,
|
| 638 |
+
**{k: dict(sorted(v.items())) for k, v in total.items()}, **dict(scalars),
|
| 639 |
+
}
|
| 640 |
+
write_json(root / f"{SOURCE}.stats.json", stats)
|
| 641 |
+
shutil.rmtree(parts)
|
| 642 |
+
return stats
|
| 643 |
+
|
| 644 |
+
|
| 645 |
+
def build(dump, out, workers):
|
| 646 |
+
(Path(out) / "parts").mkdir(parents=True, exist_ok=True)
|
| 647 |
+
jobs = sorted(((t, s, h, str(dump), str(out)) for t, s, h in MANIFEST), key=lambda j: -j[1]) # largest first
|
| 648 |
+
with ProcessPoolExecutor(workers) as pool:
|
| 649 |
+
results = list(pool.map(process_zip, jobs))
|
| 650 |
+
return merge(out, results)
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
def main(argv=None):
|
| 654 |
+
parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
| 655 |
+
parser.add_argument("--dump", type=Path, default=Path("ppc-tei-20250521"))
|
| 656 |
+
parser.add_argument("--out", type=Path, default=Path("."))
|
| 657 |
+
parser.add_argument("--download", action="store_true", help="fetch missing zips from kdp.ipipan.waw.pl")
|
| 658 |
+
parser.add_argument("--workers", type=int, default=min(12, os.cpu_count() or 1))
|
| 659 |
+
args = parser.parse_args(argv)
|
| 660 |
+
if args.download:
|
| 661 |
+
download(args.dump)
|
| 662 |
+
stats = build(args.dump, args.out, args.workers)
|
| 663 |
+
print(json.dumps({k: stats[k] for k in ("kept", "chars", "tokens", "created_min", "created_max")}, indent=1))
|
| 664 |
+
|
| 665 |
+
|
| 666 |
+
if __name__ == "__main__":
|
| 667 |
+
sys.exit(main())
|
src/fetch_sejm_api.py
CHANGED
|
@@ -116,36 +116,21 @@ def registry_entry(registry: str, source_name: str) -> re.Match[str] | None:
|
|
| 116 |
return pattern.search(registry)
|
| 117 |
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
# The `created` range only: entries also carry an `added` date.
|
| 124 |
-
created = re.search(r'["\']created["\']\s*:\s*["\']\d{4}-\d{2}-\d{2}, (\d{4}-\d{2}-\d{2})["\']',
|
| 125 |
-
match.group("body"))
|
| 126 |
-
if not created:
|
| 127 |
-
raise ContributionError(f"source {source_name} has no documented date range")
|
| 128 |
-
return created.group(1)
|
| 129 |
|
| 130 |
|
| 131 |
-
|
| 132 |
-
# `parliamentary` is checked; sejm_api_2011_2022 ends on 2022-12-31 by its own END_DATE.
|
| 133 |
-
PRIOR_PARLIAMENTARY_SOURCES = ("parliamentary",)
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
def assert_temporal_novelty(registry: str, start_date: str) -> dict[str, str]:
|
| 137 |
threshold = dt.date.fromisoformat(start_date)
|
| 138 |
-
end_dates = {
|
| 139 |
-
name: registry_source_end_date(registry, name)
|
| 140 |
-
for name in PRIOR_PARLIAMENTARY_SOURCES
|
| 141 |
-
}
|
| 142 |
overlapping = {
|
| 143 |
-
name: value for name, value in
|
| 144 |
if dt.date.fromisoformat(value) >= threshold
|
| 145 |
}
|
| 146 |
if overlapping:
|
| 147 |
raise ContributionError(f"candidate date range overlaps registered sources: {overlapping}")
|
| 148 |
-
return
|
| 149 |
|
| 150 |
|
| 151 |
def insert_source_registry_entry(registry: str, *, end_date: str) -> str:
|
|
@@ -253,7 +238,8 @@ source. No unverified upstream Creative Commons license is asserted.
|
|
| 253 |
|
| 254 |
## Temporal novelty and deduplication
|
| 255 |
|
| 256 |
-
`parliamentary` ends
|
|
|
|
| 257 |
record is dated on or after `{START_DATE}`, so its date range does not overlap it.
|
| 258 |
Exact duplicate speech texts within the contribution are removed using
|
| 259 |
SHA-1 fingerprints; this is not a claim of global cross-domain near-deduplication.
|
|
@@ -334,7 +320,7 @@ def ontology_manifest(
|
|
| 334 |
]
|
| 335 |
claims = [
|
| 336 |
{"id": f"slayer://claim/sejm-api-temporal-novelty@sha256:{version_digest[:20]}",
|
| 337 |
-
"statement": "Every contributed speech postdates every checked registered parliamentary source
|
| 338 |
"falsification_condition": "Any contributed created date is <= a documented source end date.",
|
| 339 |
"scope": [version], "supported_by": [evidence_ids["temporal-novelty"]], "asserted_by": actor},
|
| 340 |
{"id": f"slayer://claim/sejm-api-full-speaker-attribution@sha256:{version_digest[:20]}",
|
|
@@ -402,7 +388,7 @@ def build_contribution(
|
|
| 402 |
if not registry_file.is_file():
|
| 403 |
raise ContributionError(f"target source registry missing: {registry_file}")
|
| 404 |
registry = registry_file.read_text(encoding="utf-8")
|
| 405 |
-
previous_sources = assert_temporal_novelty(
|
| 406 |
|
| 407 |
try:
|
| 408 |
import pyarrow as pa
|
|
|
|
| 116 |
return pattern.search(registry)
|
| 117 |
|
| 118 |
|
| 119 |
+
# `parlamint_pl` (2015-2022) left the registry in Hub PR 54 without ever shipping data, and sejm_api_2011_2022
|
| 120 |
+
# ends on 2022-12-31 by its own END_DATE, so only `parliamentary` is checked. Its registry `created` range runs
|
| 121 |
+
# to 2025 because it holds the Senate; this source is Sejm-only, so the check uses the end of its Sejm material.
|
| 122 |
+
PRIOR_SEJM_END_DATES = {"parliamentary": common.PARLIAMENTARY_SEJM_END}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
+
def assert_temporal_novelty(start_date: str) -> dict[str, str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
threshold = dt.date.fromisoformat(start_date)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
overlapping = {
|
| 128 |
+
name: value for name, value in PRIOR_SEJM_END_DATES.items()
|
| 129 |
if dt.date.fromisoformat(value) >= threshold
|
| 130 |
}
|
| 131 |
if overlapping:
|
| 132 |
raise ContributionError(f"candidate date range overlaps registered sources: {overlapping}")
|
| 133 |
+
return dict(PRIOR_SEJM_END_DATES)
|
| 134 |
|
| 135 |
|
| 136 |
def insert_source_registry_entry(registry: str, *, end_date: str) -> str:
|
|
|
|
| 238 |
|
| 239 |
## Temporal novelty and deduplication
|
| 240 |
|
| 241 |
+
The Sejm material of `parliamentary` ends with term 8 (`{prior_sources['parliamentary']}`; its
|
| 242 |
+
Senate material is not compared: this source is Sejm-only). Every contributed
|
| 243 |
record is dated on or after `{START_DATE}`, so its date range does not overlap it.
|
| 244 |
Exact duplicate speech texts within the contribution are removed using
|
| 245 |
SHA-1 fingerprints; this is not a claim of global cross-domain near-deduplication.
|
|
|
|
| 320 |
]
|
| 321 |
claims = [
|
| 322 |
{"id": f"slayer://claim/sejm-api-temporal-novelty@sha256:{version_digest[:20]}",
|
| 323 |
+
"statement": "Every contributed speech postdates the Sejm material of every checked registered parliamentary source.",
|
| 324 |
"falsification_condition": "Any contributed created date is <= a documented source end date.",
|
| 325 |
"scope": [version], "supported_by": [evidence_ids["temporal-novelty"]], "asserted_by": actor},
|
| 326 |
{"id": f"slayer://claim/sejm-api-full-speaker-attribution@sha256:{version_digest[:20]}",
|
|
|
|
| 388 |
if not registry_file.is_file():
|
| 389 |
raise ContributionError(f"target source registry missing: {registry_file}")
|
| 390 |
registry = registry_file.read_text(encoding="utf-8")
|
| 391 |
+
previous_sources = assert_temporal_novelty(START_DATE)
|
| 392 |
|
| 393 |
try:
|
| 394 |
import pyarrow as pa
|
src/fetch_sejm_committee_transcripts.py
CHANGED
|
@@ -620,9 +620,10 @@ def regon_ok(d: str) -> bool:
|
|
| 620 |
w = [8, 9, 2, 3, 4, 5, 6, 7]
|
| 621 |
s = sum(int(a) * b for a, b in zip(d[:8], w)) % 11
|
| 622 |
return s % 10 == int(d[8])
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
|
|
|
| 626 |
|
| 627 |
|
| 628 |
def redact(text: str) -> tuple[str, int]:
|
|
|
|
| 620 |
w = [8, 9, 2, 3, 4, 5, 6, 7]
|
| 621 |
s = sum(int(a) * b for a, b in zip(d[:8], w)) % 11
|
| 622 |
return s % 10 == int(d[8])
|
| 623 |
+
# GUS weights for the 14-digit REGON; the 14th digit is the check digit.
|
| 624 |
+
w = [2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8]
|
| 625 |
+
s = sum(int(a) * b for a, b in zip(d[:13], w)) % 11
|
| 626 |
+
return s % 10 == int(d[13])
|
| 627 |
|
| 628 |
|
| 629 |
def redact(text: str) -> tuple[str, int]:
|
src/sejm_api_common.py
CHANGED
|
@@ -20,6 +20,10 @@ COPYRIGHT_ACT = "https://eli.gov.pl/api/acts/DU/2025/24/text/O/D20250024.pdf"
|
|
| 20 |
OPEN_DATA_ACT = "https://eli.gov.pl/api/acts/DU/2023/1524/text.html"
|
| 21 |
SEJM_API = "https://api.sejm.gov.pl/"
|
| 22 |
SEJM_API_DOCUMENTATION = "https://api.sejm.gov.pl/sejm.html"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
EXPECTED_FIELDS = (
|
| 25 |
"id", "text", "source", "added", "created", "token_count", "license", "author"
|
|
|
|
| 20 |
OPEN_DATA_ACT = "https://eli.gov.pl/api/acts/DU/2023/1524/text.html"
|
| 21 |
SEJM_API = "https://api.sejm.gov.pl/"
|
| 22 |
SEJM_API_DOCUMENTATION = "https://api.sejm.gov.pl/sejm.html"
|
| 23 |
+
# The end of the Sejm material that `parliamentary` keeps: the last day of term 8 (its last Sejm sitting in the
|
| 24 |
+
# shard is 2019-10-16). `parliamentary` also holds the Senate to 2025 (polish-dynaword-v2#54), which the Sejm-only
|
| 25 |
+
# API sources do not overlap.
|
| 26 |
+
PARLIAMENTARY_SEJM_END = "2019-11-11"
|
| 27 |
|
| 28 |
EXPECTED_FIELDS = (
|
| 29 |
"id", "text", "source", "added", "created", "token_count", "license", "author"
|
src/sources.py
CHANGED
|
@@ -263,18 +263,52 @@ SOURCES = {
|
|
| 263 |
"parliamentary": {
|
| 264 |
"added": "2026-06-15",
|
| 265 |
"release": "0.2.0",
|
| 266 |
-
"
|
| 267 |
"pretty": "Polish Parliamentary Corpus (Sejm/Senat)",
|
| 268 |
"license": "public-domain (official documents)",
|
| 269 |
"license_spdx": "LicenseRef-Polish-Official-Documents",
|
| 270 |
-
"traceable": "Parliamentary proceedings
|
| 271 |
-
"copyright (PL art. 4 pr.
|
| 272 |
-
"
|
| 273 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
"upstream": "http://clip.ipipan.waw.pl/PPC",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
"domain": "political/spoken",
|
| 276 |
-
"created": "
|
| 277 |
"is_ocr": False,
|
|
|
|
| 278 |
},
|
| 279 |
"sejm_api_2011_2022": {
|
| 280 |
"added": "2026-08-31",
|
|
|
|
| 263 |
"parliamentary": {
|
| 264 |
"added": "2026-06-15",
|
| 265 |
"release": "0.2.0",
|
| 266 |
+
"file_key": "parliamentary",
|
| 267 |
"pretty": "Polish Parliamentary Corpus (Sejm/Senat)",
|
| 268 |
"license": "public-domain (official documents)",
|
| 269 |
"license_spdx": "LicenseRef-Polish-Official-Documents",
|
| 270 |
+
"traceable": "Parliamentary proceedings, interpellations and the government's "
|
| 271 |
+
"replies are official documents outside copyright (PL art. 4 pr. "
|
| 272 |
+
"aut.). IPI PAN's PPC page states that the parliamentary data is "
|
| 273 |
+
"public domain; its CC BY licence covers the corpus annotations. "
|
| 274 |
+
"No annotation layer is shipped, but the speaker turns and labels "
|
| 275 |
+
"the filter reads come from IPI PAN's TEI markup, which the card "
|
| 276 |
+
"credits. Per-record ppc_path pins the document in the "
|
| 277 |
+
"SHA-256-pinned dump.",
|
| 278 |
+
"legal_note": "Not lawyer-signed-off. In sittings (plenary and committee) "
|
| 279 |
+
"only turns by MPs and senators, members of the government, "
|
| 280 |
+
"heads of constitutional organs and Sejm/Senate staff are kept "
|
| 281 |
+
"(the sejm_committee_transcripts allowlist plus PPC rules for "
|
| 282 |
+
"labels without a party tag, II RP surname-only labels and "
|
| 283 |
+
"historic offices; polish-dynaword-v2#54): 3,024,072,101 of "
|
| 284 |
+
"3,774,774,717 characters of utterance text (80.1%). A turn whose "
|
| 285 |
+
"label matches no rule is dropped, among them committee guests, "
|
| 286 |
+
"witnesses of investigative committees, the President's "
|
| 287 |
+
"Chancellery, heads of agencies other than constitutional organs, "
|
| 288 |
+
"the RCL, ministry departments, heads of state and every "
|
| 289 |
+
"interjection from the floor. Interpellations, questions and "
|
| 290 |
+
"replies are kept whole (304,741 records). Whether guest "
|
| 291 |
+
"statements are official documents under art. 4(2) is open. "
|
| 292 |
+
"IPI PAN states its own basis as public information made "
|
| 293 |
+
"available by statute (Open Data Act, Access to Public "
|
| 294 |
+
"Information Act), with no agreement with the Chancelleries "
|
| 295 |
+
"(e-mail, 2026-10-07). The rules read the printed role label, "
|
| 296 |
+
"not the person. Role table: data/parliamentary/"
|
| 297 |
+
"parliamentary.speaker-roles.csv.",
|
| 298 |
"upstream": "http://clip.ipipan.waw.pl/PPC",
|
| 299 |
+
"provenance": "Built by src/fetch_parliamentary.py from the PPC per-term TEI "
|
| 300 |
+
"dump of 2025-05-21 (28 zips pinned by size and SHA-256), "
|
| 301 |
+
"without the Sejm of 2019-2027 (covered by the sejm_* "
|
| 302 |
+
"sources): speaker turns from the TEI <u> elements, the "
|
| 303 |
+
"fail-closed role allowlist applied to sittings, interpellations "
|
| 304 |
+
"kept whole, PII pattern redaction with checksum-validated "
|
| 305 |
+
"national IDs. Pattern redaction only - re-run through "
|
| 306 |
+
"SlayerLab/NERGAL before release. Replaces the unlabelled "
|
| 307 |
+
"SpeakLeash copy (PPC_corpus) shipped up to v0.2.5.",
|
| 308 |
"domain": "political/spoken",
|
| 309 |
+
"created": "1919-02-10, 2025-04-24",
|
| 310 |
"is_ocr": False,
|
| 311 |
+
"custom_datasheet": True,
|
| 312 |
},
|
| 313 |
"sejm_api_2011_2022": {
|
| 314 |
"added": "2026-08-31",
|
src/test_parliamentary_contract.py
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contract for the parliamentary rebuild from the PPC TEI dump (fetch_parliamentary.py) and the shipped shard."""
|
| 2 |
+
import csv
|
| 3 |
+
import json
|
| 4 |
+
import sys
|
| 5 |
+
import tempfile
|
| 6 |
+
import unicodedata
|
| 7 |
+
import unittest
|
| 8 |
+
import xml.etree.ElementTree as ET
|
| 9 |
+
import zipfile
|
| 10 |
+
from collections import Counter
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from unittest import mock
|
| 13 |
+
|
| 14 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 15 |
+
|
| 16 |
+
import fetch_parliamentary as fp
|
| 17 |
+
from fetch_parliamentary import (
|
| 18 |
+
DROP_PREFIXES, SOURCE, UNDATED_TERM_RANGES, Speakers, classify_label, doc_meta,
|
| 19 |
+
sitting_days,
|
| 20 |
+
)
|
| 21 |
+
from fetch_sejm_committee_transcripts import FIELDS, LICENSE
|
| 22 |
+
from sejm_api_common import PARLIAMENTARY_SEJM_END, sha256_file
|
| 23 |
+
|
| 24 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 25 |
+
DATA = ROOT / "data" / SOURCE
|
| 26 |
+
TEI = "http://www.tei-c.org/ns/1.0"
|
| 27 |
+
LONG = "Wysoka Izbo, " + "projekt ustawy wymaga starannej pracy w komisji i dalszych poprawek. " * 4
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def person(xid, role=None, forenames=(), surnames=(), free=None):
|
| 31 |
+
"""A header <person>: structured (roleName/forename/surname) or, with `free`, a persName of plain text."""
|
| 32 |
+
if free is not None:
|
| 33 |
+
return f'<person xml:id="{xid}" role="speaker"><persName>{free}</persName></person>'
|
| 34 |
+
parts = (f"<roleName>{role}</roleName>" if role else "") + "".join(
|
| 35 |
+
f"<forename>{f}</forename>" for f in forenames) + "".join(f"<surname>{s}</surname>" for s in surnames)
|
| 36 |
+
return f'<person xml:id="{xid}" role="speaker"><persName>{parts}</persName></person>'
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def header(persons=(), date="2016-01-10", system="III RP", house="Sejm", type_="Posiedzenie plenarne",
|
| 40 |
+
term_no="8", authors=()):
|
| 41 |
+
date_el = f"<date>{date}</date>" if date is not None else ""
|
| 42 |
+
author_els = "".join(f"<author>{a}</author>" for a in authors)
|
| 43 |
+
return (f'<teiHeader xmlns="{TEI}"><fileDesc><sourceDesc><bibl>{author_els}'
|
| 44 |
+
f'<note type="system">{system}</note><note type="house">{house}</note>'
|
| 45 |
+
f'<note type="type">{type_}</note><note type="termNo">{term_no}</note>{date_el}</bibl>'
|
| 46 |
+
f"</sourceDesc></fileDesc><profileDesc><particDesc>{''.join(persons)}</particDesc></profileDesc>"
|
| 47 |
+
"</teiHeader>")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def body(*blocks):
|
| 51 |
+
"""text_structure.xml; a block is [(who, text)] (a <div>) or one (who, text) pair (a lone <u>)."""
|
| 52 |
+
def u(who, text):
|
| 53 |
+
return f'<u who="#{who}">{text}</u>'
|
| 54 |
+
inner = "".join(u(*b) if isinstance(b, tuple) else "<div>" + "".join(u(*x) for x in b) + "</div>"
|
| 55 |
+
for b in blocks)
|
| 56 |
+
return f'<teiCorpus xmlns="{TEI}"><TEI><text><body>{inner}</body></text></TEI></teiCorpus>'
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def interpellation(*paragraphs):
|
| 60 |
+
ps = "".join(f"<p>{p}</p>" for p in paragraphs)
|
| 61 |
+
return f'<teiCorpus xmlns="{TEI}"><TEI><text><body><div>{ps}</div></body></text></TEI></teiCorpus>'
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def write_zip(path, docs):
|
| 65 |
+
"""docs: {doc dir: (header xml, text_structure xml or None)}."""
|
| 66 |
+
with zipfile.ZipFile(path, "w") as z:
|
| 67 |
+
for d, (head, text) in docs.items():
|
| 68 |
+
z.writestr(d + "header.xml", head)
|
| 69 |
+
if text is not None:
|
| 70 |
+
z.writestr(d + "text_structure.xml", text)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def person_element(xml):
|
| 74 |
+
return ET.fromstring(f'<particDesc xmlns="{TEI}">{xml}</particDesc>')[0]
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class SittingDaysTest(unittest.TestCase):
|
| 78 |
+
def test_single_day(self):
|
| 79 |
+
self.assertEqual(sitting_days("1938-11-28"), ["1938-11-28"])
|
| 80 |
+
|
| 81 |
+
def test_multi_day_shapes_of_the_dump(self):
|
| 82 |
+
cases = {
|
| 83 |
+
"1938-11-28 i 29": ["1938-11-28", "1938-11-29"],
|
| 84 |
+
"1990-09-12, 13 i 14": ["1990-09-12", "1990-09-13", "1990-09-14"],
|
| 85 |
+
"1952-07-31 i 08-01": ["1952-07-31", "1952-08-01"],
|
| 86 |
+
"1945-12-29, 30, 31, 1946-01-02 i 03": ["1945-12-29", "1945-12-30", "1945-12-31", "1946-01-02",
|
| 87 |
+
"1946-01-03"],
|
| 88 |
+
"1957-04-24,25,26,27 i 28": ["1957-04-24", "1957-04-25", "1957-04-26", "1957-04-27", "1957-04-28"],
|
| 89 |
+
"1983-01-31 i 1983-02-01": ["1983-01-31", "1983-02-01"],
|
| 90 |
+
"1957-05-29 i 28": ["1957-05-29", "1957-05-28"],
|
| 91 |
+
}
|
| 92 |
+
for date, days in cases.items():
|
| 93 |
+
with self.subTest(date=date):
|
| 94 |
+
self.assertEqual(sitting_days(date), days)
|
| 95 |
+
|
| 96 |
+
def test_anything_else_raises(self):
|
| 97 |
+
for date in ("", "29 listopada 1938", "11-28", "1938-28", "1938-13-01", "1938-02-30", "1938-11-28 lub 29"):
|
| 98 |
+
with self.subTest(date=date), self.assertRaises(ValueError):
|
| 99 |
+
sitting_days(date)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class ClassifyLabelTest(unittest.TestCase):
|
| 103 |
+
KEPT = [
|
| 104 |
+
("Poseł Jan Kowalski", "III RP", "Sejm", "mp_no_party"),
|
| 105 |
+
("Poseł ks. Marian Borowiec", "PRL", "Krajowa Rada Narodowa", "mp_no_party"),
|
| 106 |
+
("Posłanka Wiceprzewodnicząca Anna Nowak", "III RP", "Sejm", "mp_no_party"),
|
| 107 |
+
("Sekretarz poseł Jan Kowalski", "III RP", "Sejm", "mp_no_party"),
|
| 108 |
+
("Sekretarz Poseł Jan Kowalski", "III RP", "Sejm", "mp_no_party"),
|
| 109 |
+
("Poeł Jan Kowalski", "III RP", "Sejm", "mp_no_party"),
|
| 110 |
+
("Przewodniczący poseł ob. Szwalbe", "PRL", "Krajowa Rada Narodowa", "mp_no_party"),
|
| 111 |
+
("P. Nowicki", "II RP", "Sejm", "mp_surname_1919_1939"),
|
| 112 |
+
("S. Karnicka", "II RP", "Senat", "senator_surname_1919_1939"),
|
| 113 |
+
("Senator Jan Kowalski", "III RP", "Senat", "senator"),
|
| 114 |
+
("Marszałek", "III RP", "Senat", "marshal_no_house"),
|
| 115 |
+
("Wicemarszałek Jan Kowalski", "III RP", "Sejm", "marshal_no_house"),
|
| 116 |
+
("Marszalek poseł Ferdynand Radziwiłł", "II RP", "Sejm", "marshal_no_house"),
|
| 117 |
+
("Marszałek Senior Jan Kowalski", "III RP", "Sejm", "marshal_no_house"),
|
| 118 |
+
("Prezes Rady Ministrów Jan Kowalski", "III RP", "Sejm", "government_member"),
|
| 119 |
+
("Prezydent Ministrów Ignacy Paderewski", "II RP", "Sejm", "government_historic"),
|
| 120 |
+
("Wicepremier Jan Kowalski", "III RP", "Sejm", "government_historic"),
|
| 121 |
+
("Minister Wyznań Religijnych i Oświecenia Publicznego Jan Kowalski", "II RP", "Sejm", "government_historic"),
|
| 122 |
+
("Kierownik Ministerstwa Skarbu Jan Kowalski", "II RP", "Sejm", "government_historic"),
|
| 123 |
+
("Minister - Szef Urzędu Rady Ministrów Jan Kowalski", "PRL", "Sejm", "government_historic"),
|
| 124 |
+
("Minister - szef Urzędu Rady Ministrów Jan Kowalski", "III RP", "Sejm", "government_historic"),
|
| 125 |
+
("Podsekretarz Stanu w Urzędzie Rady Ministrów Jan Kowalski", "III RP", "Sejm", "state_secretary_historic"),
|
| 126 |
+
("Sekretarz stanu w Urzędzie Rady Ministrów, Jan Kowalski", "III RP", "Sejm", "state_secretary_historic"),
|
| 127 |
+
("Podsekretarz stanu w URM Jan Kowalski", "III RP", "Sejm", "state_secretary_historic"),
|
| 128 |
+
("Prezes Rady Ministrów ob. Osóbka-Morawski", "PRL", "Krajowa Rada Narodowa", "government_historic"),
|
| 129 |
+
("Podsekretarz Stanu w Ministerstwie Przemysłu Chemicznego Jan Kowalski", "PRL", "Sejm", "state_secretary"),
|
| 130 |
+
("Główny Legislator w Biurze Legislacyjnym w Kancelarii Senatu Jan Kowalski", "III RP", "Senat",
|
| 131 |
+
"legislative_petitions_staff"),
|
| 132 |
+
("Główny Legislator w Biurze Legislacyjnym Jan Kowalski", "III RP", "Senat", "legislative_petitions_staff"),
|
| 133 |
+
("Przedstawiciel Biura Legislacyjnego KS Jan Kowalski", "III RP", "Sejm", "legislative_petitions_staff"),
|
| 134 |
+
("Przewodniczący Komisji Finansów Publicznych Jan Kowalski", "III RP", "Sejm", "committee_chair_named"),
|
| 135 |
+
("Zastępca Przewodniczącego Jan Kowalski", "III RP", "Senat", "committee_chair_named"),
|
| 136 |
+
("Sekretarz Komisji Finansów Publicznych Jan Kowalski", "III RP", "Sejm", "sejm_committee_secretary"),
|
| 137 |
+
("Prezes NIK Jan Kowalski", "III RP", "Sejm", "constitutional_organ_head"),
|
| 138 |
+
]
|
| 139 |
+
# Out by decision 2A (head of state, KPRP, agency deputies, "Wiceminister", bare "Sprawozdawca") or as
|
| 140 |
+
# not the chamber's own ("P." in the Senate is "Pan"; the surname-only forms are 1919-39 only).
|
| 141 |
+
DROPPED = [
|
| 142 |
+
("P. Nowicki", "III RP", "Sejm"),
|
| 143 |
+
("P. Nowicki", "II RP", "Senat"),
|
| 144 |
+
("S. Karnicka", "II RP", "Sejm"),
|
| 145 |
+
("Marszałek Województwa Mazowieckiego Adam Struzik", "III RP", "Senat"),
|
| 146 |
+
("Sekretarz stanu w Kancelarii Prezydenta RP Jan Kowalski", "III RP", "Sejm"),
|
| 147 |
+
("Wiceminister Finansów Jan Kowalski", "III RP", "Sejm"),
|
| 148 |
+
("Naczelnik Państwa Józef Piłsudski", "II RP", "Sejm"),
|
| 149 |
+
("Prezydent RP Jan Kowalski", "III RP", "Sejm"),
|
| 150 |
+
("Ob. Prezydent", "PRL", "Krajowa Rada Narodowa"),
|
| 151 |
+
("Wiceprezydent ob. Szwalbe", "PRL", "Krajowa Rada Narodowa"),
|
| 152 |
+
("Przewodniczący Rady Państwa Henryk Jabłoński", "PRL", "Sejm"),
|
| 153 |
+
("Główny Legislator w Biurze Legislacyjnym Jan Kowalski", "III RP", "Sejm"),
|
| 154 |
+
("Wiceprezes NIK Jan Kowalski", "III RP", "Sejm"),
|
| 155 |
+
# "Urzędzie" admits the Urząd Rady Ministrów only, not other offices
|
| 156 |
+
("Podsekretarz Stanu w Urzędzie Komitetu Integracji Europejskiej Jan Kowalski", "III RP", "Sejm"),
|
| 157 |
+
("Podsekretarz stanu w Urzędzie Mieszkalnictwa Jan Kowalski", "III RP", "Sejm"),
|
| 158 |
+
("Zastępca Przewodniczącego KRRiT Jan Kowalski", "III RP", "Sejm"),
|
| 159 |
+
("Sprawozdawca", "III RP", "Sejm"),
|
| 160 |
+
("Głos z sali", "III RP", "Sejm"),
|
| 161 |
+
# A role that swallows words of a name no longer fits the placeholder (structured persons).
|
| 162 |
+
("Minister Spraw Zagranicznych Ukrainy Jan Maria Kowalski", "III RP", "Sejm"),
|
| 163 |
+
("Marszałek Polski Jan Maria Kowalski", "II RP", "Sejm"),
|
| 164 |
+
("Prezes Fundacji Batorego Jan Maria Kowalski", "III RP", "Sejm"),
|
| 165 |
+
]
|
| 166 |
+
|
| 167 |
+
def test_kept_labels(self):
|
| 168 |
+
for label, system, house, rule in self.KEPT:
|
| 169 |
+
with self.subTest(label=label, system=system, house=house):
|
| 170 |
+
self.assertEqual(classify_label(label, system, house), (rule, False))
|
| 171 |
+
|
| 172 |
+
def test_dropped_labels(self):
|
| 173 |
+
for label, system, house in self.DROPPED:
|
| 174 |
+
with self.subTest(label=label, system=system, house=house):
|
| 175 |
+
self.assertIsNone(classify_label(label, system, house)[0])
|
| 176 |
+
|
| 177 |
+
def test_pan_before_an_office_in_1919_1939(self):
|
| 178 |
+
self.assertEqual(classify_label("P. Minister Skarbu Zdziechowski", "II RP", "Sejm"), ("government_member", True))
|
| 179 |
+
self.assertEqual(classify_label("P. Minister Skarbu", "II RP", "Sejm"), ("government_historic", True))
|
| 180 |
+
self.assertEqual(classify_label("P. Minister Skarbu Zdziechowski", "III RP", "Sejm"), (None, False))
|
| 181 |
+
|
| 182 |
+
def test_labels_are_read_in_nfc(self):
|
| 183 |
+
decomposed = unicodedata.normalize("NFD", "Poseł Jan Kowalczyk-Żółć")
|
| 184 |
+
self.assertNotEqual(decomposed, unicodedata.normalize("NFC", decomposed))
|
| 185 |
+
self.assertEqual(classify_label(decomposed, "III RP", "Sejm"), ("mp_no_party", False))
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class SpeakersTest(unittest.TestCase):
|
| 189 |
+
def structured(self, xml, system="III RP", house="Sejm"):
|
| 190 |
+
speakers = Speakers(Counter())
|
| 191 |
+
return speakers.structured(person_element(xml), system, house), speakers
|
| 192 |
+
|
| 193 |
+
def test_person_shapes(self):
|
| 194 |
+
cases = [
|
| 195 |
+
(person("komentarz", free="Komentarz"), ("komentarz", "komentarz", None, "commentary", None)),
|
| 196 |
+
(person("x", free=""), ("", "(no role)", None, "no_label", None)),
|
| 197 |
+
(person("x", free="Poseł ob. Ochab"), ("Poseł ob. Ochab", None, None, "free", None)),
|
| 198 |
+
(person("x", "Marszałek"), ("Marszałek", "Marszałek", "marshal_no_house", "role_only", None)),
|
| 199 |
+
(person("x", "Sprawozdawca"), ("Sprawozdawca", "Sprawozdawca", None, "role_only_unmatched", None)),
|
| 200 |
+
# a role alone must match without the placeholder too: "Przedstawiciel Związku Harcerstwa Polskiego"
|
| 201 |
+
(person("x", "Przedstawiciel Związku Harcerstwa Polskiego"),
|
| 202 |
+
("Przedstawiciel Związku Harcerstwa Polskiego", "Przedstawiciel Związku Harcerstwa Polskiego", None,
|
| 203 |
+
"role_only_unmatched", None)),
|
| 204 |
+
(person("x", None, ["Jan"], ["Kowalski"]), ("Jan Kowalski", "(no role)", None, "no_role", None)),
|
| 205 |
+
# a name _NAME refuses keeps its rule and key for the member check of scan_headers
|
| 206 |
+
(person("x", "Ekspert", ["Artur"], ["Płokszto z Litwy"]),
|
| 207 |
+
("Ekspert Artur Płokszto z Litwy", "Ekspert", None, "bad_name", (("Artur",), ("Płokszto z Litwy",)))),
|
| 208 |
+
(person("x", "Poseł", ["Piotr"], ["Van der Coghen"]),
|
| 209 |
+
("Poseł Piotr Van der Coghen", "Poseł", "mp_no_party", "bad_name", (("Piotr",), ("Van der Coghen",)))),
|
| 210 |
+
(person("x", "Poseł", ["Jan"], ["Kowalski"]),
|
| 211 |
+
("Poseł Jan Kowalski", "Poseł", "mp_no_party", "structured", (("Jan",), ("Kowalski",)))),
|
| 212 |
+
# PPC's cut party tag as one more surname part
|
| 213 |
+
(person("x", "Poseł", ["Ludwik"], ["Dorn", "(niez"]),
|
| 214 |
+
("Poseł Ludwik Dorn (niez", "Poseł", "mp_no_party", "structured", (("Ludwik",), ("Dorn",)))),
|
| 215 |
+
(person("x", "Minister Spraw Zagranicznych Ukrainy", ["Borys"], ["Tarasiuk"]),
|
| 216 |
+
("Minister Spraw Zagranicznych Ukrainy Borys Tarasiuk", "Minister Spraw Zagranicznych Ukrainy", None,
|
| 217 |
+
"unmatched", (("Borys",), ("Tarasiuk",)))),
|
| 218 |
+
]
|
| 219 |
+
for xml, expected in cases:
|
| 220 |
+
with self.subTest(xml=xml):
|
| 221 |
+
self.assertEqual(self.structured(xml)[0], expected)
|
| 222 |
+
|
| 223 |
+
def test_committee_secretary_takes_the_two_token_placeholder(self):
|
| 224 |
+
verdict, speakers = self.structured(person("x", "Sekretarz Komisji Finansów Publicznych", ["Jan"], ["Kowalski"]))
|
| 225 |
+
self.assertEqual(verdict[2:4], ("sejm_committee_secretary", "structured"))
|
| 226 |
+
self.assertEqual(speakers.stats["persons_p2_fallback"], 1)
|
| 227 |
+
verdict, _ = self.structured(person("x", "Sekretarz Komisji Finansów Publicznych", ["Jan", "Maria"],
|
| 228 |
+
["Kowalski"]))
|
| 229 |
+
self.assertEqual(verdict[2:4], (None, "unmatched"))
|
| 230 |
+
|
| 231 |
+
def test_pan_strip_is_counted(self):
|
| 232 |
+
verdict, speakers = self.structured(person("x", "P. Minister Skarbu", ["Gabriel"], ["Czechowicz"]), "II RP")
|
| 233 |
+
self.assertEqual(verdict[2], "government_historic")
|
| 234 |
+
self.assertEqual(speakers.stats["persons_p_strip"], 1)
|
| 235 |
+
|
| 236 |
+
def test_free_label_guard(self):
|
| 237 |
+
speakers = Speakers(Counter())
|
| 238 |
+
speakers.kept_names = {"Jan Kowalski", "Nowicki"}
|
| 239 |
+
speakers.kept_labels = {"Wicemarszałek Anna Nowak"}
|
| 240 |
+
cases = [
|
| 241 |
+
("Poseł Jan Kowalski", "III RP", "Sejm", ("mp_no_party", "free")),
|
| 242 |
+
("Wicemarszałek Anna Nowak", "III RP", "Sejm", ("marshal_no_house", "free")),
|
| 243 |
+
("P. Nowicki", "II RP", "Sejm", ("mp_surname_1919_1939", "free")),
|
| 244 |
+
# a role absorbing words of a name, with no kept speaker of that name in the zip
|
| 245 |
+
("Minister Spraw Zagranicznych Ukrainy Borys Tarasiuk", "III RP", "Sejm", (None, "free_guard")),
|
| 246 |
+
("Marszałek Polski Józef Piłsudski", "II RP", "Sejm", (None, "free_guard")),
|
| 247 |
+
# a title marks where the name starts (KRN, which has no structured persons)
|
| 248 |
+
("Poseł ob. Ochab", "PRL", "Krajowa Rada Narodowa", ("mp_no_party", "free_titled")),
|
| 249 |
+
("Prezes Rady Ministrów ob. Osóbka-Morawski", "PRL", "Krajowa Rada Narodowa",
|
| 250 |
+
("government_historic", "free_titled")),
|
| 251 |
+
("Wiceprezydent ob. Szwalbe", "PRL", "Krajowa Rada Narodowa", (None, "free_unmatched")),
|
| 252 |
+
# a named chair needs a structured name to check against the members
|
| 253 |
+
("Przewodniczący Komisji Finansów Publicznych Jan Kowalski", "III RP", "Sejm", (None, "free_unmatched")),
|
| 254 |
+
("Głos z sali", "III RP", "Sejm", (None, "free_unmatched")),
|
| 255 |
+
]
|
| 256 |
+
for label, system, house, expected in cases:
|
| 257 |
+
with self.subTest(label=label):
|
| 258 |
+
self.assertEqual(speakers.free(label, system, house), expected)
|
| 259 |
+
|
| 260 |
+
def test_chair_is_member(self):
|
| 261 |
+
members = {("jan", "kowalski")}
|
| 262 |
+
self.assertTrue(fp.chair_is_member("committee_chair_named", (("Jan",), ("Kowalski",)), members))
|
| 263 |
+
self.assertFalse(fp.chair_is_member("committee_chair_named", (("Hans",), ("Müller",)), members))
|
| 264 |
+
self.assertTrue(fp.chair_is_member("mp_no_party", (("Hans",), ("Müller",)), set()))
|
| 265 |
+
self.assertFalse(fp.chair_is_member("committee_chair_named", None, members))
|
| 266 |
+
|
| 267 |
+
def test_name_key(self):
|
| 268 |
+
cases = [
|
| 269 |
+
((("Jan",), ("Kowalski",)), ("jan", "kowalski")),
|
| 270 |
+
((("Piotr",), ("Van der Coghen",)), ("piotr", "van", "der", "coghen")),
|
| 271 |
+
# one-letter tokens (initials, "s." of a patronymic) and punctuation go
|
| 272 |
+
((("Jan",), ("Bury", "s. Antoniego")), ("jan", "bury", "antoniego")),
|
| 273 |
+
((("Mieczysław", "M"), ("Łuczak",)), ("mieczysław", "łuczak")),
|
| 274 |
+
((("Zdzisław",), ("Pupa:",)), ("zdzisław", "pupa")),
|
| 275 |
+
((("JANUSZ",), ("PALIKOT",)), ("janusz", "palikot")),
|
| 276 |
+
# two parts run together, a soft hyphen
|
| 277 |
+
((("JanuszPalikot",), ()), ("janusz", "palikot")),
|
| 278 |
+
((("Anna",), ("Ko\xadwalska",)), ("anna", "kowalska")),
|
| 279 |
+
]
|
| 280 |
+
for key, expected in cases:
|
| 281 |
+
with self.subTest(key=key):
|
| 282 |
+
self.assertEqual(fp.name_key(key), expected)
|
| 283 |
+
|
| 284 |
+
def test_is_member(self):
|
| 285 |
+
members = {("jan", "bury"), ("piotr", "van", "der", "coghen")}
|
| 286 |
+
for key in [(("Jan",), ("Bury",)), (("Jan",), ("Bury", "s. Antoniego")), (("Jan",), ("Bury", "syn", "Józefa")),
|
| 287 |
+
(("Piotr",), ("Van der Coghen",)), (("Piotr",), ("van der Coghen",))]:
|
| 288 |
+
with self.subTest(key=key):
|
| 289 |
+
self.assertTrue(fp.is_member(key, members))
|
| 290 |
+
# a member's name must be the whole name or its start, of at least two tokens
|
| 291 |
+
for key in [(("Jan",), ("Burysz",)), (("Józef",), ("Jan", "Bury")), (("Piotr",), ("Van der Koghen",)),
|
| 292 |
+
(("Jan",), ("Burak",)), (("Artur",), ("Płokszto z Litwy",))]:
|
| 293 |
+
with self.subTest(key=key):
|
| 294 |
+
self.assertFalse(fp.is_member(key, members | {("jan",)}))
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
class ScanHeadersTest(unittest.TestCase):
|
| 298 |
+
PLENARY = "1922-1927/sejm/posiedzenia/pp/192227-sjm-ppxxx-00001-01/"
|
| 299 |
+
COMMITTEE = "1922-1927/sejm/komisje/ks/192227-sjm-ksxxx-00001-01/"
|
| 300 |
+
|
| 301 |
+
def verdicts(self, plenary, committee):
|
| 302 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 303 |
+
path = Path(tmp) / "t.zip"
|
| 304 |
+
write_zip(path, {self.PLENARY: (header(plenary, date="1923-01-10", system="II RP"), None),
|
| 305 |
+
self.COMMITTEE: (header(committee, date="1923-01-11", system="II RP",
|
| 306 |
+
type_="Posiedzenie komisji"), None)})
|
| 307 |
+
speakers, stats = Speakers(Counter()), Counter(persons=Counter())
|
| 308 |
+
stats["persons"] = Counter()
|
| 309 |
+
with zipfile.ZipFile(path) as z:
|
| 310 |
+
raw = fp.scan_headers(z, [self.PLENARY, self.COMMITTEE], speakers, stats)
|
| 311 |
+
return {xid: tuple(record[2:4]) for _, persons in raw.values() for xid, record in persons.items()}, speakers
|
| 312 |
+
|
| 313 |
+
def test_an_unusual_name_is_kept_only_for_a_member(self):
|
| 314 |
+
verdicts, speakers = self.verdicts(
|
| 315 |
+
[person("Coghen", "Poseł", ["Piotr"], ["van der Coghen"]), # plenary evidence: a 4-token name
|
| 316 |
+
person("Bury", "Poseł", ["Jan"], ["Bury"]),
|
| 317 |
+
person("Litwa", "Poseł", ["Artur"], ["Płokszto z Litwy"])], # no evidence: a lowercase word
|
| 318 |
+
[person("CoghenK", "Poseł", ["Piotr"], ["Van der Coghen"]), # the member, cased as the dump has it
|
| 319 |
+
person("BuryK", "Poseł", ["Jan"], ["Bury", "s. Antoniego"]), # a member's name and more
|
| 320 |
+
person("Berg", "Poseł", ["Hans"], ["van der Berg"]), # a committee name is no evidence
|
| 321 |
+
person("LitwaK", "Poseł", ["Artur"], ["Płokszto z Litwy"]),
|
| 322 |
+
person("Chair", "Przewodniczący Komisji Skarbowej", ["Piotr"], ["van der Coghen"]),
|
| 323 |
+
person("RoleOnlyChair", "Przewodniczący Komisji Spraw Zagranicznych")])
|
| 324 |
+
self.assertEqual(verdicts, {
|
| 325 |
+
"Coghen": ("mp_no_party", "bad_name_member"), "Bury": ("mp_no_party", "structured"),
|
| 326 |
+
"Litwa": (None, "bad_name"), "CoghenK": ("mp_no_party", "bad_name_member"),
|
| 327 |
+
"BuryK": ("mp_no_party", "bad_name_member"), "Berg": (None, "bad_name"), "LitwaK": (None, "bad_name"),
|
| 328 |
+
"Chair": ("committee_chair_named", "bad_name_member"), "RoleOnlyChair": (None, "chair_not_member")})
|
| 329 |
+
self.assertEqual(speakers.members, {("piotr", "van", "der", "coghen"), ("jan", "bury")})
|
| 330 |
+
self.assertIn("Piotr Van der Coghen", speakers.kept_names)
|
| 331 |
+
self.assertNotIn("Artur Płokszto z Litwy", speakers.kept_names)
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
class DocMetaTest(unittest.TestCase):
|
| 335 |
+
def meta(self, d, head):
|
| 336 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 337 |
+
path = Path(tmp) / "t.zip"
|
| 338 |
+
write_zip(path, {d: (head, None)})
|
| 339 |
+
with zipfile.ZipFile(path) as z:
|
| 340 |
+
return doc_meta(z, d)[1]
|
| 341 |
+
|
| 342 |
+
def test_single_day_and_authors(self):
|
| 343 |
+
meta = self.meta("t/sejm/interpelacje/i1/", header(date="2016-01-10", type_="Interpelacja",
|
| 344 |
+
authors=["Jan Kowalski", "Anna Nowak"]))
|
| 345 |
+
self.assertEqual((meta["created"], meta["date"], meta["author"]),
|
| 346 |
+
("2016-01-10", "2016-01-10", "Jan Kowalski; Anna Nowak"))
|
| 347 |
+
|
| 348 |
+
def test_multi_day_sitting_is_a_range(self):
|
| 349 |
+
meta = self.meta("t/sejm/posiedzenia/pp/s1/", header(date="1957-05-29 i 28", system="PRL"))
|
| 350 |
+
self.assertEqual(meta["created"], "1957-05-28, 1957-05-29")
|
| 351 |
+
meta = self.meta("t/sejm/posiedzenia/pp/s1/", header(date="1938-11-28 i 28", system="II RP"))
|
| 352 |
+
self.assertEqual(meta["created"], "1938-11-28")
|
| 353 |
+
|
| 354 |
+
def test_undated_interpellation_takes_its_term(self):
|
| 355 |
+
for term_no, created in UNDATED_TERM_RANGES.items():
|
| 356 |
+
with self.subTest(term_no=term_no):
|
| 357 |
+
meta = self.meta("t/sejm/interpelacje/i1/", header(date=None, type_="Interpelacja", term_no=term_no))
|
| 358 |
+
self.assertEqual((meta["created"], meta["date"]), (created, ""))
|
| 359 |
+
|
| 360 |
+
def test_undated_anything_else_raises(self):
|
| 361 |
+
with self.assertRaisesRegex(ValueError, "no date"):
|
| 362 |
+
self.meta("t/sejm/posiedzenia/pp/s1/", header(date=None, term_no="5"))
|
| 363 |
+
with self.assertRaisesRegex(ValueError, "no date"):
|
| 364 |
+
self.meta("t/sejm/interpelacje/i1/", header(date=None, type_="Interpelacja", term_no="8"))
|
| 365 |
+
|
| 366 |
+
def test_bad_date_names_the_document(self):
|
| 367 |
+
with self.assertRaisesRegex(ValueError, "t/sejm/posiedzenia/pp/s1/: unexpected date"):
|
| 368 |
+
self.meta("t/sejm/posiedzenia/pp/s1/", header(date="29 listopada 1938"))
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
class BuildTest(unittest.TestCase):
|
| 372 |
+
"""process_zip + merge on one synthetic zip: every speaker and komentarz path of sitting_text."""
|
| 373 |
+
|
| 374 |
+
TERM = "2015-2019"
|
| 375 |
+
SITTING = "2015-2019/sejm/posiedzenia/pp/201519-sjm-ppxxx-00001-01/"
|
| 376 |
+
INTERPELLATION = "2015-2019/sejm/interpelacje/201519-sjm-inxxx-00001/"
|
| 377 |
+
DROPPED = "2019-2023/sejm/posiedzenia/pp/201923-sjm-ppxxx-00001-01/"
|
| 378 |
+
|
| 379 |
+
def docs(self):
|
| 380 |
+
persons = [
|
| 381 |
+
person("komentarz", free="Komentarz"),
|
| 382 |
+
person("Marszalek", "Marszałek"),
|
| 383 |
+
person("PoselJanKowalski", "Poseł", ["Jan"], ["Kowalski"]),
|
| 384 |
+
person("Przewodniczacy", "Przewodniczący Komisji Finansów Publicznych", ["Jan"], ["Kowalski"]),
|
| 385 |
+
person("PrzewodniczacyKomisji", "Przewodniczący Komisji Spraw Zagranicznych Bundestagu", ["Hans"],
|
| 386 |
+
["Müller"]),
|
| 387 |
+
# chair of the next term: an MP only in the dropped 2019-2023 header, which still counts for members
|
| 388 |
+
person("PrzewodniczacaNowak", "Przewodnicząca Komisji Zdrowia", ["Ewa"], ["Nowak"]),
|
| 389 |
+
person("Gosc", "Prezes Fundacji Batorego", ["Anna"], ["Zielińska"]),
|
| 390 |
+
person("PoselFree", free="Poseł Jan Kowalski"),
|
| 391 |
+
person("PoselCoghen", "Poseł", ["Piotr"], ["van der Coghen"]),
|
| 392 |
+
person("PoselLitwa", "Poseł", ["Artur"], ["Płokszto z Litwy"]),
|
| 393 |
+
]
|
| 394 |
+
sitting = body(
|
| 395 |
+
("komentarz", "(Początek posiedzenia o godz. 10)"),
|
| 396 |
+
[("Marszalek", "Otwieram posiedzenie Sejmu."),
|
| 397 |
+
("komentarz", "Głos z sali: Hańba!"),
|
| 398 |
+
("komentarz", "Proszę o spokój.")],
|
| 399 |
+
[("Gosc", "Mówię jako gość Komisji."),
|
| 400 |
+
("komentarz", "Dalszy ciąg wypowiedzi gościa.")],
|
| 401 |
+
[("PoselJanKowalski", LONG),
|
| 402 |
+
("PoselJanKowalski", "Minister Spraw Zagranicznych Ukrainy Borys Tarasiuk:"),
|
| 403 |
+
("PoselJanKowalski", "Dziękuję za zaproszenie do Sejmu."),
|
| 404 |
+
("komentarz", "(Oklaski)"),
|
| 405 |
+
("Marszalek", "Dziękuję panu ministrowi.")],
|
| 406 |
+
[("Przewodniczacy", "Komisja przyjęła sprawozdanie."),
|
| 407 |
+
("PrzewodniczacyKomisji", "Ich danke."),
|
| 408 |
+
("PrzewodniczacaNowak", "Zamykam dyskusję."),
|
| 409 |
+
("PoselFree", "Pytanie z wolnej etykiety."),
|
| 410 |
+
("Nikt", "Tekst bez mówcy w nagłówku.")],
|
| 411 |
+
[("PoselCoghen", "Głos posła van der Coghena."),
|
| 412 |
+
("PoselLitwa", "Głos posła z Litwy.")],
|
| 413 |
+
)
|
| 414 |
+
return {
|
| 415 |
+
self.SITTING: (header(persons, date="2016-01-10, 11 i 12"), sitting),
|
| 416 |
+
self.INTERPELLATION: (header(date="2016-02-01", type_="Interpelacja", authors=["Jan Kowalski"]),
|
| 417 |
+
interpellation("Szanowny Panie Ministrze,", LONG, "Z poważaniem")),
|
| 418 |
+
"2015-2019/sejm/interpelacje/201519-sjm-inxxx-00002/": (
|
| 419 |
+
header(date="2016-02-02", type_="Interpelacja"), interpellation("Za krótka.")),
|
| 420 |
+
"2015-2019/sejm/posiedzenia/pp/201519-sjm-ppxxx-00002-01/": (header(date="2016-01-13"), None),
|
| 421 |
+
self.DROPPED: (header([person("PoslankaNowak", "Posłanka", ["Ewa"], ["Nowak"])], date="2019-11-12",
|
| 422 |
+
term_no="9"), body([("PoslankaNowak", LONG)])),
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
def setUp(self):
|
| 426 |
+
self.tmp = tempfile.TemporaryDirectory()
|
| 427 |
+
self.addCleanup(self.tmp.cleanup)
|
| 428 |
+
tmp = Path(self.tmp.name)
|
| 429 |
+
self.dump, self.out = tmp / "dump", tmp / "out"
|
| 430 |
+
self.dump.mkdir()
|
| 431 |
+
path = self.dump / f"{self.TERM}-tei.zip"
|
| 432 |
+
write_zip(path, self.docs())
|
| 433 |
+
self.job = (self.TERM, path.stat().st_size, sha256_file(path), str(self.dump), str(self.out))
|
| 434 |
+
(self.out / "parts").mkdir(parents=True)
|
| 435 |
+
self.term, self.stats, self.labels = fp.process_zip(self.job)
|
| 436 |
+
|
| 437 |
+
def merged(self):
|
| 438 |
+
with mock.patch.object(fp, "MANIFEST", (self.job[:3],)):
|
| 439 |
+
stats = fp.merge(self.out, [(self.term, self.stats, self.labels)])
|
| 440 |
+
root = self.out / "data" / SOURCE
|
| 441 |
+
import pyarrow.parquet as pq
|
| 442 |
+
rows = pq.read_table(root / f"{SOURCE}.parquet").to_pylist()
|
| 443 |
+
attribution = [json.loads(line) for line in (root / f"{SOURCE}.attribution.jsonl").read_text().splitlines()]
|
| 444 |
+
with open(root / f"{SOURCE}.speaker-roles.csv", encoding="utf-8") as fh:
|
| 445 |
+
roles = list(csv.DictReader(fh))
|
| 446 |
+
return stats, rows, attribution, roles, root
|
| 447 |
+
|
| 448 |
+
def test_the_sitting_keeps_only_allowed_speakers(self):
|
| 449 |
+
_, rows, attribution, _, _ = self.merged()
|
| 450 |
+
sitting = {r["id"]: r for r in rows}[f"{SOURCE}_201519-sjm-ppxxx-00001-01"]
|
| 451 |
+
self.assertEqual(sitting["text"].split("\n"), [
|
| 452 |
+
"(Początek posiedzenia o godz. 10)", "Otwieram posiedzenie Sejmu.", "Proszę o spokój.", LONG.strip(),
|
| 453 |
+
"(Oklaski)", "Dziękuję panu ministrowi.", "Komisja przyjęła sprawozdanie.", "Zamykam dyskusję.",
|
| 454 |
+
"Pytanie z wolnej etykiety.", "Głos posła van der Coghena."])
|
| 455 |
+
line = {a["id"]: a for a in attribution}[sitting["id"]]
|
| 456 |
+
self.assertEqual(line["speakers"], ["komentarz", "Marszałek", "Poseł Jan Kowalski",
|
| 457 |
+
"Przewodniczący Komisji Finansów Publicznych Jan Kowalski",
|
| 458 |
+
"Przewodnicząca Komisji Zdrowia Ewa Nowak", "Poseł Piotr van der Coghen"])
|
| 459 |
+
self.assertEqual((sitting["created"], line["date"]), ("2016-01-10, 2016-01-12", "2016-01-10, 11 i 12"))
|
| 460 |
+
self.assertEqual(line["kept_characters"], len(sitting["text"]))
|
| 461 |
+
|
| 462 |
+
def test_dropped_characters_by_reason(self):
|
| 463 |
+
dropped = self.stats["dropped_chars"]
|
| 464 |
+
self.assertEqual(dropped["komentarz_colon"], len("Głos z sali: Hańba!"))
|
| 465 |
+
self.assertEqual(dropped["komentarz_continuation_dropped"], len("Dalszy ciąg wypowiedzi gościa."))
|
| 466 |
+
self.assertEqual(dropped["speaker:unmatched"], len("Mówię jako gość Komisji."))
|
| 467 |
+
self.assertEqual(dropped["speaker:chair_not_member"], len("Ich danke."))
|
| 468 |
+
self.assertEqual(dropped["speaker:bad_name"], len("Głos posła z Litwy."))
|
| 469 |
+
self.assertEqual(dropped["inline_label_line"], len("Minister Spraw Zagranicznych Ukrainy Borys Tarasiuk:"))
|
| 470 |
+
self.assertEqual(dropped["inline_speaker"], len("Dziękuję za zaproszenie do Sejmu."))
|
| 471 |
+
self.assertEqual(dropped["unknown_who"], len("Tekst bez mówcy w nagłówku."))
|
| 472 |
+
self.assertNotIn("short_doc", dropped) # the short interpellation is no utterance text
|
| 473 |
+
self.assertEqual(self.stats["inline_labels"], Counter({"free_guard": 1}))
|
| 474 |
+
self.assertEqual(self.stats["komentarz"], Counter({
|
| 475 |
+
"stage_direction": len("(Początek posiedzenia o godz. 10)") + len("(Oklaski)"),
|
| 476 |
+
"komentarz_colon": len("Głos z sali: Hańba!"), "komentarz_continuation": len("Proszę o spokój."),
|
| 477 |
+
"komentarz_continuation_dropped": len("Dalszy ciąg wypowiedzi gościa.")}))
|
| 478 |
+
|
| 479 |
+
def test_kept_and_dropped_characters_add_up_to_the_utterance_text(self):
|
| 480 |
+
with zipfile.ZipFile(self.dump / f"{self.TERM}-tei.zip") as z:
|
| 481 |
+
root = ET.fromstring(z.read(self.SITTING + "text_structure.xml"))
|
| 482 |
+
total = sum(len(fp.collapse("".join(u.itertext()))) for u in root.iter(f"{fp.T}u"))
|
| 483 |
+
self.assertEqual(sum(self.stats["kept_chars_by_rule"].values()) + sum(self.stats["dropped_chars"].values()),
|
| 484 |
+
total)
|
| 485 |
+
|
| 486 |
+
def test_documents_and_persons(self):
|
| 487 |
+
self.assertEqual(self.stats["dropped_docs"], Counter({"prefix_sejm_2019_2027": 1, "no_text_structure": 1,
|
| 488 |
+
"short_interpellation": 1}))
|
| 489 |
+
# the dropped term's header is not counted; the bodiless sitting's header has no persons
|
| 490 |
+
self.assertEqual(self.stats["persons"], Counter({"structured": 3, "commentary": 1, "role_only": 1,
|
| 491 |
+
"chair_not_member": 1, "unmatched": 1, "free": 1,
|
| 492 |
+
"bad_name_member": 1, "bad_name": 1}))
|
| 493 |
+
self.assertEqual(self.stats["docs_by_category"], Counter({"III RP|Sejm|Posiedzenie plenarne": 1,
|
| 494 |
+
"III RP|Sejm|Interpelacja": 1}))
|
| 495 |
+
|
| 496 |
+
def test_merge_writes_a_consistent_shard(self):
|
| 497 |
+
stats, rows, attribution, roles, root = self.merged()
|
| 498 |
+
self.assertFalse((self.out / "parts").exists())
|
| 499 |
+
self.assertEqual([r["id"] for r in rows], [a["id"] for a in attribution])
|
| 500 |
+
self.assertEqual((stats["kept"], stats["chars"], stats["tokens"]),
|
| 501 |
+
(len(rows), sum(len(r["text"]) for r in rows), sum(r["token_count"] for r in rows)))
|
| 502 |
+
self.assertTrue(all(r["token_count"] > 0 and r["source"] == SOURCE and r["license"] == LICENSE
|
| 503 |
+
and r["added"] == fp.ADDED for r in rows))
|
| 504 |
+
interp = {r["id"]: r for r in rows}[f"{SOURCE}_201519-sjm-inxxx-00001"]
|
| 505 |
+
self.assertEqual(interp["text"], "Szanowny Panie Ministrze,\n" + LONG.strip() + "\nZ poważaniem")
|
| 506 |
+
self.assertEqual(interp["author"], "Jan Kowalski")
|
| 507 |
+
self.assertEqual((stats["created_min"], stats["created_max"]), ("2016-01-10", "2016-02-01"))
|
| 508 |
+
self.assertEqual(stats["date_max_by_house"], {"Sejm": "2016-02-01"})
|
| 509 |
+
self.assertEqual(stats["licenses"], {LICENSE: 2})
|
| 510 |
+
self.assertEqual(stats["drop_prefixes"], list(DROP_PREFIXES))
|
| 511 |
+
include = sum(int(r["characters"]) for r in roles if r["decision"] == "include")
|
| 512 |
+
self.assertEqual(include, sum(stats["kept_chars_by_rule"].values()))
|
| 513 |
+
by_role = {(r["role"], r["decision"]): r for r in roles}
|
| 514 |
+
self.assertEqual(by_role[("Prezes Fundacji Batorego", "exclude")]["characters"],
|
| 515 |
+
str(len("Mówię jako gość Komisji.")))
|
| 516 |
+
|
| 517 |
+
def test_a_changed_zip_is_refused(self):
|
| 518 |
+
with self.assertRaisesRegex(SystemExit, "pinned size/SHA-256"):
|
| 519 |
+
fp.process_zip((self.TERM, self.job[1], "0" * 64, *self.job[3:]))
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
class ShippedShardTest(unittest.TestCase):
|
| 523 |
+
def test_shard_matches_its_stats_and_attribution(self):
|
| 524 |
+
import pyarrow.parquet as pq
|
| 525 |
+
|
| 526 |
+
table = pq.read_table(DATA / f"{SOURCE}.parquet")
|
| 527 |
+
self.assertEqual(table.column_names, FIELDS)
|
| 528 |
+
rows = table.to_pylist()
|
| 529 |
+
stats = json.loads((DATA / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 530 |
+
attribution = [json.loads(line) for line in
|
| 531 |
+
(DATA / f"{SOURCE}.attribution.jsonl").read_text(encoding="utf-8").splitlines() if line]
|
| 532 |
+
self.assertEqual(len(rows), stats["kept"])
|
| 533 |
+
self.assertEqual(sum(len(r["text"]) for r in rows), stats["chars"])
|
| 534 |
+
self.assertEqual(sum(r["token_count"] for r in rows), stats["tokens"])
|
| 535 |
+
self.assertEqual(len({r["id"] for r in rows}), len(rows))
|
| 536 |
+
self.assertEqual([r["id"] for r in rows], [a["id"] for a in attribution])
|
| 537 |
+
self.assertEqual([r["author"] for r in rows], [a["author"] for a in attribution])
|
| 538 |
+
self.assertTrue(all(r["source"] == SOURCE and r["license"] == LICENSE and r["token_count"] > 0
|
| 539 |
+
and len(r["text"]) >= fp.MIN_CHARS for r in rows))
|
| 540 |
+
self.assertTrue(all(len(r["created"]) == 10 or (len(r["created"]) == 22 and r["created"][10:12] == ", ")
|
| 541 |
+
for r in rows))
|
| 542 |
+
self.assertEqual(stats["created_min"], min(r["created"][:10] for r in rows))
|
| 543 |
+
self.assertEqual(stats["created_max"], max(r["created"][-10:] for r in rows))
|
| 544 |
+
self.assertFalse([a for a in attribution if a["ppc_path"].startswith(DROP_PREFIXES)])
|
| 545 |
+
self.assertLessEqual(stats["date_max_by_house"]["Sejm"], PARLIAMENTARY_SEJM_END)
|
| 546 |
+
self.assertEqual(stats["sejm_coverage_end"], PARLIAMENTARY_SEJM_END)
|
| 547 |
+
|
| 548 |
+
def test_speaker_roles_table_matches_the_stats(self):
|
| 549 |
+
stats = json.loads((DATA / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 550 |
+
with open(DATA / f"{SOURCE}.speaker-roles.csv", encoding="utf-8") as fh:
|
| 551 |
+
roles = list(csv.DictReader(fh))
|
| 552 |
+
include = Counter()
|
| 553 |
+
for row in roles:
|
| 554 |
+
if row["decision"] == "include":
|
| 555 |
+
include[row["rule"]] += int(row["characters"])
|
| 556 |
+
self.assertEqual(dict(include), stats["kept_chars_by_rule"])
|
| 557 |
+
|
| 558 |
+
def test_card_and_legal_note_cite_the_stats(self):
|
| 559 |
+
from sources import SOURCES
|
| 560 |
+
|
| 561 |
+
stats = json.loads((DATA / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 562 |
+
card = (DATA / f"{SOURCE}.md").read_text(encoding="utf-8")
|
| 563 |
+
kept, dropped = sum(stats["kept_chars_by_rule"].values()), sum(stats["dropped_chars"].values())
|
| 564 |
+
self.assertIn(f"**{stats['kept']:,} records / {stats['tokens']:,} `cl100k_base` tokens / "
|
| 565 |
+
f"{stats['chars']:,} characters**", card)
|
| 566 |
+
self.assertIn(f"**{stats['redactions']:,} redactions**", card)
|
| 567 |
+
docs, flat = stats["dropped_docs"], " ".join(card.split())
|
| 568 |
+
self.assertIn(f"{docs['empty_sitting']:,} sittings keep no turn and {docs['empty_interpellation']:,} "
|
| 569 |
+
f"interpellation records have no text; {docs['short_sitting']:,} sittings and "
|
| 570 |
+
f"{docs['short_interpellation']:,} interpellation records have under", flat)
|
| 571 |
+
for rule, chars in stats["kept_chars_by_rule"].items():
|
| 572 |
+
self.assertIn(f"| `{rule}` |", card)
|
| 573 |
+
self.assertIn(f"| {chars:,} |", card)
|
| 574 |
+
for reason, chars in stats["dropped_chars"].items():
|
| 575 |
+
self.assertIn(f"| `{reason}` | {chars:,} |", card)
|
| 576 |
+
utterance = f"{kept:,} of {kept + dropped:,} characters of utterance text ({100 * kept / (kept + dropped):.1f}%)"
|
| 577 |
+
self.assertIn(utterance, card)
|
| 578 |
+
self.assertIn(utterance, " ".join(SOURCES[SOURCE]["legal_note"].split()))
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
if __name__ == "__main__":
|
| 582 |
+
unittest.main()
|
src/test_sejm_api_contract.py
CHANGED
|
@@ -125,12 +125,15 @@ class DynawordContractTests(unittest.TestCase):
|
|
| 125 |
start_date=START_DATE, added_date="2026-08-22", encoder=FakeEncoder()
|
| 126 |
)
|
| 127 |
|
| 128 |
-
def
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
def test_overlap_with_registered_parliamentary_fails_closed(self) -> None:
|
| 132 |
with self.assertRaisesRegex(ContributionError, "overlaps"):
|
| 133 |
-
assert_temporal_novelty(
|
| 134 |
|
| 135 |
def test_registry_entry_is_valid_and_preserves_existing_sources(self) -> None:
|
| 136 |
updated = insert_source_registry_entry(REGISTRY, end_date="2026-07-03")
|
|
@@ -147,7 +150,6 @@ class DynawordContractTests(unittest.TestCase):
|
|
| 147 |
|
| 148 |
def test_rerun_against_the_shipped_registry(self) -> None:
|
| 149 |
registry = (ROOT / "src" / "sources.py").read_text(encoding="utf-8")
|
| 150 |
-
self.assertEqual(assert_temporal_novelty(registry, START_DATE), {"parliamentary": "2019-12-31"})
|
| 151 |
end_date = SOURCES["sejm_api"]["created"].split(", ")[1]
|
| 152 |
self.assertEqual(insert_source_registry_entry(registry, end_date=end_date), registry)
|
| 153 |
|
|
|
|
| 125 |
start_date=START_DATE, added_date="2026-08-22", encoder=FakeEncoder()
|
| 126 |
)
|
| 127 |
|
| 128 |
+
def test_temporal_novelty_uses_the_sejm_end_of_parliamentary(self) -> None:
|
| 129 |
+
# The registry range of `parliamentary` runs to 2025 (Senate); only its Sejm material counts.
|
| 130 |
+
self.assertEqual(SOURCES["parliamentary"]["created"].split(", ")[1][:4], "2025")
|
| 131 |
+
self.assertEqual(assert_temporal_novelty(START_DATE), {"parliamentary": "2019-11-11"})
|
| 132 |
+
self.assertEqual(assert_temporal_novelty("2019-11-12"), {"parliamentary": "2019-11-11"})
|
| 133 |
|
| 134 |
def test_overlap_with_registered_parliamentary_fails_closed(self) -> None:
|
| 135 |
with self.assertRaisesRegex(ContributionError, "overlaps"):
|
| 136 |
+
assert_temporal_novelty("2019-11-11")
|
| 137 |
|
| 138 |
def test_registry_entry_is_valid_and_preserves_existing_sources(self) -> None:
|
| 139 |
updated = insert_source_registry_entry(REGISTRY, end_date="2026-07-03")
|
|
|
|
| 150 |
|
| 151 |
def test_rerun_against_the_shipped_registry(self) -> None:
|
| 152 |
registry = (ROOT / "src" / "sources.py").read_text(encoding="utf-8")
|
|
|
|
| 153 |
end_date = SOURCES["sejm_api"]["created"].split(", ")[1]
|
| 154 |
self.assertEqual(insert_source_registry_entry(registry, end_date=end_date), registry)
|
| 155 |
|
src/test_sejm_committee_transcripts_contract.py
CHANGED
|
@@ -283,6 +283,12 @@ class RedactionTest(unittest.TestCase):
|
|
| 283 |
self.assertEqual(n, 1)
|
| 284 |
self.assertEqual(text.count("[DANE_NUMERY]"), 1)
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
def test_email_phone_iban_masked(self):
|
| 287 |
text, n = redact("pisać na jan.kowalski@sejm.gov.pl, tel. 22 694 12 34, IBAN PL61109010140000071219812874")
|
| 288 |
self.assertGreaterEqual(n, 3)
|
|
@@ -758,6 +764,17 @@ class RoleLabelTest(unittest.TestCase):
|
|
| 758 |
["Poseł", "include", "mp", 2, 100, 1],
|
| 759 |
["Prezes NIK", "include", "constitutional_organ_head", 1, 50, 1]])
|
| 760 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 761 |
|
| 762 |
class CleanScriptTest(unittest.TestCase):
|
| 763 |
"""clean_sejm_committee_transcripts.build() on a small pinned input."""
|
|
|
|
| 283 |
self.assertEqual(n, 1)
|
| 284 |
self.assertEqual(text.count("[DANE_NUMERY]"), 1)
|
| 285 |
|
| 286 |
+
def test_fourteen_digit_regon(self):
|
| 287 |
+
# This used to raise IndexError (check digit read at index 14).
|
| 288 |
+
text, _ = redact("REGON 12345678512347 oraz 12345678512348.")
|
| 289 |
+
self.assertNotIn("12345678512347", text)
|
| 290 |
+
self.assertIn("12345678512348", text)
|
| 291 |
+
|
| 292 |
def test_email_phone_iban_masked(self):
|
| 293 |
text, n = redact("pisać na jan.kowalski@sejm.gov.pl, tel. 22 694 12 34, IBAN PL61109010140000071219812874")
|
| 294 |
self.assertGreaterEqual(n, 3)
|
|
|
|
| 764 |
["Poseł", "include", "mp", 2, 100, 1],
|
| 765 |
["Prezes NIK", "include", "constitutional_organ_head", 1, 50, 1]])
|
| 766 |
|
| 767 |
+
def test_roles_table_takes_the_roles_it_is_given(self):
|
| 768 |
+
# fetch_parliamentary passes (role, label, rule) keys with their roles already cut.
|
| 769 |
+
rows = clean.roles_table({("Poseł", "Poseł Jan Kowalski", "mp_no_party"): (2, 100, "mp_no_party"),
|
| 770 |
+
("Poseł", "Poseł Anna Nowak", "mp_no_party"): (1, 30, "mp_no_party"),
|
| 771 |
+
("Ekspert", "Ekspert Adam Nowak", None): (1, 50, None)},
|
| 772 |
+
{("Poseł", "Poseł Jan Kowalski", "mp_no_party"): "Poseł",
|
| 773 |
+
("Poseł", "Poseł Anna Nowak", "mp_no_party"): "Poseł",
|
| 774 |
+
("Ekspert", "Ekspert Adam Nowak", None): "Ekspert"})
|
| 775 |
+
self.assertEqual(rows, [["Poseł", "include", "mp_no_party", 3, 130, 2],
|
| 776 |
+
["Ekspert", "exclude", "", 1, 50, 1]])
|
| 777 |
+
|
| 778 |
|
| 779 |
class CleanScriptTest(unittest.TestCase):
|
| 780 |
"""clean_sejm_committee_transcripts.build() on a small pinned input."""
|