Add source: eli_pdf_acts — Dziennik Ustaw and Monitor Polski acts published only as PDF

#47
artifacts/source_findings.md CHANGED
@@ -1008,3 +1008,40 @@ quoted third-party passages.
1008
  spot-check noisy sources, a "0 residual" pattern count is not evidence; (2)
1009
  CAPTCHA-gated origins are reproducible only via pinned checksums, not re-fetch -
1010
  say so in the datasheet instead of pretending a before/after can be regenerated.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1008
  spot-check noisy sources, a "0 residual" pattern count is not evidence; (2)
1009
  CAPTCHA-gated origins are reproducible only via pinned checksums, not re-fetch -
1010
  say so in the datasheet instead of pretending a before/after can be regenerated.
1011
+
1012
+ ## eli_pdf_acts — Dziennik Ustaw / Monitor Polski acts published only as PDF
1013
+
1014
+ **Investigated** — 2026-10-01.
1015
+
1016
+ **Verdict** — `added` (proposed with `release: None`). 33,795 acts / 209,434,373
1017
+ `cl100k_base` tokens that `dziennik_ustaw` cannot contain, because it reads
1018
+ `text.html` and the ELI API has none for them.
1019
+
1020
+ **Enumeration** — `GET https://api.sejm.gov.pl/eli/acts/{DU|MP}/{year}` lists every
1021
+ act with `textHTML` / `textPDF` flags. All years 1918–2026 (checked 2026-10-01):
1022
+ 164,568 acts, 39,110 with HTML up to 2025. **Monitor Polski: 0 of 66,697 acts have
1023
+ HTML**, in every year. Dziennik Ustaw: 2025–2026 0 of 3,185; 2000–2011 3,984 of
1024
+ 23,604; 2012–2024 all but 98; before 2000 mostly PDF only. The PDF is
1025
+ `.../{pos}/text.pdf`. Text extraction is the hard part: Dz.U. 2000–2010 PDFs use
1026
+ QuarkXPress fonts with Mac Central European codes mapped as Mac Roman
1027
+ (`ROZPORZÑDZENIE`, `noÊników`, `s∏u˝àcych` from pdftotext), two columns, and one
1028
+ PDF per act that is really the issue's pages (neighbouring acts on the first and
1029
+ last page). This source uses eli2md's published conversions (see datasheet) and
1030
+ keeps only acts with `textHTML: false` at fetch time.
1031
+
1032
+ **License evidence** — verified: Copyright Act art. 4 pkt 1 (normative acts) and
1033
+ pkt 2 (official documents and materials)
1034
+ (<https://eli.gov.pl/api/acts/DU/2025/24/text/O/D20250024.pdf>), as for
1035
+ `dziennik_ustaw`. Monitor Polski's non-normative items (notices, reports) are pkt 2.
1036
+
1037
+ **Blockers** — none to merge with `release: None`. Before release: full NERGAL pass
1038
+ (only the rules layer ran); Monitor Polski names private persons in official
1039
+ records (party/committee financial reports, decorations), which NERGAL leaves by
1040
+ design; near-dedup against `dziennik_ustaw` (consolidated texts of 2025–2026
1041
+ repeat earlier ones).
1042
+
1043
+ **Lesson** — check the API flags before assuming a "DU + MP" source covers MP:
1044
+ `fetch_eli.py`'s `textHTML` filter silently removed every Monitor Polski act. For
1045
+ OCR'd legal text, the document-level alpha-ratio gate is the wrong tool (20% of
1046
+ acts are under 0.70 because of dates, amounts and table numbers); a per-line
1047
+ filter on OCR lines only removed 2.8% of OCR characters.
data/eli_pdf_acts/eli_pdf_acts.attribution.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2def1f77810b0ca04ee1c8b1292a527b6400505dd0e9e1779c6c867cd3ea5617
3
+ size 8964610
data/eli_pdf_acts/eli_pdf_acts.md ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # eli_pdf_acts — Dziennik Ustaw and Monitor Polski acts published only as PDF
2
+
3
+ Polish official journals, the acts that the Sejm ELI API has **only as PDF**:
4
+ **33,795 documents / 209,434,373 `cl100k_base` tokens / 544,132,888 characters**.
5
+ All of Monitor Polski 2012–2026 (18,162 acts), Dziennik Ustaw 2000–2006
6
+ (12,357 acts of the 12,362 without HTML) and Dziennik Ustaw 2025–2026 plus the 98
7
+ PDF-only acts of 2020–2023 (3,276).
8
+
9
+ ## Why this is not already in `dziennik_ustaw`
10
+
11
+ `src/fetch_eli.py` takes `text.html` and skips every act whose ELI list entry has
12
+ `textHTML: false`. The ELI lists (`GET https://api.sejm.gov.pl/eli/acts/{DU|MP}/{year}`,
13
+ all years 1918–2026, checked 2026-10-01) give:
14
+
15
+ | | acts | with `textHTML` |
16
+ |---|---:|---:|
17
+ | Monitor Polski, every year | 66,697 | **0** |
18
+ | Dziennik Ustaw 2000–2011 | 23,604 | 3,984 |
19
+ | Dziennik Ustaw 2012–2024 | 30,234 | 30,136 |
20
+ | Dziennik Ustaw 2025–2026 | 3,185 | **0** |
21
+
22
+ So `dziennik_ustaw` holds no Monitor Polski act (despite its title), no act of 2025,
23
+ and about one Dziennik Ustaw act in six from 2000–2011. This source is the
24
+ complement and nothing more: the fetcher keeps an act only if the ELI list says
25
+ `textHTML: false` at fetch time (all 33,801 input rows passed; 0 had HTML), so the
26
+ two sources cannot hold the same act. If the API later adds HTML for an act, the
27
+ next fetch drops it here.
28
+
29
+ ## Origin and license
30
+
31
+ - Origin: the official PDFs of Dziennik Ustaw and Monitor Polski (Rządowe Centrum
32
+ Legislacji), served by the Sejm ELI API at
33
+ `https://api.sejm.gov.pl/eli/acts/{DU|MP}/{year}/{pos}/text.pdf`. Each document's
34
+ PDF URL, the PDF's SHA-256 and the converter version are in
35
+ `eli_pdf_acts.attribution.jsonl`; the `id` is the ELI address
36
+ (`eli_pdf_acts_DU_2003_991` = Dz.U. 2003 poz. 991).
37
+ - Conversion: [eli2md](https://github.com/PolskiAgentW/eli2md) (MIT), versions
38
+ 0.6.7–0.6.18. The converted acts are published as three datasets, pinned here by
39
+ revision: [`PolskiAgentW/monitor-polski-md`](https://huggingface.co/datasets/PolskiAgentW/monitor-polski-md)
40
+ @020d5b5, [`PolskiAgentW/dziennik-ustaw-md`](https://huggingface.co/datasets/PolskiAgentW/dziennik-ustaw-md)
41
+ @f20d217, [`PolskiAgentW/dziennik-ustaw-2000-2011-md`](https://huggingface.co/datasets/PolskiAgentW/dziennik-ustaw-2000-2011-md)
42
+ @5c07e50 (CC0-1.0).
43
+ - License: normative acts and their official drafts (art. 4 pkt 1) and official
44
+ documents and materials (art. 4 pkt 2) are not subject to copyright —
45
+ [Copyright Act, art. 4](https://eli.gov.pl/api/acts/DU/2025/24/text/O/D20250024.pdf),
46
+ the same basis as `dziennik_ustaw`. Monitor Polski also prints non-normative
47
+ official documents (notices, announcements, reports of state bodies); these fall
48
+ under art. 4 pkt 2. No Creative Commons grant is claimed for the texts.
49
+
50
+ ## What the texts are
51
+
52
+ - **Genre**: statutes, regulations, ordinances, resolutions, notices
53
+ (obwieszczenia, komunikaty), Constitutional Tribunal rulings, ratified
54
+ international agreements and their annexes (forms, tables, maps), consolidated
55
+ texts (teksty jednolite), corrections; in Monitor Polski also appointments,
56
+ financial reports of political parties and election committees, and other
57
+ reports of state bodies.
58
+ - **Register**: formal legal and administrative Polish; long enumerations,
59
+ references and numeric tables.
60
+ - **Time span**: Dziennik Ustaw 2000–2006, 2020–2021, 2023, 2025–2026;
61
+ Monitor Polski 2012–2026 (by journal year). `created` is the act's own date
62
+ ("z dnia …", ELI `announcementDate`), else its publication date, each used only if it falls in the journal year or
63
+ the year before: 1999-09-30 to 2026-09-29. 33 acts (international agreements,
64
+ conventions, protocols and denunciations: 32 in Dz.U. 2000, 1 in M.P. 2022)
65
+ have only an older title date (signing) and no publication date in the API;
66
+ they get the source range `1999-09-30, 2026-09-29`.
67
+ - **OCR**: born-digital PDFs, except pages without a usable text layer (scans of
68
+ annexes, forms, maps, and some whole acts of 2000–2002), which eli2md reads with
69
+ tesseract 5 (`pol`). 45,114 of 246,251 PDF pages; 2,821 documents contain OCR
70
+ text; 78.3M of the 544M characters come from OCR.
71
+ - Not machine-translated, not user-generated.
72
+
73
+ ## Quality of the conversion (measured against the ELI HTML where it exists)
74
+
75
+ Plain text extraction does not work on these PDFs. Dziennik Ustaw 2000–2010 was
76
+ typeset in QuarkXPress with Polish letters in Mac Central European codes mapped as
77
+ Mac Roman, the pages have two columns, and an act's PDF is the pages of the issue
78
+ it is printed on, so its first and last page carry the neighbouring acts.
79
+ `pdftotext` on Dz.U. 2003 poz. 991, first page:
80
+
81
+ ```
82
+ Za∏àcznik do rozporzàdzenia Ministra Infrastruktury
83
+ […]
84
+ ROZPORZÑDZENIE MINISTRA KULTURY1)
85
+ w sprawie okreÊlenia kategorii urzàdzeƒ i noÊników s∏u˝àcych do utrwalania utworów oraz op∏at od tych
86
+ ```
87
+
88
+ This source, same act:
89
+
90
+ ```
91
+ ROZPORZĄDZENIE MINISTRA KULTURY1)
92
+
93
+ z dnia 2 czerwca 2003 r.
94
+
95
+ w sprawie określenia kategorii urządzeń i nośników służących do utrwalania utworów oraz opłat od tych urządzeń i nośników z tytułu ich sprzedaży przez producentów i importerów
96
+ ```
97
+
98
+ Measured on random samples drawn and committed before scoring, scored once,
99
+ with the act's HTML as reference (only acts that have both can be scored):
100
+
101
+ - Dz.U. 2000–2009, sample s5207 (53 acts, 255,122 reference words): reference words
102
+ recovered in order (LCS) — eli2md **0.993**; on the same PDFs pdfplumber 0.358,
103
+ pypdf 0.621, PyMuPDF 0.676, pdftotext 0.641
104
+ ([eval/extractors_2000_2009_s5207.md](https://github.com/PolskiAgentW/eli2md/blob/main/eval/extractors_2000_2009_s5207.md)).
105
+ - Dz.U. 2012+, test sample s5113 (90 acts): main text words R 0.9993 / P 0.9979,
106
+ footnotes R 0.9701 / P 0.9564, annexes R 0.9973 / P 0.9627
107
+ ([README, 0.6.7](https://github.com/PolskiAgentW/eli2md#readme)).
108
+ - **Not measured**: Monitor Polski (no act has HTML) and Dziennik Ustaw 2025–2026
109
+ (none has HTML). Monitor Polski was checked by eye on samples only.
110
+ - OCR text is not covered by these numbers except for whole-act scans in s5207.
111
+
112
+ ## Collection and normalization
113
+
114
+ Every step is in `src/fetch_eli_pdf_acts.py`, so the shard is reproducible from
115
+ the script and the pinned revisions.
116
+
117
+ 1. **Select**: rows of the three pinned datasets whose act is `textHTML: false` in
118
+ the current ELI list for its year (33,801 of 33,801). 5 of them come out empty
119
+ and are dropped: Dz.U. 2000 poz. 48, 681, 682, 786, 886, one-page scans for
120
+ which the converter produced no text.
121
+ 2. **Markdown → text**: the first-line `# title` (written by eli2md from API
122
+ metadata; the act's printed title follows in the body) and eli2md's notes about
123
+ pages ("> [Strona 3 PDF nie ma czytelnej warstwy tekstowej …]", 61,984 lines,
124
+ 9.2M characters) are dropped. OCR'd text comes as `> ` lines: the marker is
125
+ dropped, and an OCR line is dropped as noise if it has no word of 3+ letters, or
126
+ has under 50% letters among its non-space characters and fewer than 3 such
127
+ words — 128,782 of 658,233 OCR lines, 2.3M of 80.6M OCR characters (2.8%; 0.41%
128
+ of all text): stray digits of table cells, chart axis labels, stamp and grid
129
+ debris. This also drops some genuine numeric table rows (lists of customs codes
130
+ or parcel numbers). Heading hashes (`##### § 1.` → `§ 1.`), `**`, the `*…*`
131
+ eli2md puts around signature lines (`*Prezes Rady Ministrów: D. Tusk*`, 28,303
132
+ lines), image
133
+ links and markdown backslash escapes are removed; footnote marks `[^3]` become
134
+ `3)` and definitions `3) …`, as printed. Asterisks printed in the acts (`*)`
135
+ footnotes, marks in tariff tables) are kept.
136
+ 3. **Unicode and whitespace**: NFKC; no-break, thin and other spaces → space;
137
+ zero-width characters, soft hyphens and control characters dropped; spaces
138
+ collapsed, lines trimmed, at most one empty line in a row. Polish quotation
139
+ marks „…” and dashes are kept as printed.
140
+ 4. **PII**: the rules layer of [SlayerLab/NERGAL](https://huggingface.co/SlayerLab/NERGAL)
141
+ 1.1.2 (`scrub_pii.py` at revision e0caa8b, SHA-256 checked against
142
+ `hybrid.json`): 8,847 spans (4,956 `[PII]`, 3,891 `[Telefon]`) in 661
143
+ documents (501 Monitor Polski, 160 Dziennik Ustaw), mostly phone/fax
144
+ numbers, e-mails, NIP/REGON/KRS and bank accounts in Monitor Polski notices
145
+ (financial reports of parties and election committees, tender notices) and the
146
+ ePUAP addresses of municipalities in MP 2023/503. A few hits are numbers in
147
+ tables. **The NERGAL model layer was not run** (CPU only); the shard needs a
148
+ full NERGAL pass before a release.
149
+ 5. **Gates** (`build_dynaword.py`): `is_ocr` is `False`, so the document-level
150
+ alpha-ratio gate does not run. It would drop 6,964 acts (20%), mostly short
151
+ notices and tables full of dates and amounts; OCR noise is handled per line in
152
+ step 2 instead. Other gates: 0 dropped as too short, 0 as
153
+ not Polish; exact dedup dropped 1 (M.P. 2020 poz. 747: the
154
+ same notice as poz. 736, printed twice).
155
+
156
+ Article numbering, tables (as text rows) and annexes are kept: they are content.
157
+
158
+ ## Inclusion argument and caveats
159
+
160
+ What this adds: the official journal text the corpus does not have — all of
161
+ Monitor Polski, Dziennik Ustaw 2025–2026, and the 2000–2006 Dziennik Ustaw acts
162
+ missing from `dziennik_ustaw` — with text that general PDF extractors garble on
163
+ these years.
164
+
165
+ Caveats:
166
+ - Unofficial text from automatic conversion; the binding text is the PDF.
167
+ - OCR'd parts (14% of characters) keep OCR errors, worst in tables and forms.
168
+ Tables are flattened to text rows.
169
+ - Monitor Polski names private persons in official capacities and records
170
+ (party and committee financial reports, auditors, decorations, appointments).
171
+ NERGAL does not remove names by design.
172
+ - Near-duplicates with `dziennik_ustaw` remain: a consolidated text (tekst
173
+ jednolity) of 2025–2026 repeats much of an earlier consolidated text of the
174
+ same law that `dziennik_ustaw` has from HTML; corrections repeat fragments.
175
+ - Converter versions differ by year (0.6.7–0.6.18, per document in the sidecar).
176
+ Known: Dz.U. 2000 poz. 175 (0.6.16) still ends with the issue's colophon.
177
+ - Coverage: Dziennik Ustaw 2007–2011 is being converted and is not in the pinned
178
+ revision yet; Dziennik Ustaw before 2000 and Monitor Polski before 2012 are not
179
+ converted.
data/eli_pdf_acts/eli_pdf_acts.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:14762357403a9b2bcb66b8872bffcfe4ef90ec67e61b723adba918fc492ee870
3
+ size 141887559
data/eli_pdf_acts/eli_pdf_acts.stats.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "read": 33796,
3
+ "kept": 33795,
4
+ "drop_short": 0,
5
+ "drop_lang": 0,
6
+ "drop_dup": 1,
7
+ "drop_ocr": 0,
8
+ "chars": 544132888,
9
+ "tokens": 209434373,
10
+ "licenses": {
11
+ "public-domain (official documents)": 33795
12
+ },
13
+ "authors_with_value": 0,
14
+ "secs": 29.3,
15
+ "license": "public-domain (official documents)"
16
+ }
src/fetch_eli_pdf_acts.py ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Fetch the Polish acts that the Sejm ELI API publishes only as PDF, as text, into a
3
+ SpeakLeash-style .jsonl.zst for build_dynaword.py (source `eli_pdf_acts`).
4
+
5
+ `dziennik_ustaw` (src/fetch_eli.py) takes text.html and skips every act with
6
+ `textHTML: false`. That skips all of Monitor Polski (the API has no HTML for any
7
+ MP act), Dziennik Ustaw 2025 onward, most of Dziennik Ustaw before 2012, and a
8
+ few acts 2020-2023. This source is that complement and nothing else: an act is
9
+ kept only if the ELI list for its year says `textHTML: false` at fetch time, so
10
+ the two sources never hold the same act.
11
+
12
+ Text: the official PDFs (https://api.sejm.gov.pl/eli/acts/{pub}/{year}/{pos}/text.pdf)
13
+ converted by eli2md (https://github.com/PolskiAgentW/eli2md, MIT; text layer with
14
+ the PDFs' broken font encodings repaired, page furniture removed, columns put in
15
+ reading order, OCR (tesseract) for pages with no usable text layer). The converted
16
+ acts are published as three Hugging Face datasets, pinned here by revision:
17
+ PolskiAgentW/monitor-polski-md MP 2012-2026
18
+ PolskiAgentW/dziennik-ustaw-md DU 2025-2026 and the 2020-2023 PDF-only acts
19
+ PolskiAgentW/dziennik-ustaw-2000-2011-md DU 2000-2011 (years added as converted)
20
+ Each row has `source_pdf` and `pdf_sha256`, so a document can be checked against
21
+ the PDF it came from.
22
+
23
+ Normalization (markdown -> text), in order:
24
+ 1. drop the first-line `# title` (eli2md writes it from API metadata; the act's
25
+ own title follows in the body) and the converter's notes about pages
26
+ (`> [Strona N PDF nie ma czytelnej warstwy tekstowej ...]` and the like);
27
+ 2. OCR'd text comes as `> ` quote lines: drop the marker, and drop an OCR line
28
+ that is noise read off images, form grids or stamps: no word of 3+ letters, or
29
+ under 50% letters among its non-space characters and fewer than 3 such words;
30
+ 3. strip markdown: heading hashes (`##### § 1.` -> `§ 1.`), `**`, the `*…*` eli2md
31
+ puts around signature lines (`*Prezes Rady Ministrów: D. Tusk*`), image links,
32
+ backslash escapes of markdown punctuation; footnote marks `[^3]` -> `3)` and
33
+ definitions `[^3]: …` -> `3) …`, the way the printed acts mark them;
34
+ 4. NFKC, no-break/thin/zero-width spaces to space (or dropped), soft hyphens and
35
+ control characters dropped, quote/dash zoo left as printed; spaces collapsed,
36
+ lines trimmed, at most one empty line in a row;
37
+ 5. SlayerLab/NERGAL rules (`scrub_pii.py`, pinned revision, SHA256 checked).
38
+ The NERGAL model pass is not run here (no GPU); it has to be run before a release.
39
+ Article numbering, tables (as `|` rows) and annex text are kept: they are content.
40
+ `created` is the act's date from its title in the current ELI list, else its publication date
41
+ (see act_date()).
42
+
43
+ Usage:
44
+ python3 src/fetch_eli_pdf_acts.py --out ~/speakleash
45
+ python3 src/build_dynaword.py --sources eli_pdf_acts --speakleash-dir ~/speakleash --out .
46
+ python3 src/fetch_eli_pdf_acts.py --out ~/speakleash --attribution data/eli_pdf_acts/eli_pdf_acts.parquet
47
+
48
+ The last step writes data/eli_pdf_acts/eli_pdf_acts.attribution.jsonl: for each id in the
49
+ built shard, its ELI address, source PDF URL, PDF sha256 and converter version.
50
+ """
51
+ from __future__ import annotations
52
+
53
+ import argparse
54
+ import hashlib
55
+ import importlib.util
56
+ import json
57
+ import re
58
+ import subprocess
59
+ import sys
60
+ import time
61
+ import unicodedata
62
+ from concurrent.futures import ProcessPoolExecutor
63
+ from pathlib import Path
64
+ from urllib.error import HTTPError, URLError
65
+ from urllib.request import Request, urlopen
66
+
67
+ KEY = "eli_pdf_acts"
68
+ LICENSE = "public-domain (official documents)"
69
+ API = "https://api.sejm.gov.pl/eli/acts"
70
+ UA = {"User-Agent": "polish-dynaword/0.1 (+research; openly-licensed corpus)"}
71
+ # dataset -> pinned revision (git sha on the Hub)
72
+ DATASETS = {
73
+ "PolskiAgentW/monitor-polski-md": "020d5b5f0023bb17a2df911dae7c2650656ef3e1",
74
+ "PolskiAgentW/dziennik-ustaw-md": "f20d217b2e351e5527543fc7be6860c3c1fa1e86",
75
+ "PolskiAgentW/dziennik-ustaw-2000-2011-md": "5c07e5019e439f8bc4d5f5d75ab075fca525874b",
76
+ }
77
+ NERGAL_REPO = "SlayerLab/NERGAL"
78
+ NERGAL_REV = "e0caa8b88afe213c52394afe425fb1504070f5ee" # 1.1.2
79
+ NERGAL_RULES_SHA256 = "08faef844c850bcd438c904d0b3f898df47c8bde8dd827d36ebffd39dc1594fb"
80
+ FIELDS = ("id", "text", "created", "eli", "source_pdf", "pdf_sha256", "converter")
81
+
82
+ ELI_RE = re.compile(r"^(DU|MP)/(\d{4})/(\d+)$")
83
+ MONTHS = {m: i for i, m in enumerate("stycznia lutego marca kwietnia maja czerwca lipca sierpnia września "
84
+ "października listopada grudnia".split(), 1)}
85
+ TITLE_DATE_RE = re.compile(r"\bz dnia (\d{1,2}) (" + "|".join(MONTHS) + r") (\d{4}) ?r\.")
86
+ # converter notes eli2md puts in quote lines, e.g. "> [Strona 3 PDF nie ma czytelnej warstwy tekstowej …]"
87
+ NOTE_RE = re.compile(r"^> \[(Strona|Strony|Na stronie|Na stronach) .*\]\s*$")
88
+ FOOTDEF_RE = re.compile(r"^\[\^(\w+)\]:\s?")
89
+ FOOTREF_RE = re.compile(r"\[\^(\w+)\]")
90
+ HEADING_RE = re.compile(r"^#{1,6} ")
91
+ IMAGE_RE = re.compile(r"!\[[^\]]*\]\([^)]*\)")
92
+ # eli2md writes a signature block as one italic line, "*Prezes Rady Ministrów: D. Tusk*"; a printed line that
93
+ # starts and ends with "*" (customs-tariff rows, "*) footnote") has no "Title: Name" colon or starts with ")"
94
+ SIGNATURE_RE = re.compile(r"^\*([^\s*)][^*]*:[^*]*[^\s*])\*$")
95
+ ESCAPE_RE = re.compile(r"\\([\\`*_{}\[\]()#+\-.!|>~])")
96
+ LETTER_RE = re.compile(r"[^\W\d_]")
97
+ WORD3_RE = re.compile(r"[^\W\d_]{3,}")
98
+ # no-break, thin, figure, narrow and other unicode spaces -> space; zero-width -> nothing
99
+ SPACES = dict.fromkeys(map(ord, "            "
100
+ "   "), " ")
101
+ SPACES.update(dict.fromkeys(map(ord, "​‌‍⁠­"), None)) # + soft hyphen
102
+
103
+
104
+ def ocr_noise(line: str) -> bool:
105
+ """An OCR line read off a picture, form grid or stamp rather than off text."""
106
+ chars = [c for c in line if not c.isspace()]
107
+ if not chars:
108
+ return True
109
+ words = len(WORD3_RE.findall(line))
110
+ letters = len(LETTER_RE.findall(line))
111
+ # a long citation line ("… Nr 30, poz. 179, z 1991 r. Nr 4, …") is mostly digits but has words
112
+ return words == 0 or (letters / len(chars) < 0.5 and words < 3)
113
+
114
+
115
+ def md_to_text(md: str) -> tuple[str, dict[str, int]]:
116
+ """eli2md markdown -> plain text (steps 1-3 of the module doc). Returns text and counts."""
117
+ st = {"notes": 0, "ocr_lines": 0, "ocr_noise": 0}
118
+ lines = md.split("\n")
119
+ if lines and lines[0].startswith("# "):
120
+ lines = lines[1:]
121
+ out = []
122
+ for line in lines:
123
+ if NOTE_RE.match(line):
124
+ st["notes"] += 1
125
+ continue
126
+ if line.startswith(">"):
127
+ line = line[2:] if line.startswith("> ") else line[1:]
128
+ st["ocr_lines"] += 1
129
+ if ocr_noise(line):
130
+ st["ocr_noise"] += 1
131
+ continue
132
+ else:
133
+ line = SIGNATURE_RE.sub(r"\1", line)
134
+ line = HEADING_RE.sub("", line)
135
+ line = FOOTDEF_RE.sub(lambda m: f"{m.group(1)}) ", line)
136
+ line = FOOTREF_RE.sub(lambda m: f"{m.group(1)})", line)
137
+ line = IMAGE_RE.sub("", line).replace("**", "")
138
+ line = ESCAPE_RE.sub(r"\1", line)
139
+ out.append(line)
140
+ return "\n".join(out), st
141
+
142
+
143
+ def normalize(text: str) -> str:
144
+ """Step 4: unicode and whitespace."""
145
+ text = unicodedata.normalize("NFKC", text).translate(SPACES)
146
+ text = "".join(c for c in text if c in "\n\t" or unicodedata.category(c)[0] != "C")
147
+ lines = [re.sub(r"[ \t]+", " ", ln).strip() for ln in text.split("\n")]
148
+ return re.sub(r"\n{3,}", "\n\n", "\n".join(lines)).strip()
149
+
150
+
151
+ def act_date(entry: dict, year: int) -> str:
152
+ """The act's date as its title gives it ("… z dnia 5 grudnia 2000 r. …"), else its publication date, each only
153
+ if it falls in the journal year or the year before; else "" (build_dynaword then uses the source's range).
154
+ Not the API's announcementDate: it has typos (DU/2020/2059 "z dnia 27 października 2020" -> 2020-11-27,
155
+ DU/2026/34 "z dnia 17 grudnia 2025" -> 2026-12-17). A title's first "z dnia" can belong to another document
156
+ (a treaty amended, a convention a reservation was made to), hence the year window."""
157
+ m = TITLE_DATE_RE.search(entry.get("title") or "")
158
+ if m and year - 1 <= int(m.group(3)) <= year:
159
+ return f"{int(m.group(3)):04d}-{MONTHS[m.group(2)]:02d}-{int(m.group(1)):02d}"
160
+ pub = entry.get("promulgation") or ""
161
+ return pub if pub[:4] == str(year) else ""
162
+
163
+
164
+ def _get(url: str, tries: int = 4):
165
+ for i in range(tries):
166
+ try:
167
+ with urlopen(Request(url, headers=UA), timeout=60) as r:
168
+ return json.loads(r.read())
169
+ except (HTTPError, URLError, TimeoutError):
170
+ time.sleep(2 * (i + 1))
171
+ raise RuntimeError(f"ELI API failed: {url}")
172
+
173
+
174
+ def pdf_only(pub: str, year: int, cache: dict) -> dict[int, dict]:
175
+ """Acts the ELI API has as PDF but not as HTML, as of now: position -> list entry."""
176
+ if (pub, year) not in cache:
177
+ items = _get(f"{API}/{pub}/{year}").get("items", [])
178
+ cache[pub, year] = {it["pos"]: it for it in items if not it.get("textHTML") and it.get("textPDF")}
179
+ return cache[pub, year]
180
+
181
+
182
+ def load_rules(cache_dir: Path):
183
+ from huggingface_hub import hf_hub_download
184
+ path = hf_hub_download(NERGAL_REPO, "scrub_pii.py", revision=NERGAL_REV, cache_dir=cache_dir)
185
+ digest = hashlib.sha256(Path(path).read_bytes()).hexdigest()
186
+ if digest != NERGAL_RULES_SHA256:
187
+ raise RuntimeError(f"NERGAL scrub_pii.py sha256 {digest} != {NERGAL_RULES_SHA256}")
188
+ spec = importlib.util.spec_from_file_location("scrub_pii", path)
189
+ mod = importlib.util.module_from_spec(spec)
190
+ spec.loader.exec_module(mod)
191
+ return mod
192
+
193
+
194
+ _RULES = None
195
+
196
+
197
+ def _init(rules_path: str) -> None:
198
+ global _RULES
199
+ spec = importlib.util.spec_from_file_location("scrub_pii", rules_path)
200
+ _RULES = importlib.util.module_from_spec(spec)
201
+ spec.loader.exec_module(_RULES)
202
+
203
+
204
+ def convert(row: dict) -> tuple[dict | None, dict]:
205
+ """One dataset row -> (jsonl record or None, counts)."""
206
+ text, st = md_to_text(row["markdown"] or "")
207
+ text = normalize(text)
208
+ text, hits = _RULES.scrub_pii(text)
209
+ st["pii_masks"] = sum(hits.values())
210
+ if not text:
211
+ return None, st
212
+ m = ELI_RE.match(row["eli"])
213
+ rec = {
214
+ "id": f"{KEY}_{m.group(1)}_{m.group(2)}_{m.group(3)}",
215
+ "text": text,
216
+ "created": row["created"],
217
+ "eli": row["eli"],
218
+ "source_pdf": row["source_pdf"],
219
+ "pdf_sha256": row["pdf_sha256"],
220
+ "converter": row["converter"],
221
+ }
222
+ return rec, st
223
+
224
+
225
+ def write_attribution(jsonl_zst: Path, shard: Path) -> int:
226
+ """Sidecar rows (all FIELDS but text) for the ids that made it into the built shard, in shard order."""
227
+ import pyarrow.parquet as pq
228
+ import zstandard
229
+ ids = pq.read_table(shard, columns=["id"]).column("id").to_pylist()
230
+ meta = {}
231
+ with jsonl_zst.open("rb") as fh:
232
+ for line in zstandard.ZstdDecompressor().stream_reader(fh).read().decode("utf-8").splitlines():
233
+ rec = json.loads(line)
234
+ meta[rec["id"]] = {k: rec[k] for k in FIELDS if k != "text"}
235
+ out = shard.with_name(f"{KEY}.attribution.jsonl")
236
+ with out.open("w", encoding="utf-8") as f:
237
+ for i in ids:
238
+ f.write(json.dumps(meta[i], ensure_ascii=False) + "\n")
239
+ return len(ids)
240
+
241
+
242
+ def main() -> None:
243
+ ap = argparse.ArgumentParser()
244
+ ap.add_argument("--out", default="~/speakleash")
245
+ ap.add_argument("--cache", default="~/.cache/eli_pdf_acts")
246
+ ap.add_argument("--workers", type=int, default=4)
247
+ ap.add_argument("--attribution", metavar="SHARD", help="only write the sidecar for a built shard")
248
+ args = ap.parse_args()
249
+ if args.attribution:
250
+ n = write_attribution(Path(args.out).expanduser() / f"{KEY}.jsonl.zst", Path(args.attribution))
251
+ print(f"attribution: {n:,} rows")
252
+ return
253
+ import pyarrow.parquet as pq
254
+ from huggingface_hub import hf_hub_download
255
+
256
+ out_dir = Path(args.out).expanduser()
257
+ out_dir.mkdir(parents=True, exist_ok=True)
258
+ cache_dir = Path(args.cache).expanduser()
259
+ rules_path = load_rules(cache_dir).__file__
260
+ flags: dict = {}
261
+ seen: set[str] = set()
262
+ tot = {"rows": 0, "kept": 0, "not_pdf_only": 0, "dup_eli": 0, "empty": 0, "notes": 0, "ocr_lines": 0,
263
+ "ocr_noise": 0, "pii_masks": 0}
264
+ jsonl = out_dir / f"{KEY}.jsonl"
265
+ with jsonl.open("w", encoding="utf-8") as f, \
266
+ ProcessPoolExecutor(args.workers, initializer=_init, initargs=(rules_path,)) as pool:
267
+ for repo, rev in DATASETS.items():
268
+ name = repo.split("/")[1]
269
+ path = hf_hub_download(repo, f"data/{name}.parquet", repo_type="dataset", revision=rev,
270
+ cache_dir=cache_dir)
271
+ cols = ["eli", "source_pdf", "pdf_sha256", "converter", "markdown"]
272
+ rows = []
273
+ for row in pq.read_table(path, columns=cols).to_pylist():
274
+ tot["rows"] += 1
275
+ pub, year, pos = ELI_RE.match(row["eli"]).groups()
276
+ entry = pdf_only(pub, int(year), flags).get(int(pos))
277
+ if entry is None:
278
+ tot["not_pdf_only"] += 1
279
+ continue
280
+ row["created"] = act_date(entry, int(year))
281
+ if row["eli"] in seen:
282
+ tot["dup_eli"] += 1
283
+ continue
284
+ seen.add(row["eli"])
285
+ rows.append(row)
286
+ for rec, st in pool.map(convert, rows, chunksize=64):
287
+ for k in ("notes", "ocr_lines", "ocr_noise", "pii_masks"):
288
+ tot[k] += st[k]
289
+ if rec is None:
290
+ tot["empty"] += 1
291
+ continue
292
+ f.write(json.dumps({k: rec[k] for k in FIELDS}, ensure_ascii=False) + "\n")
293
+ tot["kept"] += 1
294
+ print(f" {repo}@{rev[:8]}: {len(rows):,} PDF-only acts", flush=True)
295
+ subprocess.run(["zstd", "-q", "-f", "-19", "-T0", str(jsonl), "-o", str(jsonl) + ".zst"], check=True)
296
+ jsonl.unlink()
297
+ print(json.dumps(tot, indent=1))
298
+ (out_dir / f"{KEY}.fetch_stats.json").write_text(json.dumps(tot, indent=1))
299
+
300
+
301
+ if __name__ == "__main__":
302
+ main()
src/sources.py CHANGED
@@ -774,6 +774,32 @@ SOURCES = {
774
  "is_ocr": False,
775
  "custom_datasheet": True,
776
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
777
  }
778
 
779
  # Fallback stamp for a source with no recorded "added" date of its own.
 
774
  "is_ocr": False,
775
  "custom_datasheet": True,
776
  },
777
+ "eli_pdf_acts": {
778
+ "added": "2026-10-01",
779
+ "release": None,
780
+ "file_key": "eli_pdf_acts", # fetched by src/fetch_eli_pdf_acts.py, NOT via SpeakLeash
781
+ "pretty": "Dziennik Ustaw + Monitor Polski acts published only as PDF",
782
+ "license": "public-domain (official documents)",
783
+ "license_spdx": "CC0-1.0",
784
+ "traceable": "Normative acts (art. 4 pkt 1) and official documents (art. 4 pkt 2) "
785
+ "are not subject to copyright under the Polish Copyright Act, the "
786
+ "same basis as dziennik_ustaw. Per-record source_url and pdf_sha256 "
787
+ "in the attribution sidecar pin the official PDF on api.sejm.gov.pl.",
788
+ "upstream": "https://api.sejm.gov.pl/eli/acts",
789
+ "provenance": "Acts whose ELI list entry has textHTML=false (the ones "
790
+ "src/fetch_eli.py skips): official PDFs converted by eli2md "
791
+ "(published as PolskiAgentW/{monitor-polski-md,dziennik-ustaw-md,"
792
+ "dziennik-ustaw-2000-2011-md}, pinned revisions), markdown to text, "
793
+ "OCR-noise lines dropped, NFKC/whitespace normalization, NERGAL "
794
+ "rules layer (scrub_pii.py) only - re-run through full "
795
+ "SlayerLab/NERGAL before release.",
796
+ "domain": "legal",
797
+ "created": "1999-09-30, 2026-09-29",
798
+ "is_ocr": False, # partly OCR'd; the document-level alpha gate would drop 20% (tables, dates)
799
+ "preserve_id": True, # ids carry the ELI address
800
+ "preserve_created": True, # the act's own date
801
+ "custom_datasheet": True,
802
+ },
803
  }
804
 
805
  # Fallback stamp for a source with no recorded "added" date of its own.
src/test_eli_pdf_acts_contract.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Contract for eli_pdf_acts: markdown -> text normalization and the shipped shard."""
2
+ import json
3
+ import re
4
+ import sys
5
+ import unittest
6
+ from pathlib import Path
7
+
8
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
9
+
10
+ from fetch_eli_pdf_acts import ELI_RE, FIELDS, KEY, LICENSE, act_date, md_to_text, normalize, ocr_noise
11
+
12
+ ROOT = Path(__file__).resolve().parents[1]
13
+ DATA = ROOT / "data" / KEY
14
+ SCHEMA = ["id", "text", "source", "added", "created", "token_count", "license", "author"]
15
+ ID_RE = re.compile(rf"^{KEY}_(DU|MP)_(\d{{4}})_(\d+)$")
16
+
17
+
18
+ class MarkdownToTextTest(unittest.TestCase):
19
+ def test_title_heading_dropped_units_kept(self):
20
+ md = "# Ustawa z dnia 1 lipca 2005 r. o czymś\n\nUSTAWA\n\n##### Art. 1.\n\n1. Treść **ważna**."
21
+ text = normalize(md_to_text(md)[0]) # the order convert() uses
22
+ self.assertNotIn("#", text)
23
+ self.assertTrue(text.startswith("USTAWA"))
24
+ self.assertIn("Art. 1.", text)
25
+ self.assertIn("1. Treść ważna.", text)
26
+
27
+ def test_converter_notes_dropped_ocr_kept(self):
28
+ md = ("# T\n\n> [Strona 3 PDF nie ma czytelnej warstwy tekstowej. Tekst poniżej odczytał OCR (tesseract).]\n\n"
29
+ "> Załącznik nr 1 do rozporządzenia Ministra Zdrowia\n\n> jo] O| OO; ry 2\n\n> 58")
30
+ text, st = md_to_text(md)
31
+ self.assertNotIn("Strona 3", text)
32
+ self.assertIn("Załącznik nr 1 do rozporządzenia Ministra Zdrowia", text)
33
+ self.assertNotIn("jo]", text)
34
+ self.assertNotIn("58", text)
35
+ self.assertEqual(st["notes"], 1)
36
+ self.assertEqual(st["ocr_noise"], 2)
37
+
38
+ def test_citation_heavy_ocr_line_is_not_noise(self):
39
+ self.assertFalse(ocr_noise("Na podstawie art. 91 ust. 2 ustawy z dnia 6 kwietnia 1990 r. o Policji "
40
+ "(Dz. U. Nr 30, poz. 179, z 1991 r. Nr 94, poz. 422 i Nr 107, poz. 461)"))
41
+ self.assertTrue(ocr_noise("0709 60 100 0709 90 0709 90 90 0 ex 0709 90 90 0"))
42
+
43
+ def test_footnotes_and_escapes(self):
44
+ text, _ = md_to_text("# T\n\nMINISTRA KULTURY[^1]\n\nA \\| B \\- C \\[x\\] \\d{11}\n\n[^1]: Minister Kultury kieruje działem.")
45
+ self.assertIn("MINISTRA KULTURY1)", text)
46
+ self.assertIn("1) Minister Kultury kieruje działem.", text)
47
+ self.assertIn("A | B - C [x] \\d{11}", text) # markdown escapes undone, other backslashes kept
48
+
49
+ def test_signature_italics_dropped_printed_asterisks_kept(self):
50
+ md = ("# T\n\n*Prezes Rady Ministrów: D. Tusk*\n\n*) Należy wpisać bieżący rok.*\n\n"
51
+ "*3926 90 910 - - - - Wyprodukowane z arkusza *\n\n> *Minister Zdrowia: X*")
52
+ lines = normalize(md_to_text(md)[0]).split("\n\n")
53
+ self.assertEqual(lines[0], "Prezes Rady Ministrów: D. Tusk")
54
+ self.assertEqual(lines[1], "*) Należy wpisać bieżący rok.*")
55
+ self.assertEqual(lines[2], "*3926 90 910 - - - - Wyprodukowane z arkusza *")
56
+ self.assertEqual(lines[3], "*Minister Zdrowia: X*") # OCR text is not eli2md markup
57
+
58
+ def test_normalize_unicode_and_whitespace(self):
59
+ raw = "a\u00a0b\u200b c\u00ad d\x07 e \n\n\n\n f\ufb01"
60
+ self.assertEqual(normalize(raw), "a b c d e\n\nffi")
61
+ self.assertEqual(normalize("„Art. 5. …”"), "„Art. 5. ...”") # NFKC folds the ellipsis only
62
+
63
+
64
+ class ActDateTest(unittest.TestCase):
65
+ def test_title_date_wins_over_api_typo(self):
66
+ entry = {"title": "Obwieszczenie Marszałka Sejmu z dnia 27 października 2020 r. w sprawie …",
67
+ "announcementDate": "2020-11-27", "promulgation": "2020-11-20"}
68
+ self.assertEqual(act_date(entry, 2020), "2020-10-27")
69
+ self.assertEqual(act_date({"title": "Ustawa z dnia 17 grudnia 2025 r. o …"}, 2026), "2025-12-17")
70
+
71
+ def test_other_documents_date_falls_back_to_publication(self):
72
+ entry = {"title": "Umowa między Rządem RP a Rządem Związkowym z dnia 18 lipca 1972 r. …",
73
+ "promulgation": "2000-04-12"}
74
+ self.assertEqual(act_date(entry, 2000), "2000-04-12")
75
+
76
+ def test_no_credible_date(self):
77
+ self.assertEqual(act_date({"title": "Umowa sporządzona dnia 22 lipca 1944 r.", "promulgation": "1997-08-21"}, 2022), "")
78
+
79
+
80
+ @unittest.skipUnless((DATA / f"{KEY}.parquet").exists(), "shard not built")
81
+ class ShardContractTest(unittest.TestCase):
82
+ @classmethod
83
+ def setUpClass(cls):
84
+ import pyarrow.parquet as pq
85
+ cls.table = pq.read_table(DATA / f"{KEY}.parquet", columns=[c for c in SCHEMA if c != "text"])
86
+ cls.stats = json.loads((DATA / f"{KEY}.stats.json").read_text())
87
+
88
+ def test_schema(self):
89
+ import pyarrow.parquet as pq
90
+ self.assertEqual(pq.ParquetFile(DATA / f"{KEY}.parquet").schema_arrow.names, SCHEMA)
91
+
92
+ def test_uniform_source_and_license(self):
93
+ self.assertEqual(set(self.table.column("source").to_pylist()), {KEY})
94
+ self.assertEqual(set(self.table.column("license").to_pylist()), {LICENSE})
95
+
96
+ def test_ids_are_unique_eli_addresses(self):
97
+ ids = self.table.column("id").to_pylist()
98
+ self.assertEqual(len(ids), len(set(ids)))
99
+ self.assertTrue(all(ID_RE.match(i) for i in ids))
100
+
101
+ def test_positive_tokens_and_dates(self):
102
+ self.assertGreater(min(self.table.column("token_count").to_pylist()), 0)
103
+ from sources import SOURCES
104
+ fallback = SOURCES[KEY]["created"]
105
+ created = self.table.column("created").to_pylist()
106
+ self.assertTrue(all(re.match(r"^\d{4}-\d{2}-\d{2}$", c) or c == fallback for c in created))
107
+ self.assertLess(sum(c == fallback for c in created), 50) # 33 on 2026-10-01
108
+
109
+ def test_stats_consistent(self):
110
+ self.assertEqual(self.stats["kept"], self.table.num_rows)
111
+ self.assertEqual(self.stats["tokens"], sum(self.table.column("token_count").to_pylist()))
112
+
113
+ def test_attribution_sidecar_matches_shard(self):
114
+ rows = [json.loads(ln) for ln in (DATA / f"{KEY}.attribution.jsonl").read_text().splitlines()]
115
+ self.assertEqual([r["id"] for r in rows], self.table.column("id").to_pylist())
116
+ for r in rows[:: max(1, len(rows) // 500)]:
117
+ self.assertEqual(set(r), set(FIELDS) - {"text"})
118
+ self.assertTrue(ELI_RE.match(r["eli"]))
119
+ self.assertEqual(r["source_pdf"], f"https://api.sejm.gov.pl/eli/acts/{r['eli']}/text.pdf")
120
+ self.assertRegex(r["pdf_sha256"], r"^[0-9a-f]{64}$")
121
+
122
+
123
+ if __name__ == "__main__":
124
+ unittest.main()