wolne_lektury: drop 63 docs that duplicate eltec_pol novels (6,141 -> 6,078 docs)

#67
by ppuzio - opened
artifacts/source_findings.md CHANGED
@@ -1358,3 +1358,165 @@ S1, S8, C4; <https://www.gov.pl/web/gov/prawa-autorskie> (read 2026-10-05).
1358
 
1359
  **Lesson** — de-identification that replaces URLs also removes the provenance needed
1360
  to screen reposts. Record the credited domain before masking URLs.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1358
 
1359
  **Lesson** — de-identification that replaces URLs also removes the provenance needed
1360
  to screen reposts. Record the credited domain before masking URLs.
1361
+
1362
+ ## global_voices — partner republications dropped (2026-10-06)
1363
+
1364
+ **Verdict** — `admitted` with 114 posts withheld (polish-dynaword-v2 #50). The source
1365
+ goes from 2,040 docs / 10,073,628 chars / 3,715,020 tokens to 1,926 / 9,358,071 /
1366
+ 3,453,918. The posts come from 51 outlets. The new `src/clean_global_voices.py` filters
1367
+ the v0.2.5 Parquet and sidecar, pinned by SHA-256. `src/test_global_voices_contract.py`
1368
+ checks that no shipped row matches the rule.
1369
+
1370
+ **Reason** — Global Voices licenses "content created by Global Voices" under CC BY 3.0.
1371
+ A post that republishes a partner's article under a content-sharing agreement or with
1372
+ permission stays the partner's work.
1373
+ - **Where the rule looks.** It reads only the first 700 and last 350 characters, where
1374
+ the editorial note sits. A rule fires only on a sentence about the post itself that
1375
+ does not name Global Voices, so news reporting ("raport opublikowany przez UNESCO")
1376
+ and GV's own projects do not count. Sentences whose subject is an image are skipped
1377
+ too.
1378
+ - **Rule counts** (a post can match several):
1379
+ - originally: 69
1380
+ - agreement: 56
1381
+ - published_by: 51
1382
+ - partnership: 11
1383
+ - permission: 5
1384
+ - republished: 5
1385
+ - written_for: 3
1386
+ - non_commercial: 3
1387
+ - listed by hand: 3 (21466, 27005, 32352)
1388
+ - **Hand check.**
1389
+ - Every one of the 114 drops was read, and the English original was consulted where
1390
+ the note was unclear.
1391
+ - 25 rule matches are kept by hand with a stated reason:
1392
+ - 12 cross-posts from the author's own blog;
1393
+ - 7 posts GV wrote for the ISN blog;
1394
+ - 3210, a GV post that another outlet republished;
1395
+ - 2 notes dating GV's own English original;
1396
+ - 3 news mentions.
1397
+ - All 43 posts where the gating removed a raw match were checked. They are image
1398
+ credits, news and GV projects.
1399
+ - 15 partner-organisation accounts with no republication note (e.g. 350.org 22567,
1400
+ Metamorphosis 33071) were checked against the English page and kept.
1401
+ - **Outlets.**
1402
+ - PRI/The World 21
1403
+ - The Stand News 8
1404
+ - Hong Kong Free Press 7
1405
+ - Agência Pública 6
1406
+ - Metamorphosis/Meta.mk 5
1407
+ - 350.org 5
1408
+ - Eurasianet 3
1409
+ - Freemuse 3
1410
+ - The Irrawaddy 3
1411
+ - 2 each: Balkan Diskurs, Ensia, Kurtural, Loa, MigraMundo, NACLA, Nepali
1412
+ Times/Himalkhabar, Premium Times, Syria Untold, Teplitsa, Transitions
1413
+ - 1 each: 88 Bar, APC.org, Afroféminas, Azerbaijan Internet Watch, Baynana, Bumaga,
1414
+ CHRI, Cari-Bois, Chaikhana, Common Dreams, Connectas, Doha News, Fundación MEPI,
1415
+ GCHR, Hive-Mind/EJO, Iran Voices, New America Media, OC Media, Periodismo de
1416
+ Barrio, Promundo, Russia Post, Sin Embargo, Syria Deeply, TJournal, Tea After
1417
+ Twelve, The Isaan Record, The Moscow Times, VideoVolunteers, WITNESS,
1418
+ inmediahk.net, openDemocracy.
1419
+ - **Delta against the audit's 64.** The audit used outlet names plus an agreement
1420
+ regex, and it recorded neither the list nor the script. Its "17 PRI" is an
1421
+ undercount: all 21 posts credited to PRI/PRX's The World carry a republication note.
1422
+ Most of the remaining difference is outlets the audit's name list did not cover,
1423
+ such as The Stand News (8) and Agência Pública (6). The Hub PR has per-document
1424
+ evidence.
1425
+ - **Borderline; dropped and flagged for review.**
1426
+ - Freemuse ×3: the note allows republication "by non-commercial media" only.
1427
+ - Bumaga 30003: a shorter version of the author's article for Bumaga.
1428
+ - Hive-Mind/EJO 34820.
1429
+ - openDemocracy 29544: "under a Creative Commons licence", version not stated.
1430
+ - Transitions 34277: "powstał dzięki umowie partnerskiej", possibly a co-production.
1431
+ - 32352: built on two Meta.mk texts.
1432
+
1433
+ **Lesson** — the licence covers what the publisher created. A per-post editorial note
1434
+ is the only signal of a partner's work, so the filter has to read the note and not only
1435
+ the byline.
1436
+
1437
+ ## `1000_novels` rescreened: unknown authors fail closed, translator death years cited
1438
+
1439
+ **Investigated:** 2026-10-06
1440
+ **Verdict:** keep 888 of 1,000 texts as `public-domain` (was 837); drop 18 in copyright
1441
+ and 94 unresolved. Tracks slayerlabs/polish-dynaword-v2#44.
1442
+
1443
+ ### Verified
1444
+
1445
+ - Screen defect: a known public-domain translator cleared an author whose death year
1446
+ was unknown. `1000_novels_0733` (author "Roux", unidentified) shipped in the
1447
+ first rebuild this way. An unknown author now fails closed unless the work is listed
1448
+ as anonymous.
1449
+ - Translator death years now come from Biblioteka Narodowa / VIAF authority records,
1450
+ cited in `polish-dynaword-v2/scripts/novels_rights_screen.py`. Józef Pracki d. 1882,
1451
+ Edmund Cięglewicz d. 1928, Stanisław Sierosławski d. 1941, Bolesław Londyński d. 1928
1452
+ (22 texts), Ludwik Jenike d. 1903, Adam Stögbauer d. 1916, Kazimierz Bronikowski
1453
+ d. 1909, Maria Cumft-Pieńkowska d. 1920, Izydor Berman d. 1942, Konrad Drzewiecki
1454
+ d. 1922, Stefan Frycz d. 1960.
1455
+ - "tłum. A. W." on 29 Chekhov texts is Antoni Lange (d. 1929): BN catalogues their
1456
+ source edition (*Śmierć urzędnika*, Bibljoteka Groszowa 1926) with "nazwa właśc. tł.:
1457
+ Antoni Lange".
1458
+ - `1000_novels_0981` (Seneca's letter, "PRZEKŁAD", no name) is Żuławski's own
1459
+ translation in his 1914 collection *Bajka o człowieku szczęśliwym*. It is now
1460
+ credited to Seneca with Żuławski as translator.
1461
+ - "Roux" is Saint-Pol-Roux (d. 1940), so `0733` stays in on a cited death year.
1462
+ - `1000_novels_0462` (*Wola mocy*): BN credits Stefan Frycz (d. 1960) as
1463
+ co-translator. It is dropped although its Wolne Lektury footer says public domain. The
1464
+ screen's footer cross-check allowlists it by name.
1465
+ - Net: 53 unresolved and 10 Wolne-Lektury-footer rows move to public domain by term;
1466
+ 1 Wolne-Lektury-footer row moves to in copyright.
1467
+
1468
+ ### Not established
1469
+
1470
+ - "A. L." (`1000_novels_0734`, Schopenhauer 1901): BN records the cryptonym only. The
1471
+ row still rests on its Wolne Lektury footer (Inferred).
1472
+ - Edition rights (Art. 99¹–99²); dedup against `wolne_lektury` / `eltec_pol` (#45).
1473
+
1474
+ **Lesson:** a Wolne Lektury public-domain footer is a claim, not evidence. One of the
1475
+ 12 it covered had a translator who died in 1960.
1476
+
1477
+ **Update (2026-10-06, maintainer decision):** the screen no longer keeps a row on a
1478
+ Wolne Lektury public-domain footer. "A. L." (`1000_novels_0734`) now fails closed as
1479
+ unresolved, so the release keeps 887 texts and drops 18 in copyright and 95 unresolved.
1480
+ `src/clean_1000_novels.py` pins the screen CSV by SHA-256
1481
+ (`7fefc75f8fcbd07e5ec98842276765ffef9520b6acb4e24b4751c67cc3d2081c`, also in
1482
+ `1000_novels.license-evidence.json`).
1483
+
1484
+ ## wolne_lektury — eltec_pol duplicates dropped (2026-10-06)
1485
+
1486
+ **Verdict** — kept, 63 documents dropped: 6,141 → 6,078 documents, 103,009,797 →
1487
+ 90,654,820 tokens (input: the v0.2.5 Parquet, unchanged since v0.2.1). Each dropped
1488
+ document is a novel, or one tome of a novel, that `eltec_pol` also carries. 50 ELTeC
1489
+ novels are concerned, and `eltec_pol` stays whole (maintainer decision A,
1490
+ polish-dynaword-v2 #72). The filter is `src/clean_wolne_lektury.py` and the pair list is
1491
+ `data/wolne_lektury/wolne_lektury.eltec_pairs.tsv`.
1492
+ - Score: the share of a WL document's 5-word shingles found in the ELTeC novel that
1493
+ shares the most with it. Tokenisation follows `near_dedup`, and a trailing WL footer is
1494
+ cut first (no WL row has one). Containment is used, not Jaccard, because WL splits
1495
+ novels into tomes: Chłopi has 4, Faraon, Nad Niemnem and Stara baśń have 3.
1496
+ - Threshold 0.9, in an empty stretch: no document scores between 0.7588 and 0.9636. All
1497
+ 63 documents above it pair with an ELTeC novel by the same author and title (Żuławski's
1498
+ two WL documents are headed with the trilogy's title).
1499
+ - Hand-checked: all 3 documents between 0.3 and 0.9, the 3 between 0.9 and 0.99, and 10
1500
+ sampled at ≥ 0.99 (seed 72). In 12 of the 13 drops checked, the unmatched shingles
1501
+ form short scattered runs of at most 27 words (title head, spelling variants). The
1502
+ exception is Dzieje grzechu (0.9879): its WL copy ends with a "Dodatek" of draft
1503
+ chapters, about 1,800 words that ELTeC lacks. It is dropped with the novel.
1504
+ - Kept and listed as `keep_partial`: both WL tomes of Mniszek's Trędowata (0.7588 and
1505
+ 0.6473 against POL0051). The ELTeC text is shorter: about 121,000 words against WL's
1506
+ 162,000. 95% of the ELTeC shingles are in WL's tomes, and the WL text missing from
1507
+ ELTeC comes in runs of up to 5,418 words. The shared part stays duplicated across the
1508
+ two sources. Also kept: Kochanowski's Pieśń IX from Pieśni, księgi wtóre (0.4267),
1509
+ which Łoziński's Oko proroka quotes.
1510
+ - Below 0.3 (not listed, not dropped): 6 documents at 0.10–0.22, all poems of at most
1511
+ 2,321 tokens by Mickiewicz, Kochanowski and Miciński; their overlap with the paired
1512
+ novels was not inspected. Nothing scores between 0.2203 and 0.4267.
1513
+
1514
+ **Reason** — 51 of the 100 ELTeC novels duplicate WL texts. ELTeC's CC BY 4.0 licence
1515
+ is the clean one (`rights_audit_2026-10/reports/literary.md`: eltec_pol CLEAN). WL
1516
+ licence labels are not touched here; #57 relabels them per row.
1517
+
1518
+ References: polish-dynaword-v2 #72 (decision), #45 (method);
1519
+ `rights_audit_2026-10/literary/eltec_meta.tsv` (ELTeC file names and titles).
1520
+
1521
+ **Lesson** — Jaccard near-dedup misses a novel that one source splits into tomes.
1522
+ Measure containment from the split side.
data/1000_novels/1000_novels.attribution.jsonl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5519bac2b956db503b3c80312a9adbeaf77bc6e762a57a725a10a288c14eaa46
3
- size 304759
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ca43c45683ca0ba08aeda5d9f1089c3ca699450e2fca25ff972736f2024f603
3
+ size 323093
data/1000_novels/1000_novels.license-evidence.json CHANGED
@@ -1,19 +1,19 @@
1
  {
2
- "checked_at": "2026-10-05",
3
  "upstream": "https://clarin-pl.eu/dspace/handle/11321/312",
4
  "upstream_record_license": "CC BY 4.0, stated on a metadata-only record (read 2026-09-30); it does not license the texts",
5
  "upstream_rights_statement": "CLARIN-PL (Tomasz Naskręt), email reply received 2026-10-05: the handle currently contains metadata only and does not provide the corpus files for download or redistribution; CLARIN-PL does not distribute the individual novels or translations and does not hold documentation concerning the rights to the individual texts.",
6
  "text_license": "public-domain",
7
- "test": "Polish law (Art. 36): the author and every credited translator died in 1955 or earlier; a credited name without a curated death year fails closed. 12 rows rely on the retained Wolne Lektury footer stating no economic copyright (Inferred: Wolne Lektury's claim, not re-derived).",
8
  "not_assessed": "Edition and critical-edition rights (Art. 99^1-99^2).",
9
  "screen": "polish-dynaword-v2/evidence/1000_novels_rights_screen.csv",
10
  "screen_script": "polish-dynaword-v2/scripts/novels_rights_screen.py",
 
11
  "release_scope": {
12
  "screened": 1000,
13
- "kept": 837,
14
- "pd_by_term": 825,
15
- "pd_per_wolne_lektury": 12,
16
- "dropped_in_copyright": 17,
17
- "dropped_unresolved": 146
18
  }
19
  }
 
1
  {
2
+ "checked_at": "2026-10-06",
3
  "upstream": "https://clarin-pl.eu/dspace/handle/11321/312",
4
  "upstream_record_license": "CC BY 4.0, stated on a metadata-only record (read 2026-09-30); it does not license the texts",
5
  "upstream_rights_statement": "CLARIN-PL (Tomasz Naskręt), email reply received 2026-10-05: the handle currently contains metadata only and does not provide the corpus files for download or redistribution; CLARIN-PL does not distribute the individual novels or translations and does not hold documentation concerning the rights to the individual texts.",
6
  "text_license": "public-domain",
7
+ "test": "Polish law (Art. 36): the author and every credited translator died in 1955 or earlier; an author or credited name without a curated death year fails closed (anonymous works excepted), and a credited translator who died after 1955 makes the text in copyright. Translator death years added 2026-10-06 cite Biblioteka Narodowa / VIAF authority records in the screen script. A Wolne Lektury public-domain footer does not substitute for a death year: 1000_novels_0734 (translator \"A.L.\", not identified) is dropped as unresolved, and 1 row (1000_novels_0462, co-translator Stefan Frycz d. 1960) is dropped against its Wolne Lektury public-domain footer.",
8
  "not_assessed": "Edition and critical-edition rights (Art. 99^1-99^2).",
9
  "screen": "polish-dynaword-v2/evidence/1000_novels_rights_screen.csv",
10
  "screen_script": "polish-dynaword-v2/scripts/novels_rights_screen.py",
11
+ "screen_sha256": "7fefc75f8fcbd07e5ec98842276765ffef9520b6acb4e24b4751c67cc3d2081c",
12
  "release_scope": {
13
  "screened": 1000,
14
+ "kept": 887,
15
+ "pd_by_term": 887,
16
+ "dropped_in_copyright": 18,
17
+ "dropped_unresolved": 95
 
18
  }
19
  }
data/1000_novels/1000_novels.md CHANGED
@@ -8,7 +8,7 @@
8
  - **Language:** Polish (pl)
9
  - **License:** `public-domain` (public domain in Poland; per-row basis in `1000_novels.attribution.jsonl`)
10
  - **Created (range):** unknown
11
- - **Added:** 2026-07-02; rebuilt 2026-10-05 as the public-domain subset
12
 
13
  ## Licensing — traceable basis
14
  The CLARIN-PL record states CC BY 4.0, but CLARIN-PL confirmed on 2026-10-05 that the
@@ -21,41 +21,45 @@ script `polish-dynaword-v2/scripts/novels_rights_screen.py`):
21
 
22
  | status | texts | released |
23
  |---|---:|---|
24
- | public domain by term: the author and every credited translator died in 1955 or earlier (Art. 36) | 825 | yes |
25
- | marked public domain by Wolne Lektury in the retained footer | 12 | yes |
26
- | in copyright; published by Wolne Lektury under CC BY-SA 3.0 | 17 | no |
27
- | author or translator not verified, or the text does not match its file | 146 | no |
28
 
29
- The 12 Wolne Lektury rows rely on Wolne Lektury's statement, not on a death year we
30
- verified. Edition and critical-edition rights (Art. 99¹–99²) are not assessed.
 
 
 
 
31
 
32
  ## Attribution
33
  The `author` column credits the author and, for translations, the translator:
34
  `Hans Christian Andersen (tłum. Cecylia Niewiadomska)`. `1000_novels.attribution.jsonl`
35
  has, per row: author, author's death year, translator, title, how the title was read
36
- (`file`: header text matching the CLARIN file name, 790; `position`: the line beside the
37
- author line, 32; `manual`: read by hand, 15), CLARIN file name, screen status and basis.
38
 
39
  ## Provenance
40
  Pulled from SpeakLeash's public redistribution (`speakleash-ds-pub`, key
41
  `1000_novels_corpus_CLARIN-PL`) of the CLARIN-PL corpus; row *i* matches the *i*-th file
42
  of the CLARIN listing. Rebuilt by `src/clean_1000_novels.py` from the v0.2.5 Parquet
43
- (SHA-256 pinned in the script). Text, `added`, `created` and `token_count` are unchanged.
 
44
 
45
  ## Statistics
46
  | documents | characters | tokens (tiktoken proxy) |
47
  |---:|---:|---:|
48
- | 837 | 129,722,658 | 51,765,528 |
49
 
50
  ## Per-document license metadata
51
  | license | documents |
52
  |---|---:|
53
- | `public-domain` | 837 |
54
 
55
- Author metadata present for **837** documents.
56
 
57
  ## Filters applied
58
- - rights screen: read 1,000 → kept 837 (dropped 17 in copyright, 146 unresolved)
59
  - no length, language, deduplication or OCR filters in this rebuild
60
 
61
  Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
 
8
  - **Language:** Polish (pl)
9
  - **License:** `public-domain` (public domain in Poland; per-row basis in `1000_novels.attribution.jsonl`)
10
  - **Created (range):** unknown
11
+ - **Added:** 2026-07-02; rebuilt 2026-10-05 as the public-domain subset; rescreened 2026-10-06
12
 
13
  ## Licensing — traceable basis
14
  The CLARIN-PL record states CC BY 4.0, but CLARIN-PL confirmed on 2026-10-05 that the
 
21
 
22
  | status | texts | released |
23
  |---|---:|---|
24
+ | public domain by term: the author and every credited translator died in 1955 or earlier (Art. 36) | 887 | yes |
25
+ | in copyright: 17 published by Wolne Lektury under CC BY-SA 3.0, 1 with a translator who died in 1960 | 18 | no |
26
+ | author or translator not verified, or the text does not match its file | 95 | no |
 
27
 
28
+ Translator death years added on 2026-10-06 cite Biblioteka Narodowa and VIAF authority
29
+ records, listed in the screen script. They identify the cryptonym "A. W." on 29 Chekhov
30
+ texts as Antoni Lange (d. 1929). They also show that *Wola mocy* (`1000_novels_0462`) was
31
+ co-translated by Stefan Frycz (d. 1960), so it is dropped although its Wolne Lektury footer
32
+ says public domain. A Wolne Lektury public-domain footer alone does not clear a text:
33
+ `1000_novels_0734` (translator "A.L.", not identified) is dropped as unresolved. Edition and critical-edition rights (Art. 99¹–99²) are not assessed.
34
 
35
  ## Attribution
36
  The `author` column credits the author and, for translations, the translator:
37
  `Hans Christian Andersen (tłum. Cecylia Niewiadomska)`. `1000_novels.attribution.jsonl`
38
  has, per row: author, author's death year, translator, title, how the title was read
39
+ (`file`: header text matching the CLARIN file name, 838; `position`: the line beside the
40
+ author line, 32; `manual`: read by hand, 17), CLARIN file name, screen status and basis.
41
 
42
  ## Provenance
43
  Pulled from SpeakLeash's public redistribution (`speakleash-ds-pub`, key
44
  `1000_novels_corpus_CLARIN-PL`) of the CLARIN-PL corpus; row *i* matches the *i*-th file
45
  of the CLARIN listing. Rebuilt by `src/clean_1000_novels.py` from the v0.2.5 Parquet
46
+ and the screen CSV, both pinned by SHA-256 in the script. Text, `added`, `created` and
47
+ `token_count` are unchanged.
48
 
49
  ## Statistics
50
  | documents | characters | tokens (tiktoken proxy) |
51
  |---:|---:|---:|
52
+ | 887 | 130,201,301 | 51,981,548 |
53
 
54
  ## Per-document license metadata
55
  | license | documents |
56
  |---|---:|
57
+ | `public-domain` | 887 |
58
 
59
+ Author metadata present for **887** documents.
60
 
61
  ## Filters applied
62
+ - rights screen: read 1,000 → kept 887 (dropped 18 in copyright, 95 unresolved)
63
  - no length, language, deduplication or OCR filters in this rebuild
64
 
65
  Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
data/1000_novels/1000_novels.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2947b057afa57204f3cc2d29752dfc2b2eb1a9482d9449716d849c5b172621d2
3
- size 63085970
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d568499837a4c2518396849462e16a2203996e077c7d551c0e17cda6f69fd82
3
+ size 63324274
data/1000_novels/1000_novels.stats.json CHANGED
@@ -1,29 +1,28 @@
1
  {
2
  "read": 1000,
3
- "kept": 837,
4
- "drop_rights": 163,
5
  "drop_short": 0,
6
  "drop_lang": 0,
7
  "drop_dup": 0,
8
  "drop_ocr": 0,
9
- "chars": 129722658,
10
- "tokens": 51765528,
11
  "licenses": {
12
- "public-domain": 837
13
  },
14
- "authors_with_value": 837,
15
  "license": "public-domain",
16
  "screen": {
17
- "pd_by_term": 825,
18
- "unresolved": 146,
19
- "in_copyright": 17,
20
- "pd_per_wolne_lektury": 12
21
  },
22
  "titles": {
23
- "file": 790,
24
  "position": 32,
25
- "manual": 15
26
  },
27
  "input_sha256": "27be09e5e2347dcf1a83e94b6c210ca26bdd89365bc3563e88ea5af9846990ea",
28
- "screen_sha256": "f5a68656f8ac7ff5c2a7a284094f944983ad8d33383e3d86cc40a1f31b9f2880"
29
  }
 
1
  {
2
  "read": 1000,
3
+ "kept": 887,
4
+ "drop_rights": 113,
5
  "drop_short": 0,
6
  "drop_lang": 0,
7
  "drop_dup": 0,
8
  "drop_ocr": 0,
9
+ "chars": 130201301,
10
+ "tokens": 51981548,
11
  "licenses": {
12
+ "public-domain": 887
13
  },
14
+ "authors_with_value": 887,
15
  "license": "public-domain",
16
  "screen": {
17
+ "pd_by_term": 887,
18
+ "unresolved": 95,
19
+ "in_copyright": 18
 
20
  },
21
  "titles": {
22
+ "file": 838,
23
  "position": 32,
24
+ "manual": 17
25
  },
26
  "input_sha256": "27be09e5e2347dcf1a83e94b6c210ca26bdd89365bc3563e88ea5af9846990ea",
27
+ "screen_sha256": "7fefc75f8fcbd07e5ec98842276765ffef9520b6acb4e24b4751c67cc3d2081c"
28
  }
data/global_voices/NOTICE.md CHANGED
@@ -6,6 +6,8 @@ original authors and translators under Creative Commons Attribution 3.0.
6
  Source: https://pl.globalvoices.org/
7
  License: https://creativecommons.org/licenses/by/3.0/
8
 
9
- Per-record contributor attribution is stored in the `author` column. The accompanying `global_voices.attribution.jsonl` sidecar additionally preserves each released article's title, canonical URL, license URL and modification notice. Twelve historical records had no machine-readable contributor field; full-text review recovered Didem Tali and Khalid Ibrahim for two of them. Ten records without an identifiable contributor use the explicitly organizational attribution `Global Voices`; this must not be interpreted as a known individual author.
 
 
10
 
11
  Binary media files are not included. Articles may nevertheless contain captions, URLs, social-media posts and quotations from third-party works; rights in those materials may remain with their respective authors. Article-level CC BY 3.0 is not asserted independently for photographs, videos, embeds or separately quoted works.
 
6
  Source: https://pl.globalvoices.org/
7
  License: https://creativecommons.org/licenses/by/3.0/
8
 
9
+ Per-record contributor attribution is stored in the `author` column. The accompanying `global_voices.attribution.jsonl` sidecar additionally preserves each released article's title, canonical URL, license URL and modification notice. Eleven released records had no machine-readable contributor field; full-text review recovered Khalid Ibrahim for one of them. Ten records without an identifiable contributor use the explicitly organizational attribution `Global Voices`; this must not be interpreted as a known individual author.
10
+
11
+ Posts that Global Voices republished from partner outlets (for example PRI's The World, Hong Kong Free Press, The Stand News, Meta.mk and 350.org) are not included. Their text remains the partner's work, and the Global Voices CC BY 3.0 grant does not demonstrably cover it.
12
 
13
  Binary media files are not included. Articles may nevertheless contain captions, URLs, social-media posts and quotations from third-party works; rights in those materials may remain with their respective authors. Article-level CC BY 3.0 is not asserted independently for photographs, videos, embeds or separately quoted works.
data/global_voices/global_voices.attribution.jsonl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ab8ad393c4453524c4f3d7fe89157bfca1d9f66f2a735815f3b1ebd405c8fa13
3
- size 1146354
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4709fcc9a53bb5d7d1a90eb29d2b6e8f398c28bfb842f9be0710353e9a4e691
3
+ size 1078938
data/global_voices/global_voices.md CHANGED
@@ -17,7 +17,7 @@ Global Voices describes its Lingua translations as human-made work performed by
17
 
18
  | documents | characters | tokens (`cl100k_base` proxy) |
19
  |---:|---:|---:|
20
- | 2,040 | 10,073,628 | 3,715,020 |
21
 
22
  The Parquet schema matches DynaWord:
23
 
@@ -34,7 +34,7 @@ Published files:
34
 
35
  Articles were acquired directly from the Polish Global Voices website through its official publication interfaces, rather than from a third-party corpus. Each released ID is linked to the corresponding canonical article URL in `global_voices.attribution.jsonl`.
36
 
37
- The source release contained 2,044 records. Four records below the minimum quality and length requirements were excluded, leaving 2,040 documents. The final source contains no exact duplicate documents.
38
 
39
  ## Cleaning
40
 
@@ -46,7 +46,19 @@ The cleaning process did not use machine translation or automatic speech transcr
46
 
47
  CC BY 3.0 was verified from the article-level license link published with each retained Global Voices article. Each released record carries `CC-BY-3.0` metadata. Contributor roles are preserved in the `author` column where available, distinguishing original authors from Polish translators.
48
 
49
- Because the fixed DynaWord schema does not contain article titles or URLs, the attribution sidecar maps every released `id` to its title, canonical URL, contributor attribution, license URL and modification notice. It contains one unique URL-bearing record for each of the 2,040 Parquet documents.
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  Recommended attribution:
52
 
 
17
 
18
  | documents | characters | tokens (`cl100k_base` proxy) |
19
  |---:|---:|---:|
20
+ | 1,926 | 9,358,071 | 3,453,918 |
21
 
22
  The Parquet schema matches DynaWord:
23
 
 
34
 
35
  Articles were acquired directly from the Polish Global Voices website through its official publication interfaces, rather than from a third-party corpus. Each released ID is linked to the corresponding canonical article URL in `global_voices.attribution.jsonl`.
36
 
37
+ The source release contained 2,044 records. Four records below the minimum quality and length requirements were excluded, leaving 2,040 documents. A later rights review excluded 114 posts that Global Voices republished from partner outlets (see below), leaving 1,926 documents. The final source contains no exact duplicate documents.
38
 
39
  ## Cleaning
40
 
 
46
 
47
  CC BY 3.0 was verified from the article-level license link published with each retained Global Voices article. Each released record carries `CC-BY-3.0` metadata. Contributor roles are preserved in the `author` column where available, distinguishing original authors from Polish translators.
48
 
49
+ Because the fixed DynaWord schema does not contain article titles or URLs, the attribution sidecar maps every released `id` to its title, canonical URL, contributor attribution, license URL and modification notice. It contains one unique URL-bearing record for each of the 1,926 Parquet documents.
50
+
51
+ ### Partner republications (excluded)
52
+
53
+ Global Voices licenses the content it creates under CC BY 3.0. Some posts instead republish an article that a partner outlet published first, under a content-sharing agreement or with the outlet's permission. That text remains the partner's work, so the release excludes it. `src/clean_global_voices.py` finds the editorial note such posts carry in their opening or closing lines (for example "pierwotnie ukazał się na portalu PRI.org … w ramach umowy o wymianie treści"). It also excludes three posts whose note the rules miss and keeps 25 look-alike notes, each with a stated reason. Every match was checked by hand.
54
+
55
+ The rule excluded 114 posts from 51 outlets. The largest groups are PRI/The World (21), The Stand News (8), Hong Kong Free Press (7), Agência Pública (6), Metamorphosis/Meta.mk (5) and 350.org (5). Three Freemuse co-commissions are excluded because their note allows republication only by non-commercial media.
56
+
57
+ The following posts are kept:
58
+ - posts that Global Voices contributors cross-posted from their own blogs;
59
+ - posts Global Voices wrote for the ISN blog;
60
+ - posts that partner organisations wrote directly for Global Voices without a republication note;
61
+ - photo-only permission credits.
62
 
63
  Recommended attribution:
64
 
data/global_voices/global_voices.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1ca02fdb6bad32b20757ddcd9b9f072056ff35b68c487143138cc7912b3a45c3
3
- size 5253559
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd33133703e9ea375060cf2f83c2aec915d9786db5fd7d4b34fc2f3643c9c7ba
3
+ size 4907377
data/global_voices/global_voices.stats.json CHANGED
@@ -1,15 +1,34 @@
1
  {
2
  "read": 2044,
3
- "kept": 2040,
4
  "drop_short": 4,
5
  "drop_lang": 0,
6
  "drop_dup": 0,
7
  "drop_ocr": 0,
8
- "chars": 10073628,
9
- "tokens": 3715020,
 
10
  "licenses": {
11
- "CC-BY-3.0": 2040
12
  },
13
- "authors_with_value": 2040,
14
- "stats_recomputed_from_parquet": true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  }
 
1
  {
2
  "read": 2044,
3
+ "kept": 1926,
4
  "drop_short": 4,
5
  "drop_lang": 0,
6
  "drop_dup": 0,
7
  "drop_ocr": 0,
8
+ "drop_partner_republication": 114,
9
+ "chars": 9358071,
10
+ "tokens": 3453918,
11
  "licenses": {
12
+ "CC-BY-3.0": 1926
13
  },
14
+ "authors_with_value": 1926,
15
+ "stats_recomputed_from_parquet": true,
16
+ "partner_republication": {
17
+ "by_rule": {
18
+ "agreement": 56,
19
+ "non_commercial": 3,
20
+ "originally": 69,
21
+ "partnership": 11,
22
+ "permission": 5,
23
+ "published_by": 51,
24
+ "republished": 5,
25
+ "written_for": 3
26
+ },
27
+ "listed": 3,
28
+ "kept_by_hand": 25
29
+ },
30
+ "input_sha256": {
31
+ "global_voices.parquet": "1ca02fdb6bad32b20757ddcd9b9f072056ff35b68c487143138cc7912b3a45c3",
32
+ "global_voices.attribution.jsonl": "ab8ad393c4453524c4f3d7fe89157bfca1d9f66f2a735815f3b1ebd405c8fa13"
33
+ }
34
  }
data/wolne_lektury/wolne_lektury.eltec_pairs.tsv ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ wl_id eltec_id score action wl_title
2
+ wolne_lektury_2372617 eltec_pol_2455238 0.9995 drop Wacław Berent / Ozimina
3
+ wolne_lektury_2372618 eltec_pol_2455239 0.9997 drop Wacław Berent / Próchno
4
+ wolne_lektury_2373135 eltec_pol_2455240 0.9921 drop Deotyma / Branki w jasyrze
5
+ wolne_lektury_2373136 eltec_pol_2455241 0.9986 drop Deotyma / Panienka z okienka
6
+ wolne_lektury_2372152 eltec_pol_2455242 0.9998 drop Deotyma / Zwierciadlana zagadka
7
+ wolne_lektury_2374432 eltec_pol_2455246 0.9981 drop Tadeusz Dołęga-Mostowicz / Kariera Nikodema Dyzmy
8
+ wolne_lektury_2373182 eltec_pol_2455247 0.9999 drop Pamiętnik pani Hanki / Tadeusz Dołęga-Mostowicz
9
+ wolne_lektury_2372109 eltec_pol_2455248 0.9984 drop Tadeusz Dołęga-Mostowicz / Znachor
10
+ wolne_lektury_2374147 eltec_pol_2455249 0.9985 drop Antonina Domańska / Historia żółtej ciżemki
11
+ wolne_lektury_2374899 eltec_pol_2455250 0.9985 drop Antonina Domańska / Krysia bezimienna
12
+ wolne_lektury_2376177 eltec_pol_2455251 0.9981 drop Antonina Domańska / Paziowie
13
+ wolne_lektury_2373959 eltec_pol_2455258 0.9955 drop Stefan Grabiński / Namiętność
14
+ wolne_lektury_2376971 eltec_pol_2455259 0.9977 drop Stefan Grabiński / Salamandra
15
+ wolne_lektury_2373979 eltec_pol_2455260 0.9981 drop Stefan Grabiński / Wyspa Itongo
16
+ wolne_lektury_2374400 eltec_pol_2455262 0.9636 drop Zygmunt Kaczkowski / Murdelio
17
+ wolne_lektury_2374184 eltec_pol_2455267 0.9984 drop Józef Ignacy Kraszewski / Hrabina Cosel
18
+ wolne_lektury_2376438 eltec_pol_2455268 0.9980 drop Józef Ignacy Kraszewski / Pogrobek
19
+ wolne_lektury_2377370 eltec_pol_2455269 0.9984 drop Józef Ignacy Kraszewski / Stara baśń
20
+ wolne_lektury_2377371 eltec_pol_2455269 0.9983 drop Józef Ignacy Kraszewski / Stara baśń
21
+ wolne_lektury_2377372 eltec_pol_2455269 0.9983 drop Józef Ignacy Kraszewski / Stara baśń
22
+ wolne_lektury_2375201 eltec_pol_2455275 0.9974 drop Władysław Łoziński / Oko proroka
23
+ wolne_lektury_2376242 eltec_pol_2455275 0.4267 keep_partial Jan Kochanowski / Pieśni, Księgi wtóre
24
+ wolne_lektury_2375475 eltec_pol_2455281 0.7588 keep_partial Tom pierwszy / I
25
+ wolne_lektury_2375476 eltec_pol_2455281 0.6473 keep_partial Helena Mniszek / Trędowata
26
+ wolne_lektury_2375490 eltec_pol_2455283 0.9966 drop Zuzanna Morawska / Na zgliszczach Zakonu
27
+ wolne_lektury_2375491 eltec_pol_2455284 0.9966 drop Zuzanna Morawska / Wilcze gniazdo
28
+ wolne_lektury_2375933 eltec_pol_2455285 0.9999 drop Eliza Orzeszkowa / Marta
29
+ wolne_lektury_2375340 eltec_pol_2455286 0.9993 drop Eliza Orzeszkowa / Meir Ezofowicz
30
+ wolne_lektury_2375558 eltec_pol_2455287 0.9994 drop Eliza Orzeszkowa / Nad Niemnem
31
+ wolne_lektury_2375559 eltec_pol_2455287 0.9992 drop Eliza Orzeszkowa / Nad Niemnem
32
+ wolne_lektury_2375560 eltec_pol_2455287 0.9995 drop Eliza Orzeszkowa / Nad Niemnem
33
+ wolne_lektury_2373434 eltec_pol_2455291 0.9974 drop Bolesław Prus / Emancypantki
34
+ wolne_lektury_2373439 eltec_pol_2455292 0.9979 drop Bolesław Prus / Faraon
35
+ wolne_lektury_2373440 eltec_pol_2455292 0.9972 drop Bolesław Prus / Faraon
36
+ wolne_lektury_2373441 eltec_pol_2455292 0.9981 drop Bolesław Prus / Faraon
37
+ wolne_lektury_2375026 eltec_pol_2455293 0.9988 drop Bolesław Prus / Lalka
38
+ wolne_lektury_2375027 eltec_pol_2455293 0.9982 drop Bolesław Prus / Lalka
39
+ wolne_lektury_2372954 eltec_pol_2455294 0.9990 drop Władysław Stanisław Reymont / Chłopi
40
+ wolne_lektury_2372955 eltec_pol_2455294 0.9989 drop Władysław Stanisław Reymont / Chłopi
41
+ wolne_lektury_2372956 eltec_pol_2455294 0.9992 drop Władysław Stanisław Reymont / Chłopi
42
+ wolne_lektury_2376750 eltec_pol_2455294 0.9990 drop Władysław Stanisław Reymont / Chłopi
43
+ wolne_lektury_2374612 eltec_pol_2455295 0.9992 drop Władysław Stanisław Reymont / Komediantka
44
+ wolne_lektury_2372093 eltec_pol_2455296 0.9985 drop Władysław St. Reymont / Ziemia obiecana, tom II
45
+ wolne_lektury_2372094 eltec_pol_2455296 0.9990 drop Władysław St. Reymont / Ziemia obiecana, tom I
46
+ wolne_lektury_2376762 eltec_pol_2455297 0.9977 drop Maria Rodziewiczówna / Lato
47
+ wolne_lektury_2376763 eltec_pol_2455298 0.9985 drop Maria Rodziewiczówna / Między ustami a
48
+ wolne_lektury_2376764 eltec_pol_2455299 0.9984 drop Maria Rodziewiczówna / Straszny dziadunio
49
+ wolne_lektury_2375871 eltec_pol_2455300 0.9983 drop Henryk Sienkiewicz / Ogniem i mieczem
50
+ wolne_lektury_2375872 eltec_pol_2455300 0.9981 drop Henryk Sienkiewicz / Ogniem i mieczem
51
+ wolne_lektury_2376691 eltec_pol_2455301 0.9970 drop Henryk Sienkiewicz / Quo vadis
52
+ wolne_lektury_2376766 eltec_pol_2455302 0.9983 drop Henryk Sienkiewicz / Rodzina Połanieckich
53
+ wolne_lektury_2377398 eltec_pol_2455303 0.9998 drop Andrzej Strug / Dzieje jednego pocisku
54
+ wolne_lektury_2377720 eltec_pol_2455307 0.9899 drop Aleksander Świętochowski / Tragikomedya prawdy
55
+ wolne_lektury_2371802 eltec_pol_2455316 0.9991 drop Stanisław Ignacy Witkiewicz / Nienasycenie
56
+ wolne_lektury_2371803 eltec_pol_2455316 0.9988 drop Stanisław Ignacy Witkiewicz / Nienasycenie
57
+ wolne_lektury_2371806 eltec_pol_2455317 0.9993 drop Stanisław Ignacy Witkiewicz / Pożegnanie jesieni
58
+ wolne_lektury_2372038 eltec_pol_2455318 0.9999 drop Gabriela Zapolska / Kaśka Kariatyda
59
+ wolne_lektury_2372039 eltec_pol_2455319 0.9966 drop Gabiela Zapolska / Kobieta bez skazy
60
+ wolne_lektury_2377058 eltec_pol_2455320 0.9981 drop Gabriela Zapolska / Sezonowa miłość
61
+ wolne_lektury_2373356 eltec_pol_2455321 0.9879 drop Stefan Żeromski / Dzieje grzechu
62
+ wolne_lektury_2376559 eltec_pol_2455322 0.9995 drop Stefan Żeromski / Przedwiośnie
63
+ wolne_lektury_2377473 eltec_pol_2455323 0.9985 drop Stefan Żeromski / Syzyfowe prace
64
+ wolne_lektury_2372105 eltec_pol_2455326 0.9989 drop Narcyza Żmichowska / Poganka
65
+ wolne_lektury_2371605 eltec_pol_2455327 0.9988 drop Jerzy Żuławski / Trylogia księżycowa
66
+ wolne_lektury_2372130 eltec_pol_2455328 0.9986 drop Jerzy Żuławski / Powrót
67
+ wolne_lektury_2371607 eltec_pol_2455329 0.9981 drop Jerzy Żuławski / Trylogia księżycowa
data/wolne_lektury/wolne_lektury.md CHANGED
@@ -19,16 +19,19 @@ Pulled from SpeakLeash's public redistribution (`speakleash-ds-pub`, key `wolne_
19
  ## Statistics
20
  | documents | characters | tokens (tiktoken proxy) |
21
  |---:|---:|---:|
22
- | 6,141 | 261,892,000 | 103,009,797 |
23
 
24
 
25
  ## Per-document license metadata
26
  | license | documents |
27
  |---|---:|
28
- | `CC-BY-SA-4.0 / Wolna Sztuka 1.3` | 6,141 |
29
 
30
  Author metadata present for **0** documents. Empty values mean the upstream record did not expose a machine-readable author field.
31
 
 
 
 
32
  Statistics were recomputed directly from the released parquet file.
33
 
34
  ## Filters applied (build_dynaword.py)
@@ -37,7 +40,7 @@ Minimal, per Dynaword guidelines (heavy filtering left to downstream use):
37
  - drop non-Polish (diacritic ratio): **0**
38
  - exact cross-source dedup (sha1): **0**
39
  - OCR alpha-ratio < 0.70 (OCR sources only): **0**
40
- - read 6,141 → kept 6,141
41
 
42
  Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
43
  Llama-3 count is computed at release.
 
19
  ## Statistics
20
  | documents | characters | tokens (tiktoken proxy) |
21
  |---:|---:|---:|
22
+ | 6,078 | 230,764,171 | 90,654,820 |
23
 
24
 
25
  ## Per-document license metadata
26
  | license | documents |
27
  |---|---:|
28
+ | `CC-BY-SA-4.0 / Wolna Sztuka 1.3` | 6,078 |
29
 
30
  Author metadata present for **0** documents. Empty values mean the upstream record did not expose a machine-readable author field.
31
 
32
+ ## Legal scope note
33
+ For v0.2.6, 63 documents whose text is an eltec_pol novel are dropped (share of a document's 5-word shingles found in one ELTeC novel >= 0.9; src/clean_wolne_lektury.py, polish-dynaword-v2#72). eltec_pol keeps those 50 novels whole under CC BY 4.0. Three documents only partly in an ELTeC novel are kept: both tomes of Mniszek's Trędowata (the ELTeC text is shorter) and Kochanowski's Pieśń IX, quoted in Łoziński's Oko proroka. Every pair is listed in wolne_lektury.eltec_pairs.tsv.
34
+
35
  Statistics were recomputed directly from the released parquet file.
36
 
37
  ## Filters applied (build_dynaword.py)
 
40
  - drop non-Polish (diacritic ratio): **0**
41
  - exact cross-source dedup (sha1): **0**
42
  - OCR alpha-ratio < 0.70 (OCR sources only): **0**
43
+ - read 6,141 → kept 6,078
44
 
45
  Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
46
  Llama-3 count is computed at release.
data/wolne_lektury/wolne_lektury.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5833c25db296f2479b3c09745ebedd550b2425dd6ebaf021f0095e684a0221a1
3
- size 128562077
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f308d49235551241d6c47c5e88138ba52e6235422ae272ddbc135c3b8696ae0e
3
+ size 113055766
data/wolne_lektury/wolne_lektury.stats.json CHANGED
@@ -1,16 +1,19 @@
1
  {
2
  "read": 6141,
3
- "kept": 6141,
4
  "drop_short": 0,
5
  "drop_lang": 0,
6
  "drop_dup": 0,
7
  "drop_ocr": 0,
8
- "chars": 261892000,
9
- "tokens": 103009797,
10
  "licenses": {
11
- "CC-BY-SA-4.0 / Wolna Sztuka 1.3": 6141
12
  },
13
  "authors_with_value": 0,
14
  "license": "CC-BY-SA-4.0 / Wolna Sztuka 1.3",
15
- "stats_recomputed_from_parquet": true
 
 
 
16
  }
 
1
  {
2
  "read": 6141,
3
+ "kept": 6078,
4
  "drop_short": 0,
5
  "drop_lang": 0,
6
  "drop_dup": 0,
7
  "drop_ocr": 0,
8
+ "chars": 230764171,
9
+ "tokens": 90654820,
10
  "licenses": {
11
+ "CC-BY-SA-4.0 / Wolna Sztuka 1.3": 6078
12
  },
13
  "authors_with_value": 0,
14
  "license": "CC-BY-SA-4.0 / Wolna Sztuka 1.3",
15
+ "stats_recomputed_from_parquet": true,
16
+ "drop_eltec_dup": 63,
17
+ "input_sha256": "5833c25db296f2479b3c09745ebedd550b2425dd6ebaf021f0095e684a0221a1",
18
+ "eltec_sha256": "ba40061741dff11165149f6c2cf3d5526e1b6c759e7ce1e03ccc164d58838325"
19
  }
src/clean_1000_novels.py CHANGED
@@ -9,7 +9,8 @@ kept only when the per-text rights screen finds it public domain in Poland:
9
  Kept rows are labelled `public-domain`, and `author` credits the author and any translator.
10
  Title, death year, screen basis and CLARIN file name go to `1000_novels.attribution.jsonl`.
11
 
12
- The input is the v0.2.5 Parquet, pinned by SHA-256. Restore it before a rerun:
 
13
  git checkout v0.2.5 -- data/1000_novels/1000_novels.parquet
14
  python3 src/clean_1000_novels.py --screen ../polish-dynaword-v2/evidence/1000_novels_rights_screen.csv
15
  """
@@ -31,9 +32,11 @@ SOURCE = "1000_novels"
31
  ROOT = Path(__file__).resolve().parents[1]
32
  DATA = ROOT / "data" / SOURCE
33
  INPUT_SHA256 = "27be09e5e2347dcf1a83e94b6c210ca26bdd89365bc3563e88ea5af9846990ea" # v0.2.5
 
 
34
  UPSTREAM = "https://clarin-pl.eu/dspace/handle/11321/312"
35
  LICENSE = "public-domain"
36
- KEEP = {"pd_by_term", "pd_per_wolne_lektury"}
37
  SCREENS = KEEP | {"in_copyright", "unresolved"}
38
  # Read off each text's header by hand where the rules below fail: no header, a dedication
39
  # ("H. K. T."), a series title (Proust), a title broken over lines, or a misspelt file name.
@@ -45,6 +48,8 @@ TITLES = {
45
  "proust_w-cieniu-zakwitajacych-dziewczat_tom-III_1937.txt": "W cieniu zakwitających dziewcząt",
46
  "prus_co-sie-z-wielkiej-idei-zrobilo-w-malym-miasteczku.txt": "Co się z wielkiej idei zrobiło w małem miasteczku",
47
  "prus_piesn-swiata_1935.txt": "Pleśń świata",
 
 
48
  "reymont_wampir.txt": "Wampir",
49
  "sienkiewicz_bajka1.txt": "Bajka",
50
  "sienkiewicz_bajka3.txt": "Bajka",
@@ -54,6 +59,7 @@ TITLES = {
54
  "Przygody trzech Rossyan i trzech Anglików w południowej Afryce",
55
  "zapolska_papuzia_1958.txt": "Papuzia",
56
  "zeromski_popioly.txt": "Popioły",
 
57
  "zulawski_z-domu-ojcow_1897.txt": "Z domu ojców",
58
  }
59
  NOT_A_TITLE = re.compile(r"^(tłum|tłumacz|przekład|rozdział|tom|księga|[IVXLC]+\.?$|\d+\.?$)", re.I)
@@ -130,6 +136,10 @@ def credit(author: str, translator: str) -> str:
130
 
131
 
132
  def build(input_path: Path, screen_path: Path, out_dir: Path) -> dict:
 
 
 
 
133
  if sha256(input_path) != INPUT_SHA256:
134
  raise SystemExit(f"{input_path} is not the v0.2.5 Parquet; restore it with "
135
  "`git checkout v0.2.5 -- data/1000_novels/1000_novels.parquet`")
@@ -165,7 +175,7 @@ def build(input_path: Path, screen_path: Path, out_dir: Path) -> dict:
165
  "licenses": {LICENSE: len(kept)}, "authors_with_value": sum(bool(r["author"]) for r in kept),
166
  "license": LICENSE, "screen": dict(Counter(r["screen"] for r in screen.values())),
167
  "titles": dict(Counter(a["title_from"] for a in attribution)),
168
- "input_sha256": INPUT_SHA256, "screen_sha256": sha256(screen_path),
169
  }
170
  staged = {
171
  out_dir / f"{SOURCE}.parquet.tmp": lambda p: pq.write_table(
 
9
  Kept rows are labelled `public-domain`, and `author` credits the author and any translator.
10
  Title, death year, screen basis and CLARIN file name go to `1000_novels.attribution.jsonl`.
11
 
12
+ The input is the v0.2.5 Parquet and the screen CSV, both pinned by SHA-256. Restore the Parquet
13
+ before a rerun:
14
  git checkout v0.2.5 -- data/1000_novels/1000_novels.parquet
15
  python3 src/clean_1000_novels.py --screen ../polish-dynaword-v2/evidence/1000_novels_rights_screen.csv
16
  """
 
32
  ROOT = Path(__file__).resolve().parents[1]
33
  DATA = ROOT / "data" / SOURCE
34
  INPUT_SHA256 = "27be09e5e2347dcf1a83e94b6c210ca26bdd89365bc3563e88ea5af9846990ea" # v0.2.5
35
+ # polish-dynaword-v2 evidence/1000_novels_rights_screen.csv for v0.2.6; also in 1000_novels.license-evidence.json
36
+ SCREEN_SHA256 = "7fefc75f8fcbd07e5ec98842276765ffef9520b6acb4e24b4751c67cc3d2081c"
37
  UPSTREAM = "https://clarin-pl.eu/dspace/handle/11321/312"
38
  LICENSE = "public-domain"
39
+ KEEP = {"pd_by_term"}
40
  SCREENS = KEEP | {"in_copyright", "unresolved"}
41
  # Read off each text's header by hand where the rules below fail: no header, a dedication
42
  # ("H. K. T."), a series title (Proust), a title broken over lines, or a misspelt file name.
 
48
  "proust_w-cieniu-zakwitajacych-dziewczat_tom-III_1937.txt": "W cieniu zakwitających dziewcząt",
49
  "prus_co-sie-z-wielkiej-idei-zrobilo-w-malym-miasteczku.txt": "Co się z wielkiej idei zrobiło w małem miasteczku",
50
  "prus_piesn-swiata_1935.txt": "Pleśń świata",
51
+ "puszkin_basn-o-krolu-saltanie_1924.txt":
52
+ "Baśń o królu Sałtanie, o jego synu, słynnym i potężnym bohaterze Gwidonie, i o pięknej królewnie Łabędziu",
53
  "reymont_wampir.txt": "Wampir",
54
  "sienkiewicz_bajka1.txt": "Bajka",
55
  "sienkiewicz_bajka3.txt": "Bajka",
 
59
  "Przygody trzech Rossyan i trzech Anglików w południowej Afryce",
60
  "zapolska_papuzia_1958.txt": "Papuzia",
61
  "zeromski_popioly.txt": "Popioły",
62
+ "zulawski_list-senki-do-lucjusza_1914.txt": "List Seneki do Lucyljusza",
63
  "zulawski_z-domu-ojcow_1897.txt": "Z domu ojców",
64
  }
65
  NOT_A_TITLE = re.compile(r"^(tłum|tłumacz|przekład|rozdział|tom|księga|[IVXLC]+\.?$|\d+\.?$)", re.I)
 
136
 
137
 
138
  def build(input_path: Path, screen_path: Path, out_dir: Path) -> dict:
139
+ if (found := sha256(screen_path)) != SCREEN_SHA256:
140
+ raise SystemExit(f"{screen_path} is not the pinned rights screen: SHA-256 {found}, expected "
141
+ f"{SCREEN_SHA256}; regenerate it with polish-dynaword-v2/scripts/novels_rights_screen.py "
142
+ "or update SCREEN_SHA256 and 1000_novels.license-evidence.json together")
143
  if sha256(input_path) != INPUT_SHA256:
144
  raise SystemExit(f"{input_path} is not the v0.2.5 Parquet; restore it with "
145
  "`git checkout v0.2.5 -- data/1000_novels/1000_novels.parquet`")
 
175
  "licenses": {LICENSE: len(kept)}, "authors_with_value": sum(bool(r["author"]) for r in kept),
176
  "license": LICENSE, "screen": dict(Counter(r["screen"] for r in screen.values())),
177
  "titles": dict(Counter(a["title_from"] for a in attribution)),
178
+ "input_sha256": INPUT_SHA256, "screen_sha256": SCREEN_SHA256,
179
  }
180
  staged = {
181
  out_dir / f"{SOURCE}.parquet.tmp": lambda p: pq.write_table(
src/clean_global_voices.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Drop Global Voices posts republished from partner outlets (slayerlabs/polish-dynaword-v2#50).
3
+
4
+ Global Voices licenses "content created by Global Voices" under CC BY 3.0. Posts it republished
5
+ from partner outlets (PRI's The World, Hong Kong Free Press, The Stand News, Meta.mk, 350.org,
6
+ The Irrawaddy, ...) under content-sharing agreements or with permission stay the partner's work,
7
+ so the CC BY grant does not demonstrably cover them. Each such post carries an editorial note in
8
+ its first or last lines, e.g. "Ten artykuł ... pierwotnie ukazał się na portalu PRI.org ... i jest
9
+ publikowany ponownie w ramach umowy o wymianie treści". `note_rules()` finds those notes.
10
+
11
+ Kept on purpose: posts that GV contributors cross-posted from their own blogs, posts GV wrote for
12
+ the ISN partnership, partner organisations writing directly for GV with no republication note,
13
+ and photo-only permission credits ("Zdjęcie ..., użyte za pozwoleniem").
14
+
15
+ The input is the Parquet and sidecar as of v0.2.5 (the Parquet is unchanged since), pinned by
16
+ SHA-256. Restore them before a rerun:
17
+ git checkout 92b36dc -- data/global_voices/global_voices.parquet data/global_voices/global_voices.attribution.jsonl
18
+ python3 src/clean_global_voices.py
19
+ """
20
+ from __future__ import annotations
21
+
22
+ import argparse
23
+ import hashlib
24
+ import json
25
+ import os
26
+ import re
27
+ from collections import Counter
28
+ from pathlib import Path
29
+
30
+ import pyarrow.parquet as pq
31
+
32
+ SOURCE = "global_voices"
33
+ ROOT = Path(__file__).resolve().parents[1]
34
+ DATA = ROOT / "data" / SOURCE
35
+ INPUT_SHA256 = {
36
+ f"{SOURCE}.parquet": "1ca02fdb6bad32b20757ddcd9b9f072056ff35b68c487143138cc7912b3a45c3",
37
+ f"{SOURCE}.attribution.jsonl": "ab8ad393c4453524c4f3d7fe89157bfca1d9f66f2a735815f3b1ebd405c8fa13",
38
+ }
39
+
40
+ # The contributed release (PR #7) read 2,044 records and dropped 4 short ones before the v0.2.5 input.
41
+ READ, DROP_SHORT = 2044, 4
42
+ # Editorial notes sit in the lede or the closing lines; the body quotes and reports on
43
+ # agreements, first publications and permissions far too often to search it.
44
+ HEAD, TAIL = 700, 350
45
+ # Sentence ends before an upper-case start or at a paragraph break, so "umowy dot. współdzielenia" holds.
46
+ SENTENCE = re.compile(r"(?<=[.!?])\s+(?=[^\sa-ząćęłńóśźż])|\s*\n+\s*")
47
+ PUB = r"(?:opublik|publik|ukaza|ukazuj|pojawi|przedruk|zamieszcz|udostępni|reprodukow|wydan)\w*"
48
+ FIRST = r"(?:pierwotnie|oryginalnie|orginalnie|po\s+raz\s+pierwszy|pierwszy\s+raz|początkowo|uprzednio|wcześniej|najpierw|w\s+oryginale)"
49
+ NOT_GV = r"(?!Global\s*Voices|GV\b|globalvoices|ramach|naszym|niniejszym|tym\b)"
50
+ # A note speaks about the post itself: "Ten artykuł ...", "Poniżej publikujemy zredagowaną wersję artykułu ...",
51
+ # "Jest to trzecia odsłona historii ...", "Opublikowano za zgodą PRI".
52
+ SELF = re.compile(
53
+ r"^\W*(?:\S+\s+){0,2}?(?:artykuł|tekst|post|wpis|histori|reportaż|wywiad|wiadomoś|wersj|seri|częś|materiał|opowieś|esej|treś)\w{0,3}\b"
54
+ rf"|^\W*(?:Jest|Są)\s+to\b|^\W*(?:\S+\s+)?{PUB}", re.I)
55
+ GV = re.compile(r"\bGV\b|Global\s*Voices|Rising\s*Voices", re.I)
56
+ # Photo, art and video credits ("Zdjęcie: ... Opublikowano za zgodą.") are not text republications;
57
+ # their sentences do not open with a text noun, and a bare permission line right after one belongs to it.
58
+ IMAGE = r"zdj[eę]ci|zdjęć|fotograf|\bfot\.|ilustracj|obraz|grafik|wideo|\bfilm|nagrani|plakat|rysun|karykatur|okład|zrzut|\bmap"
59
+ CREDIT = re.compile(rf"^\W*(?:\S+\s+)?\S*?(?:{IMAGE})", re.I) # an image is the subject
60
+
61
+ RULES = {
62
+ # "w ramach umowy o wymianie treści", "na mocy porozumienia o dzieleniu się treściami",
63
+ # "umowy partnerskiej", "porozumienie z Global Voices"
64
+ "agreement": re.compile(
65
+ r"\b(?:umow|porozumie)\w*\s+(?:\w+\s+){0,3}?(?:o\s+|dot\.\s*|dotycząc\w*\s+|w\s+sprawie\s+)?"
66
+ r"(?:wymian|udostępn|dzieleni|współdziel|podzia|rozpowszechn|partnersk|partnerstw)\w*"
67
+ r"|\bporozumieni\w*\s+z\s+Global\s+Voices", re.I),
68
+ # "w ramach partnerstwa pomiędzy PRI i Global Voices", "w ramach naszej współpracy z Syria Deeply",
69
+ # "post partnerski ze strony EurasiaNet.org"
70
+ "partnership": re.compile(
71
+ r"(?:w\s+ramach|na\s+mocy|na\s+podstawie|jako\s+część)\s+(?:\w+\s+){0,2}?(?:partnerstw|współprac)\w*\s+"
72
+ r"(?:\w+\s+){0,3}?(?:z|pomiędzy|między)\s"
73
+ r"|\bpost\w*\s+partnersk\w*|\bpartnersk\w*\s+post\w*", re.I),
74
+ # "pierwotnie ukazał się na portalu PRI.org", "pojawił się po raz pierwszy na stronie CHRI",
75
+ # "Oryginalny tekst [ru] dostępny na stronie Teplicy"
76
+ "originally": re.compile(
77
+ rf"{FIRST}\s+(?:\S+\s+){{0,6}}?(?:{PUB}|ujrzał\w*)|{PUB}\s+(?:\S+\s+){{0,2}}?{FIRST}"
78
+ r"|oryginaln\w*\s+(?:\[\w+\]\s+)?(?:wersj|tekst|artykuł|publikacj)\w*", re.I),
79
+ # "Ta republikacja", "jest tutaj reprodukowany", "poniższa reedycja"
80
+ "republished": re.compile(r"\brepublikacj\w*|reprodukowan\w*|przedrukowan\w*|reedycj\w*", re.I),
81
+ # "napisany przez Fentona Lutunatabua dla 350.org", "artykułu napisanego przez Irinę Illa Pueyo dla Afroféminas"
82
+ "written_for": re.compile(rf"napisan\w*\s+(?:\S+\s+){{0,6}}?dla\s+{NOT_GV}", re.I),
83
+ # "Artykuł został opublikowany na stronie internetowej Agência Pública", "część artykułu opublikowanego na łamach The Stand News"
84
+ "published_by": re.compile(
85
+ rf"(?:artykuł|tekst|post|wpis|histori|reportaż|wywiad|wiadomoś|wersj|seri)\w*\s+(?:\S+\s+){{0,8}}?"
86
+ rf"(?:opublikowan|publikowan|ukazał|pojawił)\w*\s+(?:\S+\s+){{0,3}}?"
87
+ rf"(?:na\s+stronie|na\s+łamach|na\s+portalu|w\s+serwisie|na\s+blogu|przez|w)\s+{NOT_GV}", re.I),
88
+ # "Opublikowano za zgodą PRI", "Opublikowany za pozwoleniem." (the author's or artist's own consent is not a partner's)
89
+ "permission": re.compile(
90
+ rf"{PUB}\s+(?:\S+\s+){{0,6}}?(?:za|ze|z)\s+(?:\S+\s+)?(?:zgodą|pozwoleniem|przyzwoleniem)(?!\s+(?:autor|artyst))", re.I),
91
+ # Freemuse co-commissions: "may be republished by non-commercial media" conflicts with CC BY
92
+ "non_commercial": re.compile(r"niekomercyjn\w*\s+medi|non-commercial\s+media", re.I),
93
+ }
94
+ # Rules that fire only on a sentence about the post itself that does not name Global Voices,
95
+ # so news reporting ("raport opublikowany przez UNESCO") and GV's own projects do not count.
96
+ SELF_RULES = {"originally", "republished", "written_for", "published_by", "permission"}
97
+
98
+ # Notes a rule matches that are not partner republications, checked by hand against the text
99
+ # and, where unclear, the English original on globalvoices.org.
100
+ OWN_BLOG = "the GV author's cross-post from their own blog"
101
+ ISN = "written by GV for the ISN blog under the GV-ISN partnership"
102
+ KEEP = {
103
+ **{f"global_voices_{n}": OWN_BLOG + " (Juan Arellano, Globalizado)"
104
+ for n in (7749, 11971, 18309, 20340, 21612, 22399, 25101)},
105
+ "global_voices_1420": OWN_BLOG + " (Georgia Popplewell, Caribbean Free Radio)",
106
+ "global_voices_23554": OWN_BLOG + " (Elia Ayoub, Hummus For Thought)",
107
+ "global_voices_28150": OWN_BLOG + " (Jillian C. York)",
108
+ "global_voices_28814": OWN_BLOG + " (Anca Matioc, Medium)",
109
+ "global_voices_29905": OWN_BLOG + " (Derek Lackaff, r12n)",
110
+ **{f"global_voices_{n}": ISN for n in (13370, 14712, 14881, 14946, 15662, 17435, 18724)},
111
+ "global_voices_3210": "a GV post that Ezhednevny Zhurnal republished, not the reverse",
112
+ "global_voices_15986": "dates GV's own English original",
113
+ "global_voices_22228": "dates GV's own English original",
114
+ "global_voices_8": "news about an AOL partnership deal",
115
+ "global_voices_14503": "news: a quoted blogger's posts also ran in The Guardian",
116
+ "global_voices_15837": "news: interviews published on the Mujeres Mundi blog",
117
+ }
118
+ # Partner republications whose note no rule matches.
119
+ DROP = {
120
+ "global_voices_21466": "Agência Pública; a long quoted title splits the note",
121
+ "global_voices_27005": "inmediahk.net; the note follows a 1,000-character lede",
122
+ "global_voices_32352": "based on two Meta.mk / CriThink.mk (Metamorphosis Foundation) texts",
123
+ }
124
+
125
+
126
+ def sha256(path: Path) -> str:
127
+ digest = hashlib.sha256()
128
+ with path.open("rb") as stream:
129
+ for chunk in iter(lambda: stream.read(1 << 20), b""):
130
+ digest.update(chunk)
131
+ return digest.hexdigest()
132
+
133
+
134
+ def note_zone(text: str) -> str:
135
+ return text if len(text) <= HEAD + TAIL else text[:HEAD] + "\n" + text[-TAIL:]
136
+
137
+
138
+ def note_rules(text: str) -> list[str]:
139
+ """Names of the rules whose pattern matches a sentence in the post's opening or closing lines."""
140
+ hits = []
141
+ previous = ""
142
+ for sentence in SENTENCE.split(note_zone(text)):
143
+ about_post = SELF.search(sentence) and not GV.search(sentence) and not CREDIT.search(sentence)
144
+ for name, rule in RULES.items():
145
+ if name in hits or (name in SELF_RULES and not about_post):
146
+ continue
147
+ if name == "permission" and re.search(IMAGE, previous, re.I):
148
+ continue
149
+ if rule.search(sentence):
150
+ hits.append(name)
151
+ previous = sentence
152
+ return hits
153
+
154
+
155
+ def reason(doc_id: str, text: str) -> str | None:
156
+ """Why a row is dropped (rule names, or the DROP note), or None to keep it."""
157
+ if doc_id in DROP:
158
+ return "listed: " + DROP[doc_id]
159
+ if doc_id in KEEP:
160
+ return None
161
+ hits = note_rules(text)
162
+ return "+".join(hits) if hits else None
163
+
164
+
165
+
166
+ def build(input_dir: Path, out_dir: Path) -> dict:
167
+ parquet, sidecar = (input_dir / name for name in INPUT_SHA256)
168
+ for path, expected in zip((parquet, sidecar), INPUT_SHA256.values()):
169
+ if sha256(path) != expected:
170
+ raise SystemExit(f"{path} is not the v0.2.5 input; restore it with the command in this script's docstring")
171
+ table = pq.read_table(parquet)
172
+ lines = sidecar.read_text(encoding="utf-8").splitlines(keepends=True)
173
+ ids = table.column("id").to_pylist()
174
+ sidecar_ids = [json.loads(line)["id"] for line in lines]
175
+ if len(set(ids)) != len(ids) or set(ids) != set(sidecar_ids) or len(sidecar_ids) != len(ids):
176
+ raise SystemExit("Parquet and attribution sidecar do not cover the same ids")
177
+ if stale := (KEEP.keys() | DROP.keys()) - set(ids):
178
+ raise SystemExit(f"KEEP/DROP name ids that are not in the input: {sorted(stale)}")
179
+
180
+ rows = table.to_pylist()
181
+ dropped = {row["id"]: why for row in rows if (why := reason(row["id"], row["text"]))}
182
+ kept = [row for row in rows if row["id"] not in dropped]
183
+ rules = Counter(name for why in dropped.values() if not why.startswith("listed: ") for name in why.split("+"))
184
+ stats = {
185
+ "read": READ, "kept": len(kept),
186
+ "drop_short": DROP_SHORT, "drop_lang": 0, "drop_dup": 0, "drop_ocr": 0,
187
+ "drop_partner_republication": len(dropped),
188
+ "chars": sum(len(r["text"]) for r in kept), "tokens": sum(r["token_count"] for r in kept),
189
+ "licenses": dict(Counter(r["license"] for r in kept)), "authors_with_value": sum(bool(r["author"]) for r in kept),
190
+ "stats_recomputed_from_parquet": True,
191
+ "partner_republication": {
192
+ "by_rule": dict(sorted(rules.items())),
193
+ "listed": sum(why.startswith("listed: ") for why in dropped.values()),
194
+ "kept_by_hand": len(KEEP),
195
+ },
196
+ "input_sha256": INPUT_SHA256,
197
+ }
198
+ staged = {
199
+ out_dir / f"{SOURCE}.parquet.tmp": lambda p: pq.write_table(
200
+ table.from_pylist(kept, schema=table.schema), p, compression="zstd"),
201
+ out_dir / f"{SOURCE}.attribution.jsonl.tmp": lambda p: p.write_text(
202
+ "".join(line for line, i in zip(lines, sidecar_ids) if i not in dropped), encoding="utf-8"),
203
+ out_dir / f"{SOURCE}.stats.json.tmp": lambda p: p.write_text(
204
+ json.dumps(stats, indent=2, ensure_ascii=False) + "\n", encoding="utf-8"),
205
+ }
206
+ for path, write in staged.items():
207
+ write(path)
208
+ for path in staged:
209
+ os.replace(path, path.with_suffix(""))
210
+ return {**stats, "dropped": dropped}
211
+
212
+
213
+ def main() -> None:
214
+ parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
215
+ parser.add_argument("--input", type=Path, default=DATA, help="directory holding the v0.2.5 Parquet and sidecar")
216
+ parser.add_argument("--out", type=Path, default=DATA)
217
+ args = parser.parse_args()
218
+ print(json.dumps(build(args.input, args.out), indent=2, ensure_ascii=False))
219
+
220
+
221
+ if __name__ == "__main__":
222
+ main()
src/clean_wolne_lektury.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Drop wolne_lektury documents whose text is an eltec_pol novel (slayerlabs/polish-dynaword-v2#72).
3
+
4
+ Half of the 100 ELTeC-pol novels are also in Wolne Lektury. The maintainer chose (2026-10-06) to
5
+ drop the Wolne Lektury copies and keep eltec_pol whole, because ELTeC's CC BY 4.0 is the clean
6
+ licence. Wolne Lektury splits long novels into tomes, so the test is containment, not Jaccard:
7
+
8
+ score = |S(wl) & S(novel)| / |S(wl)|
9
+
10
+ S() is the set of 5-word shingles over NFKC-casefolded \\w+ tokens (the tokenisation of the
11
+ repo's near_dedup), and `novel` is the ELTeC novel sharing the most shingles with the WL doc;
12
+ the shingling and scoring code is in src/shingle_containment.py.
13
+ A trailing Wolne Lektury footer is cut from WL text before scoring (the #45 measurement's rule);
14
+ the released text is not changed. Docs scoring >= DROP_AT are dropped. Docs scoring
15
+ >= REPORT_AT but below DROP_AT are only partly in an ELTeC novel; they are kept and listed.
16
+ Both groups are written to wolne_lektury.eltec_pairs.tsv.
17
+
18
+ Both input Parquets are pinned by SHA-256. Restore the WL Parquet before a rerun:
19
+ git checkout v0.2.5 -- data/wolne_lektury/wolne_lektury.parquet
20
+ python3 src/clean_wolne_lektury.py
21
+ """
22
+ from __future__ import annotations
23
+
24
+ import argparse
25
+ import csv
26
+ import hashlib
27
+ import json
28
+ import os
29
+ from collections import Counter
30
+ from pathlib import Path
31
+
32
+ import pyarrow as pa
33
+ import pyarrow.compute as pc
34
+ import pyarrow.parquet as pq
35
+
36
+ from shingle_containment import best_containment, strip_wl_footer
37
+
38
+ SOURCE = "wolne_lektury"
39
+ ROOT = Path(__file__).resolve().parents[1]
40
+ DATA = ROOT / "data" / SOURCE
41
+ ELTEC = ROOT / "data" / "eltec_pol" / "eltec_pol.parquet"
42
+ INPUT_SHA256 = "5833c25db296f2479b3c09745ebedd550b2425dd6ebaf021f0095e684a0221a1" # v0.2.1-v0.2.5
43
+ ELTEC_SHA256 = "ba40061741dff11165149f6c2cf3d5526e1b6c759e7ce1e03ccc164d58838325" # v0.2.1-v0.2.5
44
+ PAIRS = f"{SOURCE}.eltec_pairs.tsv"
45
+ # Thresholds sit in empty stretches of the v0.2.5 score distribution: no doc scores between
46
+ # 0.7588 and 0.9636 (above: 63 docs, the novels; below: two tomes of an abridged ELTeC
47
+ # Trędowata), and none between 0.2203 and 0.4267 (below: poems quoted in a novel).
48
+ DROP_AT = 0.9
49
+ REPORT_AT = 0.3
50
+
51
+
52
+ def wl_title(text: str) -> str:
53
+ """Author and title: the first two non-empty lines of a Wolne Lektury text."""
54
+ return " / ".join([line.strip() for line in text.splitlines() if line.strip()][:2])
55
+
56
+
57
+ def check_pin(path: Path, expected: str, restore: str) -> None:
58
+ with path.open("rb") as stream:
59
+ if hashlib.file_digest(stream, "sha256").hexdigest() != expected:
60
+ raise SystemExit(f"{path} does not match the pinned SHA-256; {restore}")
61
+
62
+
63
+ def build(input_path: Path, eltec_path: Path, out_dir: Path) -> dict:
64
+ check_pin(input_path, INPUT_SHA256,
65
+ f"restore it with `git checkout v0.2.5 -- data/{SOURCE}/{SOURCE}.parquet`")
66
+ check_pin(eltec_path, ELTEC_SHA256, "it is not the v0.2.5 eltec_pol Parquet")
67
+ table = pq.read_table(input_path)
68
+ eltec = pq.read_table(eltec_path, columns=["id", "text"])
69
+ texts = table.column("text").to_pylist()
70
+ eltec_ids = eltec.column("id").to_pylist()
71
+ scores = best_containment([strip_wl_footer(t) for t in texts], eltec.column("text").to_pylist())
72
+
73
+ keep, pairs = [], []
74
+ for wl_id, text, (novel, score) in zip(table.column("id").to_pylist(), texts, scores, strict=True):
75
+ keep.append(score < DROP_AT)
76
+ if score >= REPORT_AT:
77
+ pairs.append({"wl_id": wl_id, "eltec_id": eltec_ids[novel], "score": f"{score:.4f}",
78
+ "action": "drop" if score >= DROP_AT else "keep_partial",
79
+ "wl_title": wl_title(text)})
80
+ kept = table.filter(pa.array(keep))
81
+
82
+ stats_path = out_dir / f"{SOURCE}.stats.json"
83
+ stats = json.loads(stats_path.read_text(encoding="utf-8")) # keeps build_dynaword's read/drop_* counts
84
+ stats.update(
85
+ kept=kept.num_rows,
86
+ drop_eltec_dup=table.num_rows - kept.num_rows,
87
+ chars=pc.sum(pc.utf8_length(kept.column("text"))).as_py(),
88
+ tokens=pc.sum(kept.column("token_count")).as_py(),
89
+ licenses=dict(sorted(Counter(kept.column("license").to_pylist()).items())),
90
+ authors_with_value=sum(map(bool, kept.column("author").to_pylist())),
91
+ input_sha256=INPUT_SHA256,
92
+ eltec_sha256=ELTEC_SHA256,
93
+ )
94
+ drops = ("drop_short", "drop_lang", "drop_dup", "drop_ocr", "drop_eltec_dup")
95
+ if stats["read"] - sum(stats[k] for k in drops) != stats["kept"]:
96
+ raise SystemExit("stats drop counts do not add up to the kept rows")
97
+
98
+ staged = {
99
+ out_dir / f"{SOURCE}.parquet.tmp": lambda p: pq.write_table(kept, p, compression="zstd"),
100
+ out_dir / f"{PAIRS}.tmp": lambda p: _write_pairs(p, pairs),
101
+ out_dir / f"{SOURCE}.stats.json.tmp": lambda p: p.write_text(
102
+ json.dumps(stats, indent=2, ensure_ascii=False) + "\n", encoding="utf-8"),
103
+ }
104
+ for path, write in staged.items():
105
+ write(path)
106
+ for path in staged:
107
+ os.replace(path, path.with_suffix(""))
108
+ return stats
109
+
110
+
111
+ def _write_pairs(path: Path, pairs: list[dict]) -> None:
112
+ with path.open("w", encoding="utf-8", newline="") as handle:
113
+ writer = csv.DictWriter(handle, ["wl_id", "eltec_id", "score", "action", "wl_title"],
114
+ delimiter="\t", lineterminator="\n")
115
+ writer.writeheader()
116
+ writer.writerows(sorted(pairs, key=lambda p: (p["eltec_id"], p["wl_id"])))
117
+
118
+
119
+ def main() -> None:
120
+ parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
121
+ parser.add_argument("--input", type=Path, default=DATA / f"{SOURCE}.parquet")
122
+ parser.add_argument("--eltec", type=Path, default=ELTEC)
123
+ parser.add_argument("--out", type=Path, default=DATA)
124
+ args = parser.parse_args()
125
+ print(json.dumps(build(args.input, args.eltec, args.out), indent=2, ensure_ascii=False))
126
+
127
+
128
+ if __name__ == "__main__":
129
+ main()
src/shingle_containment.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shingle containment between documents and a set of reference documents.
2
+
3
+ Shared by the cross-source dedup filters (src/clean_wolne_lektury.py, src/clean_1000_novels.py).
4
+ S() is the set of K-word shingles over NFKC-casefolded \\w+ tokens, the tokenisation of the repo's
5
+ near_dedup. Containment, not Jaccard: a document is scored by the share of its own shingles that
6
+ a reference holds, because Wolne Lektury splits long novels into tomes.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ import re
12
+ import unicodedata
13
+ from functools import lru_cache
14
+ from typing import NamedTuple
15
+
16
+ import numpy as np
17
+
18
+ K = 5
19
+ WORD = re.compile(r"\w+")
20
+ # Odd 64-bit multipliers that mix the K word hashes of a shingle in order.
21
+ MULT = np.array([0x9E3779B97F4A7C15, 0xC2B2AE3D27D4EB4F, 0x165667B19E3779F9,
22
+ 0xD6E8FEB86659FD93, 0xFF51AFD7ED558CCD], dtype=np.uint64)
23
+
24
+
25
+ def strip_wl_footer(text: str) -> str:
26
+ """Text before a trailing "-----" footer that names wolnelektury, else the text unchanged."""
27
+ j = text.rfind("\n-----")
28
+ if j >= 0 and len(text) - j < 5000 and "wolnelektury" in text[j:].lower():
29
+ return text[:j]
30
+ return text
31
+
32
+
33
+ @lru_cache(maxsize=None)
34
+ def _word_hash(word: str) -> int:
35
+ # blake2b, not hash(): str hashing is salted per process, and the scores must be reproducible.
36
+ return int.from_bytes(hashlib.blake2b(word.encode("utf-8"), digest_size=8).digest(), "little")
37
+
38
+
39
+ def shingles(text: str) -> np.ndarray:
40
+ """Sorted unique uint64 hashes of the text's K-word shingles."""
41
+ words = WORD.findall(unicodedata.normalize("NFKC", text).casefold())
42
+ n = len(words) - K + 1
43
+ if n <= 0:
44
+ return np.empty(0, np.uint64)
45
+ h = np.fromiter((_word_hash(w) for w in words), dtype=np.uint64, count=len(words))
46
+ s = np.zeros(n, np.uint64)
47
+ for i in range(K):
48
+ s += h[i:i + n] * MULT[i]
49
+ s ^= s >> np.uint64(31)
50
+ return np.unique(s)
51
+
52
+
53
+ class Match(NamedTuple):
54
+ """How much of one document's shingle set the references hold."""
55
+ shingles: int # unique shingles in the document
56
+ covered: int # of those, how many occur in at least one reference
57
+ refs: np.ndarray # indices of the references sharing at least one shingle, ascending
58
+ shared: np.ndarray # shingles shared with each of those references
59
+
60
+ @property
61
+ def cover(self) -> float:
62
+ """Share of the document's shingles found in any reference (the union of the references)."""
63
+ return self.covered / self.shingles if self.shingles else 0.0
64
+
65
+ def best(self) -> tuple[int, float]:
66
+ """(index of the reference holding most shingles, share it holds); (-1, 0.0) if none."""
67
+ if not len(self.refs):
68
+ return -1, 0.0
69
+ i = int(self.shared.argmax()) # ties go to the lowest reference index
70
+ return int(self.refs[i]), self.shared[i] / self.shingles
71
+
72
+
73
+ def containment(docs: list[str], refs: list[str]) -> list[Match]:
74
+ """Match every doc against all refs at once."""
75
+ sets = [shingles(text) for text in refs] or [np.empty(0, np.uint64)]
76
+ hashes = np.concatenate(sets)
77
+ owner = np.concatenate([np.full(len(s), i, np.int32) for i, s in enumerate(sets)])
78
+ order = np.argsort(hashes, kind="stable")
79
+ hashes, owner = hashes[order], owner[order]
80
+ out = []
81
+ for text in docs:
82
+ a = shingles(text)
83
+ lo, hi = np.searchsorted(hashes, a, "left"), np.searchsorted(hashes, a, "right")
84
+ lens = hi - lo
85
+ # Every (doc shingle, ref) hit: each ref's set is unique, so a shingle counts once per ref.
86
+ idx = np.repeat(lo - np.cumsum(lens) + lens, lens) + np.arange(lens.sum())
87
+ ref_ids, shared = np.unique(owner[idx], return_counts=True)
88
+ out.append(Match(len(a), int((lens > 0).sum()), ref_ids, shared))
89
+ return out
90
+
91
+
92
+ def best_containment(docs: list[str], refs: list[str]) -> list[tuple[int, float]]:
93
+ """For each doc: (index of the ref holding most of its shingles, share held), (-1, 0.0) if none."""
94
+ return [m.best() for m in containment(docs, refs)]
src/sources.py CHANGED
@@ -311,6 +311,13 @@ SOURCES = {
311
  "upstream": "https://wolnelektury.pl/api/books/",
312
  "domain": "literature",
313
  "created": "1500-01-01, 2024-12-31",
 
 
 
 
 
 
 
314
  "is_ocr": False,
315
  },
316
  "wikinews": {
@@ -710,13 +717,11 @@ SOURCES = {
710
  "Reduced by src/clean_1000_novels.py to the public-domain texts of the "
711
  "per-text rights screen; text unchanged.",
712
  "legal_note": "Public domain in Poland only (Art. 36, life + 70); status in other "
713
- "jurisdictions not assessed. 12 rows rely on Wolne Lektury's "
714
- "public-domain footer. Edition rights (Art. 99^1-99^2) not assessed.",
715
  "license": "public-domain",
716
  "license_spdx": "LicenseRef-Public-Domain-PL",
717
  "traceable": "Only texts in the public domain in Poland are kept: the author and "
718
- "every credited translator died in 1955 or earlier (Art. 36), or the "
719
- "retained Wolne Lektury footer states no economic copyright. Per-text "
720
  "screen: polish-dynaword-v2/evidence/1000_novels_rights_screen.csv; "
721
  "author, translator, title and basis per row in "
722
  "1000_novels.attribution.jsonl. The CLARIN-PL CC BY 4.0 record covers "
@@ -733,9 +738,10 @@ SOURCES = {
733
  "global_voices": {
734
  "added": "2026-07-15",
735
  "release": "0.2.3",
736
- # Data contributed directly (PR #7): no in-repo fetch/build script and a
737
- # hand-authored datasheet. Registered for the source table + release totals;
738
- # the datasheet stays contributor-owned via custom_datasheet.
 
739
  "file_key": "global_voices",
740
  "pretty": "Global Voices Polish",
741
  "license": "CC-BY-3.0",
@@ -744,6 +750,17 @@ SOURCES = {
744
  "with each retained Global Voices article; each record carries "
745
  "CC-BY-3.0 metadata and per-document author/translator attribution "
746
  "in global_voices.attribution.jsonl.",
 
 
 
 
 
 
 
 
 
 
 
747
  "upstream": "https://pl.globalvoices.org/",
748
  "domain": "civic media, news and public-interest journalism",
749
  "created": "2008-11-04, 2023-05-24",
 
311
  "upstream": "https://wolnelektury.pl/api/books/",
312
  "domain": "literature",
313
  "created": "1500-01-01, 2024-12-31",
314
+ "legal_note": "For v0.2.6, 63 documents whose text is an eltec_pol novel are dropped "
315
+ "(share of a document's 5-word shingles found in one ELTeC novel >= 0.9; "
316
+ "src/clean_wolne_lektury.py, polish-dynaword-v2#72). eltec_pol keeps those "
317
+ "50 novels whole under CC BY 4.0. Three documents only partly in an ELTeC "
318
+ "novel are kept: both tomes of Mniszek's Trędowata (the ELTeC text is "
319
+ "shorter) and Kochanowski's Pieśń IX, quoted in Łoziński's Oko proroka. "
320
+ "Every pair is listed in wolne_lektury.eltec_pairs.tsv.",
321
  "is_ocr": False,
322
  },
323
  "wikinews": {
 
717
  "Reduced by src/clean_1000_novels.py to the public-domain texts of the "
718
  "per-text rights screen; text unchanged.",
719
  "legal_note": "Public domain in Poland only (Art. 36, life + 70); status in other "
720
+ "jurisdictions not assessed. Edition rights (Art. 99^1-99^2) not assessed.",
 
721
  "license": "public-domain",
722
  "license_spdx": "LicenseRef-Public-Domain-PL",
723
  "traceable": "Only texts in the public domain in Poland are kept: the author and "
724
+ "every credited translator died in 1955 or earlier (Art. 36). Per-text "
 
725
  "screen: polish-dynaword-v2/evidence/1000_novels_rights_screen.csv; "
726
  "author, translator, title and basis per row in "
727
  "1000_novels.attribution.jsonl. The CLARIN-PL CC BY 4.0 record covers "
 
738
  "global_voices": {
739
  "added": "2026-07-15",
740
  "release": "0.2.3",
741
+ # Data contributed directly (PR #7) with a hand-authored datasheet; no fetch
742
+ # script. src/clean_global_voices.py drops partner republications from it.
743
+ # Registered for the source table + release totals; the datasheet stays
744
+ # contributor-owned via custom_datasheet.
745
  "file_key": "global_voices",
746
  "pretty": "Global Voices Polish",
747
  "license": "CC-BY-3.0",
 
750
  "with each retained Global Voices article; each record carries "
751
  "CC-BY-3.0 metadata and per-document author/translator attribution "
752
  "in global_voices.attribution.jsonl.",
753
+ "provenance": "Contributed directly (PR #7) from pl.globalvoices.org. "
754
+ "src/clean_global_voices.py filters the v0.2.5 Parquet and "
755
+ "attribution sidecar (pinned by SHA-256) to drop partner "
756
+ "republications: 2,040 -> 1,926 documents.",
757
+ "legal_note": "Posts Global Voices republished from partner outlets are dropped "
758
+ "(114 posts from 51 outlets, among them PRI's The World, The Stand "
759
+ "News, Hong Kong Free Press, Agência Pública, Meta.mk and 350.org). "
760
+ "Their text is the partner's work, not content created by Global "
761
+ "Voices under its CC BY 3.0 grant. The rule matches the "
762
+ "republication note in a post's opening or closing lines; posts "
763
+ "contributors cross-posted from their own blogs are kept.",
764
  "upstream": "https://pl.globalvoices.org/",
765
  "domain": "civic media, news and public-interest journalism",
766
  "created": "2008-11-04, 2023-05-24",
src/test_1000_novels_contract.py CHANGED
@@ -4,8 +4,9 @@ import json
4
  from pathlib import Path
5
 
6
  import pyarrow.parquet as pq
 
7
 
8
- from clean_1000_novels import credit, file_slug, title_of
9
 
10
  ROOT = Path(__file__).resolve().parents[1]
11
  DATA = ROOT / "data" / "1000_novels"
@@ -17,14 +18,14 @@ def test_schema_counts_and_attribution():
17
  rows = table.select(["id", "source", "license", "author"]).to_pylist()
18
  sidecar = [json.loads(line) for line in (DATA / "1000_novels.attribution.jsonl").read_text(encoding="utf-8").splitlines()]
19
  assert table.column_names == ["id", "text", "source", "added", "created", "token_count", "license", "author"]
20
- assert table.num_rows == stats["kept"] == len(sidecar) == stats["screen"]["pd_by_term"] + stats["screen"]["pd_per_wolne_lektury"]
 
21
  assert len({r["id"] for r in rows}) == table.num_rows
22
  assert {r["source"] for r in rows} == {"1000_novels"}
23
  assert {r["license"] for r in rows} == {a["license"] for a in sidecar} == {"public-domain"}
24
- assert {a["screen"] for a in sidecar} <= {"pd_by_term", "pd_per_wolne_lektury"}
25
  scope = json.loads((DATA / "1000_novels.license-evidence.json").read_text(encoding="utf-8"))["release_scope"]
26
  assert scope == {"screened": stats["read"], "kept": stats["kept"], "pd_by_term": stats["screen"]["pd_by_term"],
27
- "pd_per_wolne_lektury": stats["screen"]["pd_per_wolne_lektury"],
28
  "dropped_in_copyright": stats["screen"]["in_copyright"], "dropped_unresolved": stats["screen"]["unresolved"]}
29
  by_id = {a["id"]: a for a in sidecar}
30
  assert by_id.keys() == {r["id"] for r in rows}
@@ -35,6 +36,20 @@ def test_schema_counts_and_attribution():
35
  assert bool(a["title"]) == (a["title_from"] != "none")
36
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  def test_title_rules():
39
  assert file_slug("sienkiewicz_krzyzacy_tom-II_1900.txt") == "krzyzacy-tom-ii"
40
  assert title_of("Henryk Sienkiewicz\nKrzyżacy\nTom II\n", "sienkiewicz_krzyzacy_tom-II_1900.txt", "Henryk Sienkiewicz") == ("Krzyżacy Tom II", "file")
 
4
  from pathlib import Path
5
 
6
  import pyarrow.parquet as pq
7
+ import pytest
8
 
9
+ from clean_1000_novels import SCREEN_SHA256, build, credit, file_slug, title_of
10
 
11
  ROOT = Path(__file__).resolve().parents[1]
12
  DATA = ROOT / "data" / "1000_novels"
 
18
  rows = table.select(["id", "source", "license", "author"]).to_pylist()
19
  sidecar = [json.loads(line) for line in (DATA / "1000_novels.attribution.jsonl").read_text(encoding="utf-8").splitlines()]
20
  assert table.column_names == ["id", "text", "source", "added", "created", "token_count", "license", "author"]
21
+ assert table.num_rows == stats["kept"] == len(sidecar) == stats["screen"]["pd_by_term"]
22
+ assert stats["screen"].keys() <= {"pd_by_term", "in_copyright", "unresolved"}
23
  assert len({r["id"] for r in rows}) == table.num_rows
24
  assert {r["source"] for r in rows} == {"1000_novels"}
25
  assert {r["license"] for r in rows} == {a["license"] for a in sidecar} == {"public-domain"}
26
+ assert {a["screen"] for a in sidecar} == {"pd_by_term"}
27
  scope = json.loads((DATA / "1000_novels.license-evidence.json").read_text(encoding="utf-8"))["release_scope"]
28
  assert scope == {"screened": stats["read"], "kept": stats["kept"], "pd_by_term": stats["screen"]["pd_by_term"],
 
29
  "dropped_in_copyright": stats["screen"]["in_copyright"], "dropped_unresolved": stats["screen"]["unresolved"]}
30
  by_id = {a["id"]: a for a in sidecar}
31
  assert by_id.keys() == {r["id"] for r in rows}
 
36
  assert bool(a["title"]) == (a["title_from"] != "none")
37
 
38
 
39
+
40
+ def test_screen_pin_matches_license_evidence_and_stats():
41
+ evidence = json.loads((DATA / "1000_novels.license-evidence.json").read_text(encoding="utf-8"))
42
+ stats = json.loads((DATA / "1000_novels.stats.json").read_text(encoding="utf-8"))
43
+ assert SCREEN_SHA256 == evidence["screen_sha256"] == stats["screen_sha256"]
44
+
45
+
46
+ def test_build_rejects_an_unpinned_screen(tmp_path):
47
+ screen = tmp_path / "screen.csv"
48
+ screen.write_text("id,screen\n1000_novels_0001,pd_by_term\n", encoding="utf-8")
49
+ with pytest.raises(SystemExit, match="not the pinned rights screen"):
50
+ build(tmp_path / "unused.parquet", screen, tmp_path)
51
+ assert list(tmp_path.iterdir()) == [screen]
52
+
53
  def test_title_rules():
54
  assert file_slug("sienkiewicz_krzyzacy_tom-II_1900.txt") == "krzyzacy-tom-ii"
55
  assert title_of("Henryk Sienkiewicz\nKrzyżacy\nTom II\n", "sienkiewicz_krzyzacy_tom-II_1900.txt", "Henryk Sienkiewicz") == ("Krzyżacy Tom II", "file")
src/test_global_voices_contract.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Contract checks for the partner-republication drop in global_voices (src/clean_global_voices.py)."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ import pyarrow.parquet as pq
7
+
8
+ from clean_global_voices import DROP, KEEP, note_rules, reason
9
+
10
+ DATA = Path(__file__).resolve().parents[1] / "data" / "global_voices"
11
+ KEPT = 1926 # 2,040 in v0.2.5 minus 114 partner republications
12
+
13
+
14
+ def test_release_has_no_partner_republications():
15
+ stats = json.loads((DATA / "global_voices.stats.json").read_text(encoding="utf-8"))
16
+ table = pq.read_table(DATA / "global_voices.parquet")
17
+ rows = table.to_pylist()
18
+ sidecar = [json.loads(line) for line in (DATA / "global_voices.attribution.jsonl").read_text(encoding="utf-8").splitlines()]
19
+ ids = [r["id"] for r in rows]
20
+ assert table.column_names == ["id", "text", "source", "added", "created", "token_count", "license", "author"]
21
+ assert table.num_rows == stats["kept"] == len(sidecar) == KEPT
22
+ assert stats["read"] == stats["kept"] + stats["drop_short"] + stats["drop_partner_republication"]
23
+ assert stats["chars"] == sum(len(r["text"]) for r in rows)
24
+ assert stats["tokens"] == sum(r["token_count"] for r in rows)
25
+ assert len(set(ids)) == len(ids)
26
+ assert {a["id"] for a in sidecar} == set(ids)
27
+ assert {r["source"] for r in rows} == {"global_voices"}
28
+ assert {r["license"] for r in rows} == {a["license"] for a in sidecar} == {"CC-BY-3.0"}
29
+ assert [i for i, r in zip(ids, rows) if reason(i, r["text"])] == []
30
+ assert not DROP.keys() & set(ids)
31
+ # Every hand exception is still in the release and still needed (a rule matches it).
32
+ texts = dict(zip(ids, (r["text"] for r in rows)))
33
+ assert [i for i in KEEP if not note_rules(texts[i])] == []
34
+
35
+
36
+ def test_note_rules():
37
+ pri = "Ten artykuł autorstwa Jane Doe pierwotnie ukazał się na portalu PRI.org 5 maja 2015 r. i jest publikowany ponownie w ramach umowy o wymianie treści."
38
+ assert note_rules(pri) == ["agreement", "originally", "published_by"]
39
+ assert note_rules("Opublikowano za zgodą PRI.") == ["permission"]
40
+ assert note_rules("Artykuł, napisany przez Giorgiego Lomsadze, jest również dostępny na stronie EurasiaNet.org. Opublikowany za pozwoleniem.") == ["permission"]
41
+ assert note_rules("Ten artykuł został napisany przez Hodę Baraka dla 350.org, organizacji tworzącej ruch na rzecz klimatu.") == ["written_for"]
42
+ assert note_rules("Jest to już trzecia odsłona historii, która pierwotnie została opublikowana w języku chińskim na stronie The Stand News.") == ["originally"]
43
+ assert note_rules("Poniżej publikujemy zredagowaną wersję artykułu, który pojawił się po raz pierwszy na stronie Centrum Praw Człowieka w Iranie.") == ["originally"]
44
+ # Notes are searched only in the opening and closing lines.
45
+ assert note_rules("x " * 1000 + "\nTen artykuł pierwotnie ukazał się na PRI.org.") == ["originally"]
46
+ assert note_rules("x " * 400 + "\nTen artykuł pierwotnie ukazał się na PRI.org.\n" + "y " * 400) == []
47
+ # Photo credits, the author's own consent, news reporting, GV's own projects and look-alike words.
48
+ for text in (
49
+ "Więzienie w Monte Cristo. Zdjęcie: Luiz Silveira, Agence CNJ. Opublikowano za zgodą.",
50
+ "Zdjęcie opublikowane za zgodą Tunisia Live",
51
+ "Ilustracja opublikowana pierwotnie w magazynie Puck 25 stycznia 1899 roku.",
52
+ "Sami Shah. Opublikowane za zgodą autora.",
53
+ "Według raportu opublikowanego przez Amnesty International, 13 tys. osób zginęło.",
54
+ "Artykuł ten został napisany i opublikowany przez Rezwana w ramach projektu Rising Voices",
55
+ "Inicjatywa I Can Help U podsumowuje to wszystko udostępniając zdjęcie poniżej:",
56
+ "Dekret ogranicza naukę rdzennych języków w republikach narodowych Federacji Rosyjskiej.",
57
+ "Tunezyjski blog Nawaat, we współpracy z Ministerstwem Młodzieży, rozpoczął nowy projekt.",
58
+ ):
59
+ assert note_rules(text) == [], text
60
+
61
+
62
+ def test_reason_lists():
63
+ own_blog = "Ten post był pierwotnie opublikowany na blogu Juana Arellano Globalizado [es]."
64
+ assert reason("global_voices_0", own_blog) == "originally+published_by"
65
+ assert reason("global_voices_7749", own_blog) is None
66
+ assert reason("global_voices_32352", "").startswith("listed: ")
67
+ assert reason("global_voices_0", "Zwykły tekst bez noty.") is None
src/test_shingle_containment.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for the shared cross-source containment code (src/shingle_containment.py)."""
2
+
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
7
+
8
+ from shingle_containment import best_containment, containment, shingles, strip_wl_footer
9
+
10
+ NOVEL = " ".join(f"w{i}" for i in range(400))
11
+ OTHER = " ".join(f"x{i}" for i in range(400))
12
+
13
+
14
+ def test_shingles_are_reproducible_across_processes():
15
+ # Fixed values: a salted hash() would change them on every interpreter start.
16
+ assert shingles("Ala ma kota, a kot ma Alę.").tolist() == [
17
+ 1095117514565903941, 11979537242062189157, 12971353317152582320]
18
+ assert shingles("ALA ma\nkota, a kot ma alę").tolist() == shingles("Ala ma kota, a kot ma Alę.").tolist()
19
+ assert shingles("a b c d e").tolist() != shingles("e d c b a").tolist()
20
+ assert len(shingles("a b c d")) == 0
21
+
22
+
23
+ def test_strip_wl_footer_cuts_only_a_trailing_wolne_lektury_footer():
24
+ footer = "\n-----\nTa lektura pochodzi ze strony wolnelektury.pl.\n"
25
+ assert strip_wl_footer("Tekst." + footer) == "Tekst."
26
+ assert strip_wl_footer("Tekst.\n-----\nKoniec.") == "Tekst.\n-----\nKoniec."
27
+ assert strip_wl_footer("Tekst." + footer + "x" * 5000) == "Tekst." + footer + "x" * 5000
28
+
29
+
30
+ def test_best_containment_finds_tomes_and_partial_copies():
31
+ words = NOVEL.split()
32
+ tome = " ".join(words[100:300]).upper()
33
+ half = " ".join(words[:100] + OTHER.split()[:100])
34
+ unrelated = " ".join(f"y{i}" for i in range(50))
35
+ novels = [" ".join(OTHER.split()[:50]), NOVEL]
36
+ scores = best_containment([tome, half, unrelated, "za krótki", NOVEL], novels)
37
+ assert scores[0] == (1, 1.0)
38
+ assert scores[1][0] == 1 and 0.45 < scores[1][1] < 0.55 # novel 1 holds more than novel 0
39
+ assert scores[2] == scores[3] == (-1, 0.0)
40
+ assert scores[4] == (1, 1.0)
41
+
42
+
43
+ def test_cover_is_the_union_of_the_references():
44
+ words = NOVEL.split()
45
+ tomes = [" ".join(words[:200]), " ".join(words[196:])] # two tomes, no shingle in both
46
+ whole, empty = containment([NOVEL, ""], tomes)
47
+ assert whole.shingles == whole.covered == 396 and whole.cover == 1.0
48
+ assert whole.refs.tolist() == [0, 1] and whole.shared.tolist() == [196, 200]
49
+ assert whole.best() == (1, 200 / 396) # no single tome holds half of it
50
+ assert (empty.shingles, empty.covered, empty.cover, empty.best()) == (0, 0, 0.0, (-1, 0.0))
51
+ [alone] = containment([NOVEL], [])
52
+ assert (alone.covered, alone.cover, alone.best()) == (0, 0.0, (-1, 0.0))
src/test_wolne_lektury_contract.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Contract checks for wolne_lektury after the eltec_pol dedup (src/clean_wolne_lektury.py, v2#72)."""
2
+
3
+ import csv
4
+ import hashlib
5
+ import json
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ import pyarrow as pa
10
+ import pyarrow.compute as pc
11
+ import pyarrow.parquet as pq
12
+ import pytest
13
+
14
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
15
+
16
+ from clean_wolne_lektury import (DATA, DROP_AT, ELTEC, ELTEC_SHA256, PAIRS, REPORT_AT, build,
17
+ wl_title)
18
+
19
+ # Hand-checked: only part of each is in its ELTeC novel, so they stay (see the findings entry).
20
+ PARTIAL_IDS = {"wolne_lektury_2375475", "wolne_lektury_2375476", "wolne_lektury_2376242"}
21
+
22
+
23
+ def test_wl_title_is_the_first_two_nonempty_lines():
24
+ assert wl_title("Stefan Żeromski\n\nDzieje grzechu\n\nISBN 1\n\nText") == "Stefan Żeromski / Dzieje grzechu"
25
+
26
+
27
+ def test_build_fails_closed_on_unpinned_inputs(tmp_path):
28
+ fake = tmp_path / "wolne_lektury.parquet"
29
+ pq.write_table(pa.table({"id": ["a"], "text": ["b"]}), fake)
30
+ with pytest.raises(SystemExit, match="pinned SHA-256"):
31
+ build(fake, ELTEC, tmp_path)
32
+ assert sorted(p.name for p in tmp_path.iterdir()) == ["wolne_lektury.parquet"]
33
+
34
+
35
+ def test_release_has_no_eltec_duplicates_and_matches_stats():
36
+ stats = json.loads((DATA / "wolne_lektury.stats.json").read_text(encoding="utf-8"))
37
+ table = pq.read_table(DATA / "wolne_lektury.parquet")
38
+ ids = set(table.column("id").to_pylist())
39
+ with (DATA / PAIRS).open(encoding="utf-8", newline="") as handle:
40
+ pairs = list(csv.DictReader(handle, delimiter="\t"))
41
+ dropped = {p["wl_id"] for p in pairs if p["action"] == "drop"}
42
+ partial = {p["wl_id"] for p in pairs if p["action"] == "keep_partial"}
43
+
44
+ assert table.num_rows == len(ids) == stats["kept"] == 6_078
45
+ assert len(dropped) == stats["drop_eltec_dup"] == 63
46
+ assert partial == PARTIAL_IDS
47
+ assert not dropped & ids and partial <= ids
48
+ assert all(float(p["score"]) >= DROP_AT for p in pairs if p["action"] == "drop")
49
+ assert all(REPORT_AT <= float(p["score"]) < DROP_AT for p in pairs if p["action"] == "keep_partial")
50
+ assert all(p["eltec_id"].startswith("eltec_pol_") for p in pairs)
51
+ drops = ("drop_short", "drop_lang", "drop_dup", "drop_ocr", "drop_eltec_dup")
52
+ assert stats["read"] - sum(stats[k] for k in drops) == stats["kept"]
53
+ assert pc.sum(table.column("token_count")).as_py() == stats["tokens"]
54
+ assert pc.sum(pc.utf8_length(table.column("text"))).as_py() == stats["chars"]
55
+ assert stats["licenses"] == {"CC-BY-SA-4.0 / Wolna Sztuka 1.3": stats["kept"]} # #57 relabels later
56
+ with ELTEC.open("rb") as stream: # eltec_pol is kept whole
57
+ assert hashlib.file_digest(stream, "sha256").hexdigest() == ELTEC_SHA256
58
+
59
+
60
+ def test_datasheet_counts_match_stats():
61
+ stats = json.loads((DATA / "wolne_lektury.stats.json").read_text(encoding="utf-8"))
62
+ card = (DATA / "wolne_lektury.md").read_text(encoding="utf-8")
63
+ assert f"| {stats['kept']:,} | {stats['chars']:,} | {stats['tokens']:,} |" in card
64
+ assert f"{stats['drop_eltec_dup']} " in card and "eltec_pol" in card