Datasets:
Download src/test_build_uzp_orzeczenia_pl.py from SlayerLab/polish-dynaword: direct link, hf CLI and curl.
- Browser
- Download file 6.15 kB
-
https://huggingface.co/datasets/SlayerLab/polish-dynaword/resolve/d3c7b3995a44abb8b801e25f33ce64ecc2755838/src/test_build_uzp_orzeczenia_pl.py
- Command line
-
hf download hf://datasets/SlayerLab/polish-dynaword@d3c7b3995a44abb8b801e25f33ce64ecc2755838/src/test_build_uzp_orzeczenia_pl.py
-
curl -L -o test_build_uzp_orzeczenia_pl.py https://huggingface.co/datasets/SlayerLab/polish-dynaword/resolve/d3c7b3995a44abb8b801e25f33ce64ecc2755838/src/test_build_uzp_orzeczenia_pl.py
6.15 kB
| import importlib.util | |
| from pathlib import Path | |
| SCRIPT = Path(__file__).with_name("build_uzp_orzeczenia_pl.py") | |
| SPEC = importlib.util.spec_from_file_location("build_uzp_orzeczenia_pl", SCRIPT) | |
| MODULE = importlib.util.module_from_spec(SPEC) | |
| SPEC.loader.exec_module(MODULE) | |
| def results_page(ids, counts="35694,34412,1277,3,2"): | |
| items = "".join( | |
| f'<div class="search-list-item">' | |
| f'<label>Organ wydający:</label> Krajowa Izba Odwoławcza' | |
| f'<p><label>Rodzaj dokumentu:</label> wyrok</p>' | |
| f'<p><label>Sygnatura:</label> KIO {i}/26</p>' | |
| f'<p><label>Data wydania:</label> 07-08-2026</p>' | |
| f'<a class="link-details" href="/Home/Details/{i}">Wyświetl szczegóły</a>' | |
| f'</div>' | |
| for i in ids) | |
| return f'<input type="hidden" value="{counts}" id="resultCounts" />' + items | |
| def details_page(doc_id=36097, kind="KIO", signature="KIO 3640/26"): | |
| return ( | |
| f'<html><body><label>Organ wydający</label> Krajowa Izba Odwoławcza' | |
| f'<label>Rodzaj dokumentu</label> postanowienie' | |
| f'<label>Data wydania rozstrzygnięcia</label> 07-08-2026' | |
| f'<label>Przewodniczący</label> Jan Kowalski' | |
| f'<label>Zamawiający</label> Szpital Miejski' | |
| f'<label>Miejscowość</label> Warszawa' | |
| f'<label>Sygnatura akt / Sposób rozstrzygnięcia</label> {signature} / umorzenie' | |
| f'<label>Kluczowe przepisy ustawy Pzp</label> art. 568 pkt 2' | |
| f'<a href="/Home/PdfContent/{doc_id}?Kind={kind}">Pobierz treść PDF</a>' | |
| f'</body></html>') | |
| def test_parse_result_items_extracts_records_and_totals(): | |
| records, totals = MODULE.parse_result_items(results_page([36097, 36096, 36095])) | |
| assert [r["doc_id"] for r in records] == [36097, 36096, 36095] | |
| assert records[0]["organ"].startswith("Krajowa Izba") | |
| assert records[0]["doc_type"] == "wyrok" | |
| assert records[0]["signature"] == "KIO 36097/26" | |
| assert records[0]["issued"] == "07-08-2026" | |
| assert totals == [35694, 34412, 1277, 3, 2] | |
| def test_parse_counts_maps_kinds(): | |
| counts = MODULE.parse_counts(results_page([1])) | |
| assert counts == {"ALL": 35694, "KIO": 34412, "SO": 1277, "SA": 3, "SN": 2} | |
| def test_parse_details_extracts_metadata_and_pdf_link(): | |
| details = MODULE.parse_details(details_page(), 36097) | |
| assert details["doc_id"] == 36097 | |
| assert details["organ"] == "Krajowa Izba Odwoławcza" | |
| assert details["chairman"] == "Jan Kowalski" | |
| assert details["purchaser"] == "Szpital Miejski" | |
| assert details["signature"] == "KIO 3640/26 / umorzenie" | |
| assert details["pdf_path_url"] == "https://orzeczenia.uzp.gov.pl/Home/PdfContent/36097?Kind=KIO" | |
| assert details["pdf_kind"] == "KIO" | |
| def test_parse_details_so_kind(): | |
| details = MODULE.parse_details(details_page(9036, "SO", "X Ga 286/13"), 9036) | |
| assert details["pdf_path_url"].endswith("?Kind=SO") | |
| assert details["pdf_kind"] == "SO" | |
| def test_iso_date_dd_mm_yyyy(): | |
| assert MODULE.iso_date("07-08-2026") == "2026-08-07" | |
| assert MODULE.iso_date("03-10-2013") == "2013-10-03" | |
| assert MODULE.iso_date("") == "" | |
| def test_normalize_drops_repeated_signature_and_page_numbers(): | |
| raw = "Sygn. akt KIO 1/26\nPierwszy akapit\n3\nSygn. akt KIO 1/26\nDrugi akapit" | |
| out = MODULE.normalize(raw) | |
| assert out.count("Sygn. akt") == 1 | |
| assert "\n3\n" not in "\n" + out + "\n" | |
| assert "Pierwszy akapit" in out and "Drugi akapit" in out | |
| def test_normalize_repairs_line_wraps(): | |
| raw = "To jest dłu-\ngi wyraz\noraz kolejna\nlinia tekstu." | |
| out = MODULE.normalize(raw) | |
| assert "długi wyraz" in out | |
| assert "oraz kolejna linia tekstu." in out | |
| def test_redact_pii_masks_patterns(): | |
| text = "Kontakt: jan@example.com tel. 601 234 567 PESEL 44051401458 " \ | |
| "rachunek 12 3456 7890 1234 5678 9012 3456 IP 10.0.0.1" | |
| out, counts = MODULE.redact_pii(text) | |
| assert "[REDACTED:EMAIL]" in out | |
| assert "[REDACTED:PHONE]" in out | |
| assert "[REDACTED:ID]" in out | |
| assert "[REDACTED:ACCOUNT]" in out | |
| assert "[REDACTED:IP]" in out | |
| assert "jan@example.com" not in out | |
| assert counts["email"] == 1 and counts["national_identifier"] == 1 | |
| def test_redact_pii_compressed_ipv6(): | |
| out, counts = MODULE.redact_pii("adres ::1 oraz 2001:db8::ff00:42:8329 w tekście") | |
| assert "[REDACTED:IP]" in out | |
| assert counts["ipv6"] >= 1 | |
| def test_filter_sketch_drops_boilerplate_shingles(): | |
| boiler = MODULE.shingle_sketch("Krajowa Izba Odwoławcza w składzie Przewodniczący") | |
| own_a = MODULE.shingle_sketch("sygnatura sprawa alfa unikalna treść alfa") | |
| own_b = MODULE.shingle_sketch("sygnatura sprawa beta unikalna treść beta") | |
| df = MODULE.shingle_document_frequencies([boiler | own_a, boiler | own_b]) | |
| max_df = 1 # boiler appears in both docs -> df=2 > max_df | |
| filtered = MODULE.filter_sketch(boiler | own_a, df, max_df) | |
| assert filtered <= own_a | |
| assert filtered == own_a | |
| def test_near_duplicate_index_matches_exhaustive(): | |
| base = " ".join(f"słowo{i}" for i in range(300)) | |
| near = MODULE.NearDuplicateIndex() | |
| near.add("doc_a", MODULE.shingle_sketch(base)) | |
| hit, score = near.find(MODULE.shingle_sketch(base + " dodatkowy koniec")) | |
| assert hit == "doc_a" and score >= 0.90 | |
| distinct = " ".join(f"inne{i}" for i in range(300)) | |
| assert near.find(MODULE.shingle_sketch(distinct)) == (None, 0.0) | |
| # regression: index must agree with exhaustive pairwise comparison | |
| sketches = {f"d{i}": MODULE.shingle_sketch(" ".join(f"x{i}w{j}" for j in range(200))) | |
| for i in range(30)} | |
| sketches["dup"] = MODULE.shingle_sketch(" ".join(f"x0w{j}" for j in range(200))) | |
| index = MODULE.NearDuplicateIndex() | |
| added = {} | |
| for rid, sk in sketches.items(): | |
| other, score = index.find(sk) | |
| expected = None | |
| for oid, osk in added.items(): | |
| inter = len(sk & osk) | |
| s = inter / max(len(sk) + len(osk) - inter, 1) | |
| if s >= 0.90: | |
| expected = oid | |
| break | |
| assert (other is not None) == (expected is not None), rid | |
| index.add(rid, sk) | |
| added[rid] = sk | |