wikipedia: licence labels by contribution date (v2#110), seven pages withheld

#128
by ppuzio - opened
artifacts/source_findings.md CHANGED
@@ -2281,8 +2281,8 @@ faults in `drop_residue`, fixed for every source:
2281
  they can be a sentence about the option; they are now removed only next to a pipe;
2282
  - the trailing-options rule took the `| class=...` of a table start `{| class=...` for a file
2283
  option and left a lone `{`; it now skips a pipe after `{`. Four wikivoyage rows released in Hub
2284
- PR 125 have this fault (`wikivoyage_2055`, `2564`, `9129`, `10490`); a follow-up PR rebuilds
2285
- them.
2286
 
2287
  Known limits, as matched in the cleaned text (documents; a match is not always residue):
2288
  `...thumb|` glued to the word before it 10, a line holding only `mały` 18, `Kategoria:` inside a
@@ -2340,6 +2340,91 @@ both. `wikibooks_3083`, whose page states CC BY-SA 3.0, was 4.0 by its last edit
2340
 
2341
  README, CHANGELOG and totals are left to v2#80.
2342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2343
  ## `studia_bas`: licence version resolved to CC BY 3.0 PL
2344
 
2345
  **Investigated:** 2026-10-06
 
2281
  they can be a sentence about the option; they are now removed only next to a pipe;
2282
  - the trailing-options rule took the `| class=...` of a table start `{| class=...` for a file
2283
  option and left a lone `{`; it now skips a pipe after `{`. Four wikivoyage rows released in Hub
2284
+ PR 125 have this fault (`wikivoyage_2055`, `2564`, `9129`, `10490`). A rebuild would only
2285
+ turn the lone `{` back into the table markup `{| class="wikitable"`, so they are not rebuilt.
2286
 
2287
  Known limits, as matched in the cleaned text (documents; a match is not always residue):
2288
  `...thumb|` glued to the word before it 10, a line holding only `mały` 18, `Kategoria:` inside a
 
2340
 
2341
  README, CHANGELOG and totals are left to v2#80.
2342
 
2343
+ ## wikipedia — licence labels by contribution date, seven pages withheld (update to the sections above)
2344
+
2345
+ **Investigated** — 2026-10-18 (slayerlabs/polish-dynaword-v2#110 option B, as for wikivoyage and
2346
+ wikibooks above; the deletion logs of released pages missing from the 2026-10-01 stub dump).
2347
+
2348
+ **Verdict** — `kept`, seven more pages withheld, relabelled: 1,468,647 documents, 3,140,823,417
2349
+ characters, 1,226,906,115 tokens (was 1,468,654 / 3,140,838,409 / 1,226,912,191). Labels per
2350
+ record: `CC-BY-SA-3.0` 719,119 documents (364,335,667 tokens, 29.7%), `CC-BY-SA-3.0 AND
2351
+ CC-BY-SA-4.0` 629,454 (765,350,761, 62.4%), `CC-BY-SA-4.0` 120,074 (97,219,687, 7.9%). The
2352
+ last-revision labels of the sections above were 3.0 190,836 (81,022,938 tokens) and 4.0
2353
+ 1,277,818 (1,145,889,253). Every 3.0 row stays 3.0; of the 1,277,811 4.0 rows still released,
2354
+ 528,283 are now 3.0, 629,454 both and 120,074 stay 4.0. Each sidecar line gains `license_basis`
2355
+ and `pre_cutoff_revid`; the build record holds the stub dump and the count per basis; the card
2356
+ explains each basis.
2357
+
2358
+ **Withheld: seven pages deleted from plwiki for copyright after the dump** —
2359
+ `wikipedia_4095632` Brzezina (opowiadanie), deleted 2026-09-01, log reason "Naruszenie praw
2360
+ autorskich" with a studocu.com link (not fetched); `wikipedia_6131122` Edmund Bielecki, `6131594`
2361
+ Ryszard Cyffer, `6131631` Stanisław Czarnomski, `6131646` Mikołaj Dmochowski (deleted
2362
+ 2026-09-05), `6132108` Włodzimierz Daszkiewicz and `6132151` Konstanty Jankowski (oficer)
2363
+ (2026-09-06), log reason "naruszenie praw autorskich". 14,992 characters, 6,076 tokens, all
2364
+ labelled 4.0 by their last revision. None is in the stub dump, so their history cannot be
2365
+ checked. They are in `COPIED_PAGES` (9 pages now) with the day and the log reason.
2366
+ `fetch_wikipedia.py withhold` drops a page listed after the build from the committed release, as
2367
+ `prepare` would, and adds it to the copyright sample's `rows_dropped_since`, so the sample's draw
2368
+ still reproduces; it refuses to run after `relabel`.
2369
+
2370
+ **No residue cleanup (v2#116)** — `strip_article` already drops category and file links, so
2371
+ `drop_residue` is not applied. Run on this release it would change 426 documents and remove
2372
+ 477,849 characters, nearly all content: flattened medal tables whose line starts
2373
+ `Kategoria:Złoto:Srebro:Brąz:` and goes on with the results (`wikipedia_1515505`), and field
2374
+ labels such as `Kategoria: olej nieschnący` (`wikipedia_127177`). v2#116 read the 410 rows with a
2375
+ `Kategoria:` line as medal-table headers; most are, but 14 documents hold a category link on a
2376
+ line of its own (16 lines, e.g. `wikipedia_103834` `Kategoria:Wielcy marszałkowie zakonu
2377
+ krzyżackiego`), left by malformed links. Also left: 13 documents with an unclosed file link
2378
+ (`[[Plik:...|thumb|...`, `wikipedia_13010`) and 363 with `<ref`. Listed in the card, not cleaned
2379
+ in v0.2.6.
2380
+
2381
+ **Enumeration** — `plwiki-20261001-stub-meta-history.xml.gz` (7,039,541,375 bytes, sha1
2382
+ `47fd7549…` matched to the dump's `dumpstatus.json`, 2026-10-18). plwiki's stub dump is written
2383
+ in parts; the whole file is listed under the `xmlstubsdumprecombine` job, which
2384
+ `wiki_history.download` now reads. 190,836 pages were last edited before the cutoff (3.0);
2385
+ 120,074 have no revision before it (4.0); for 5,028 the shipped revision's sha1 equals the
2386
+ pre-cutoff one (3.0). For the other 1,152,624 the pre-cutoff revision was fetched from the
2387
+ pl.wikipedia.org API by revision id, converted with `strip_article` and compared as for
2388
+ wikivoyage: 492,757 give the shipped text and 30,498 lose words only (3.0); 629,338 gain at least
2389
+ one word (both); for 31 the pre-cutoff text is hidden (both). 85 pages edited after the cutoff
2390
+ are not in the stub dump (both, below). `compare` ran as 12 sidecar slices in parallel, joined in
2391
+ sidecar order (a test checks that joined slices equal one run); its labels were computed before
2392
+ the withholding and filtered to the sidecar after it. A rerun of relabel is byte-identical.
2393
+
2394
+ The cutoff day: 76 pages created on 2023-06-07 are 4.0 alone. Of the 184 documents last edited
2395
+ that day, 37 gain words only through that day's edits (both) and 4 were created that day (4.0);
2396
+ if the switch came later that day, those 41 are 3.0 alone.
2397
+
2398
+ **Deleted from plwiki since the dump** — 104 released pages (before the withholding) are missing
2399
+ from the stub dump. The deletion log of each was read from the pl.wikipedia API
2400
+ (`list=logevents` by title) and classed by its latest deletion: 7 for a copyright violation
2401
+ (withheld, above); 88 after a deletion discussion (Poczekalnia); 7 as a duplicate, needless
2402
+ disambiguation, advertising, spam or nonsense (`wikipedia_239449` Monceaux (Calvados), `1342574`
2403
+ Rhenus, `2550999` Odcinacz, `2977355` Feliks (męczennik), `5437048` Gropa (Połonina Czerwona),
2404
+ `5860110` Chór Akademicki Uniwersytetu Szczecińskiego, `5964373` Softswiss); 2 for a history
2405
+ merge or a move and then restored (`wikipedia_99795` Młotogłów wielkogłowy, 2026-09-18;
2406
+ `wikipedia_1105144` 103 męczenników koreańskich, 2026-09-21). Of the 97 still released, 85 are
2407
+ labelled both (no history to compare) and 12 were last edited before the cutoff (3.0 by their
2408
+ shipped revision). They are kept: their deletions are a quality call, not a rights one.
2409
+ `wikipedia_4033410` Teatr Piosenki Młyn, deleted after a discussion on 2026-09-30, was also
2410
+ deleted for copyright on 2017-05-23 and recreated by 2017-07-14; the released text was not
2411
+ compared with the deleted one. Counts per class are in the evidence's `deleted_since_dump`.
2412
+
2413
+ **Blockers** — none to merge. Open:
2414
+ - Any added word makes a page 3.0 and 4.0; there is no threshold.
2415
+ - Text moved or merged from an older page into a page created after the cutoff is labelled 4.0
2416
+ alone.
2417
+ - The time of day of the switch (the cutoff day above).
2418
+ - The comparison is on converted text, so words that `strip_article` drops (templates, `<ref>`
2419
+ bodies) are not compared.
2420
+ - The 95 pages deleted after a discussion or as spam or duplicates stay in the release; Młyn is
2421
+ not compared; pages deleted after 2026-10-01 and other pages by the authors of the seven are
2422
+ not checked.
2423
+ - As in the sections above: pastes beyond the copyright sample, GFDL-era text, appendix headings,
2424
+ the NERGAL pass.
2425
+
2426
+ README, CHANGELOG and totals are left to v2#80.
2427
+
2428
  ## `studia_bas`: licence version resolved to CC BY 3.0 PL
2429
 
2430
  **Investigated:** 2026-10-06
data/wikipedia/wikipedia.attribution.jsonl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:046067a7992e0f98950ba6d7e0e8b7499e75e58bb5aac0a64e0779e6d69e0a2e
3
- size 344192023
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aac58a47f87d548e0a42477e41a686a18705b86b95b25f2ce45d89d27bf38d09
3
+ size 455694527
data/wikipedia/wikipedia.build.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
- "attribution_rows": 1468654,
3
- "attribution_sha256": "046067a7992e0f98950ba6d7e0e8b7499e75e58bb5aac0a64e0779e6d69e0a2e",
4
  "by_sa_4_cutoff": "2023-06-07T00:00:00+00:00",
5
  "copyvio_tagged": [
6
  {
@@ -199,6 +199,26 @@
199
  "url": "https://dumps.wikimedia.org/plwiki/20260901/plwiki-20260901-pages-articles6.xml-p4962394p6142332.bz2"
200
  }
201
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  "prepare": {
203
  "copied_pages": [
204
  {
@@ -210,12 +230,47 @@
210
  "pageid": "1126780",
211
  "reason": "Czarnka: the lake paragraph (revision 42979631, 2015-06-19) closely paraphrases the Drawieński Park Narodowy page dpn.pl/czarne, archived 2012-01-25; whether Art. 4 of the Polish copyright act (official materials) applies was not assessed",
212
  "title": "Czarnka"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  }
214
  ],
215
  "counts": {
216
  "CC-BY-SA-3.0": 284075,
217
- "CC-BY-SA-4.0": 1421860,
218
- "copied_page": 2,
219
  "ek_copyright": 0,
220
  "exact_duplicate": 382,
221
  "extracted": 1706319
 
1
  {
2
+ "attribution_rows": 1468647,
3
+ "attribution_sha256": "aac58a47f87d548e0a42477e41a686a18705b86b95b25f2ce45d89d27bf38d09",
4
  "by_sa_4_cutoff": "2023-06-07T00:00:00+00:00",
5
  "copyvio_tagged": [
6
  {
 
199
  "url": "https://dumps.wikimedia.org/plwiki/20260901/plwiki-20260901-pages-articles6.xml-p4962394p6142332.bz2"
200
  }
201
  ],
202
+ "licence_labels": {
203
+ "cases": {
204
+ "changed_after_cutoff": 629338,
205
+ "created_after_cutoff": 120074,
206
+ "identical_text": 492757,
207
+ "no_text_added": 30498,
208
+ "page_not_in_dump": 85,
209
+ "pre_text_hidden": 31,
210
+ "same_revision_text": 5028,
211
+ "shipped_before_cutoff": 190836
212
+ },
213
+ "created_on_cutoff_day": 76,
214
+ "stub": {
215
+ "checked_at": "2026-10-18",
216
+ "name": "plwiki-20261001-stub-meta-history.xml.gz",
217
+ "sha1": "47fd7549026521bd02c174ee418c63a93f7e4118",
218
+ "size": 7039541375,
219
+ "url": "https://dumps.wikimedia.org/plwiki/20261001/plwiki-20261001-stub-meta-history.xml.gz"
220
+ }
221
+ },
222
  "prepare": {
223
  "copied_pages": [
224
  {
 
230
  "pageid": "1126780",
231
  "reason": "Czarnka: the lake paragraph (revision 42979631, 2015-06-19) closely paraphrases the Drawieński Park Narodowy page dpn.pl/czarne, archived 2012-01-25; whether Art. 4 of the Polish copyright act (official materials) applies was not assessed",
232
  "title": "Czarnka"
233
+ },
234
+ {
235
+ "pageid": "4095632",
236
+ "reason": "Brzezina (opowiadanie): deleted from plwiki on 2026-09-01 for a copyright violation, deletion log: \"Naruszenie praw autorskich: https://www.studocu.com/pl/document/uniwersytet-jagiellonski/filologia-polska/proza-poetycka-i-awangardowa-iwaszkiewicz-jasienski-choromanski/74568413\"",
237
+ "title": "Brzezina (opowiadanie)"
238
+ },
239
+ {
240
+ "pageid": "6131122",
241
+ "reason": "Edmund Bielecki: deleted from plwiki on 2026-09-05 for a copyright violation, deletion log: \"[[Wikipedia:Prawa autorskie|naruszenie praw autorskich]]\"",
242
+ "title": "Edmund Bielecki"
243
+ },
244
+ {
245
+ "pageid": "6131594",
246
+ "reason": "Ryszard Cyffer: deleted from plwiki on 2026-09-05 for a copyright violation, deletion log: \"[[Wikipedia:Prawa autorskie|naruszenie praw autorskich]]\"",
247
+ "title": "Ryszard Cyffer"
248
+ },
249
+ {
250
+ "pageid": "6131631",
251
+ "reason": "Stanisław Czarnomski: deleted from plwiki on 2026-09-05 for a copyright violation, deletion log: \"[[Wikipedia:Prawa autorskie|naruszenie praw autorskich]]\"",
252
+ "title": "Stanisław Czarnomski"
253
+ },
254
+ {
255
+ "pageid": "6131646",
256
+ "reason": "Mikołaj Dmochowski: deleted from plwiki on 2026-09-05 for a copyright violation, deletion log: \"[[Wikipedia:Prawa autorskie|naruszenie praw autorskich]]\"",
257
+ "title": "Mikołaj Dmochowski"
258
+ },
259
+ {
260
+ "pageid": "6132108",
261
+ "reason": "Włodzimierz Daszkiewicz: deleted from plwiki on 2026-09-06 for a copyright violation, deletion log: \"[[Wikipedia:Prawa autorskie|naruszenie praw autorskich]]\"",
262
+ "title": "Włodzimierz Daszkiewicz"
263
+ },
264
+ {
265
+ "pageid": "6132151",
266
+ "reason": "Konstanty Jankowski (oficer): deleted from plwiki on 2026-09-06 for a copyright violation, deletion log: \"[[Wikipedia:Prawa autorskie|naruszenie praw autorskich]]\"",
267
+ "title": "Konstanty Jankowski (oficer)"
268
  }
269
  ],
270
  "counts": {
271
  "CC-BY-SA-3.0": 284075,
272
+ "CC-BY-SA-4.0": 1421853,
273
+ "copied_page": 9,
274
  "ek_copyright": 0,
275
  "exact_duplicate": 382,
276
  "extracted": 1706319
data/wikipedia/wikipedia.license-evidence.json CHANGED
@@ -1,11 +1,11 @@
1
  {
2
- "license": "CC-BY-SA-3.0 or CC-BY-SA-4.0 per record, by the page's last revision",
3
  "spdx": [
4
  "https://spdx.org/licenses/CC-BY-SA-3.0.html",
5
  "https://spdx.org/licenses/CC-BY-SA-4.0.html"
6
  ],
7
  "status": "documented-open-cc-by-sa",
8
- "review_scope": "licence of contributors' text on pl.wikipedia and its version per page; copyright pastes estimated by sample; not independent legal advice",
9
  "checked_at": "2026-10-05",
10
  "evidence_url": "https://foundation.wikimedia.org/w/index.php?title=Policy:Terms_of_Use&oldid=554823",
11
  "sha256": "c96ef93b439ff9b8242dc3233f41ede57c0984ef9153fafa51aa5f8cf0678832",
@@ -25,25 +25,19 @@
25
  "url": "https://creativecommons.org/licenses/by-sa/4.0/deed.pl"
26
  }
27
  },
28
- "licence_text": {
29
- "url": "https://creativecommons.org/licenses/by-sa/3.0/legalcode",
30
- "sha256": "3f941b3b89cf7b8370ceb83cc76d2120d471b58735d8ca60238a751a48d7f72f",
31
- "section": "4(b)",
32
- "statement": "You may Distribute or Publicly Perform an Adaptation only under the terms of: (i) this License; (ii) a later version of this License with the same License Elements as this License"
33
- },
34
  "label_rule": {
35
- "function": "src/fetch_wikipedia.py license_for_revision",
36
  "cutoff": "2023-06-07T00:00:00+00:00",
37
- "rule": "last revision before the cutoff -> CC-BY-SA-3.0; at or after -> CC-BY-SA-4.0; a timestamp without a time zone or missing stops the build",
38
- "cutoff_day": "the Terms of Use give the day, not the time; midnight UTC labels the whole of 2023-06-07 as 4.0. If the switch came later that day, pages last edited before it are 3.0 text under a 4.0 label. The rights audit (wikimedia.md L3) suggested 2023-06-08; that would label 4.0 edits of 2023-06-07 as 3.0, which 4.0 §3(b)(1) does not allow. Neither choice is exact without the time of the switch",
39
  "licence_text_4": {
40
  "url": "https://creativecommons.org/licenses/by-sa/4.0/legalcode",
41
  "sha256": "28a9529c7d0bb4dc51f4bf5c116a3d16ef247a052f7591466768ddf563fd1cf5",
42
  "section": "3(b)(1)",
43
  "statement": "The Adapter's License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License."
44
  },
45
- "pages_last_revised_on_cutoff_day": 184,
46
- "tests": "src/test_wikipedia_contract.py test_license_for_revision, test_license_for_revision_fails_without_a_zoned_timestamp, test_every_row_label_follows_its_last_revision"
47
  },
48
  "chain": [
49
  {
@@ -59,23 +53,20 @@
59
  "mark": "V"
60
  },
61
  {
62
- "hop": "page last edited on or after 2023-06-07 -> released as 4.0",
63
- "basis": "CC BY-SA 3.0 §4(b)(ii) lets an adaptation be licensed under a later version with the same License Elements",
64
- "url": "https://creativecommons.org/licenses/by-sa/3.0/legalcode",
65
- "mark": "I"
66
  }
67
  ],
68
- "attribution": "author = \"Wikipedia contributors, <page URL>\"; the page history names the contributors; Terms of Use section 7 accepts a link or URL to the page. wikipedia.attribution.jsonl: id, pageid, revid, title, url, last_revision_at, license per row",
69
  "intermediary_removed": "v0.2.0-v0.2.5 used the SpeakLeash plwiki snapshot (speakleash-ds-pub); the v0.2.6 rebuild reads the official dump directly",
70
- "finding": "Contributors' text is CC BY-SA; its version follows the page's last revision. Pages carrying the plwiki copyright-violation notice ({{NPA}}, {{Copyvio}}, {{Plagiat}}) are dropped, as are pages whose speedy-deletion notice {{ek}} gives a copyright reason (none in this dump) and the pages the copyright sample found copied (src/fetch_wikipedia.py COPIED_PAGES).",
71
  "release_scope": {
72
  "labels": {
73
- "CC-BY-SA-4.0": 1277818,
74
- "CC-BY-SA-3.0": 190836
75
- },
76
- "tokens_by_label": {
77
- "CC-BY-SA-4.0": 1145889253,
78
- "CC-BY-SA-3.0": 81022938
79
  },
80
  "pages_scanned": 2877278,
81
  "namespace_0": 2304425,
@@ -85,13 +76,18 @@
85
  "parser_failures": 0,
86
  "converted": 1706319,
87
  "exact_duplicates": 382,
88
- "copied_pages": 2,
89
  "ek_notices": 0,
90
  "ek_copyright": 0,
91
  "under_200_chars": 231717,
92
  "non_polish": 5564,
93
- "documents_released": 1468654,
94
- "last_revised_before_2009": 0
 
 
 
 
 
95
  },
96
  "copyvio_notice_recheck": {
97
  "checked_at": "2026-10-05",
@@ -135,7 +131,7 @@
135
  "copyright_sample": {
136
  "file": "wikipedia.copyvio-sample.jsonl",
137
  "checked_at": "2026-10-05",
138
- "method": "random.seed(seed); per label in sorted order, random.sample of that label's released ids in page-id order; each sampled revision (revid) run through Earwig's Copyvio Detector API (copyvios.toolforge.org, action=search, use_engine=1, use_links=1); every page whose best source reached confidence 0.10 or a 'possible'/'suspected' verdict was compared by hand (Earwig compare detail, the page history, the source's date)",
139
  "seed": 20261006,
140
  "per_stratum": {
141
  "CC-BY-SA-3.0": 40,
@@ -216,18 +212,63 @@
216
  [
217
  "wikipedia_1126780",
218
  "CC-BY-SA-4.0"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  ]
220
  ],
221
  "note": "the sample was drawn from this earlier build; test_copyright_sample_matches_the_release reproduces it from the released ids plus rows_dropped_since, each of which must be a copyright drop"
222
- }
 
223
  },
224
  "not_checked": [
225
  "pastes from copyrighted sources beyond the sample above",
226
- "the 3.0 -> 4.0 label of pages edited after the cutoff (inferred from 3.0 §4(b)(ii), not reviewed by a lawyer), and the time of day of the switch (184 pages last edited on 2023-06-07)",
 
 
227
  "text imported from elsewhere under another licence or with extra attribution requirements (Terms of Use, Re-use); template notices are removed by the conversion",
228
  "text first contributed under GFDL before the 2009 move to CC BY-SA (0 pages last edited before 2009); GFDL dual licensing; only the CC BY-SA grant is relied on",
229
  "quotations inside articles (Art. 29 of the Polish copyright act)",
230
- "deletion discussions and maintenance notices other than {{NPA}} and {{ek}}; their reasons are not read",
 
 
231
  "personal data (NERGAL scrub runs before release)"
232
- ]
 
 
 
 
 
 
 
 
 
 
 
 
233
  }
 
1
  {
2
+ "license": "CC-BY-SA-3.0, CC-BY-SA-4.0 or both per record, by contribution date",
3
  "spdx": [
4
  "https://spdx.org/licenses/CC-BY-SA-3.0.html",
5
  "https://spdx.org/licenses/CC-BY-SA-4.0.html"
6
  ],
7
  "status": "documented-open-cc-by-sa",
8
+ "review_scope": "licence of contributors' text on pl.wikipedia and its version per contribution; copyright pastes estimated by sample; not independent legal advice",
9
  "checked_at": "2026-10-05",
10
  "evidence_url": "https://foundation.wikimedia.org/w/index.php?title=Policy:Terms_of_Use&oldid=554823",
11
  "sha256": "c96ef93b439ff9b8242dc3233f41ede57c0984ef9153fafa51aa5f8cf0678832",
 
25
  "url": "https://creativecommons.org/licenses/by-sa/4.0/deed.pl"
26
  }
27
  },
 
 
 
 
 
 
28
  "label_rule": {
29
+ "function": "src/wiki_history.py compare; src/fetch_wikipedia.py relabel writes the labels",
30
  "cutoff": "2023-06-07T00:00:00+00:00",
31
+ "rule": "each contribution keeps the licence it was made under: a row whose text was all contributed before the cutoff -> CC-BY-SA-3.0; a page created at or after it -> CC-BY-SA-4.0; a row holding text from both sides, or whose pre-cutoff text cannot be compared, -> CC-BY-SA-3.0 AND CC-BY-SA-4.0. The basis is license_basis per row in wikipedia.attribution.jsonl, counted in wikipedia.build.json licence_labels",
32
+ "cutoff_day": "the Terms of Use give the day, not the time; midnight UTC counts edits made on 2023-06-07 as 4.0. If the switch came later that day, an older page that gained words before it is labelled both (3.0 is still named), and a page created before it is 3.0 text labelled 4.0 alone (pages_created_on_cutoff_day). The rights audit (wikimedia.md L3) suggested 2023-06-08; that would count 4.0 edits of 2023-06-07 as 3.0, which 4.0 §3(b)(1) does not allow. Neither choice is exact without the time of the switch",
33
  "licence_text_4": {
34
  "url": "https://creativecommons.org/licenses/by-sa/4.0/legalcode",
35
  "sha256": "28a9529c7d0bb4dc51f4bf5c116a3d16ef247a052f7591466768ddf563fd1cf5",
36
  "section": "3(b)(1)",
37
  "statement": "The Adapter's License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License."
38
  },
39
+ "pages_created_on_cutoff_day": 76,
40
+ "tests": "src/test_wikipedia_contract.py test_every_row_is_labelled_by_contribution; src/test_wiki_history.py"
41
  },
42
  "chain": [
43
  {
 
53
  "mark": "V"
54
  },
55
  {
56
+ "hop": "page history -> licence label per row",
57
+ "basis": "stub dump plwiki-20261001-stub-meta-history.xml.gz (sha1 matched to dumpstatus.json) and the text of each page's last revision before 2023-06-07 from the MediaWiki API, converted with strip_article and compared with the shipped text (src/wiki_history.py); any added word -> CC-BY-SA-3.0 AND CC-BY-SA-4.0",
58
+ "url": "https://dumps.wikimedia.org/plwiki/20261001/plwiki-20261001-stub-meta-history.xml.gz",
59
+ "mark": "V"
60
  }
61
  ],
62
+ "attribution": "author = \"Wikipedia contributors, <page URL>\"; the page history names the contributors; Terms of Use section 7 accepts a link or URL to the page. wikipedia.attribution.jsonl: id, pageid, revid, title, url, last_revision_at, license, license_basis, pre_cutoff_revid per row",
63
  "intermediary_removed": "v0.2.0-v0.2.5 used the SpeakLeash plwiki snapshot (speakleash-ds-pub); the v0.2.6 rebuild reads the official dump directly",
64
+ "finding": "Contributors' text is CC BY-SA; each contribution keeps the version it was made under, and each row is labelled 3.0, 4.0 or both by the contributions its text holds. Pages carrying the plwiki copyright-violation notice ({{NPA}}, {{Copyvio}}, {{Plagiat}}) are dropped, as are pages whose speedy-deletion notice {{ek}} gives a copyright reason (none in this dump) and the pages found to hold copied text, by the copyright sample or by a plwiki deletion for copyright after the dump (src/fetch_wikipedia.py COPIED_PAGES).",
65
  "release_scope": {
66
  "labels": {
67
+ "CC-BY-SA-3.0": 719119,
68
+ "CC-BY-SA-3.0 AND CC-BY-SA-4.0": 629454,
69
+ "CC-BY-SA-4.0": 120074
 
 
 
70
  },
71
  "pages_scanned": 2877278,
72
  "namespace_0": 2304425,
 
76
  "parser_failures": 0,
77
  "converted": 1706319,
78
  "exact_duplicates": 382,
79
+ "copied_pages": 9,
80
  "ek_notices": 0,
81
  "ek_copyright": 0,
82
  "under_200_chars": 231717,
83
  "non_polish": 5564,
84
+ "documents_released": 1468647,
85
+ "last_revised_before_2009": 0,
86
+ "tokens": {
87
+ "CC-BY-SA-3.0": 364335667,
88
+ "CC-BY-SA-3.0 AND CC-BY-SA-4.0": 765350761,
89
+ "CC-BY-SA-4.0": 97219687
90
+ }
91
  },
92
  "copyvio_notice_recheck": {
93
  "checked_at": "2026-10-05",
 
131
  "copyright_sample": {
132
  "file": "wikipedia.copyvio-sample.jsonl",
133
  "checked_at": "2026-10-05",
134
+ "method": "random.seed(seed); per stratum in sorted order, random.sample of that stratum's released ids in page-id order; each sampled revision (revid) run through Earwig's Copyvio Detector API (copyvios.toolforge.org, action=search, use_engine=1, use_links=1); every page whose best source reached confidence 0.10 or a 'possible'/'suspected' verdict was compared by hand (Earwig compare detail, the page history, the source's date)",
135
  "seed": 20261006,
136
  "per_stratum": {
137
  "CC-BY-SA-3.0": 40,
 
212
  [
213
  "wikipedia_1126780",
214
  "CC-BY-SA-4.0"
215
+ ],
216
+ [
217
+ "wikipedia_4095632",
218
+ "CC-BY-SA-4.0"
219
+ ],
220
+ [
221
+ "wikipedia_6131122",
222
+ "CC-BY-SA-4.0"
223
+ ],
224
+ [
225
+ "wikipedia_6131594",
226
+ "CC-BY-SA-4.0"
227
+ ],
228
+ [
229
+ "wikipedia_6131631",
230
+ "CC-BY-SA-4.0"
231
+ ],
232
+ [
233
+ "wikipedia_6131646",
234
+ "CC-BY-SA-4.0"
235
+ ],
236
+ [
237
+ "wikipedia_6132108",
238
+ "CC-BY-SA-4.0"
239
+ ],
240
+ [
241
+ "wikipedia_6132151",
242
+ "CC-BY-SA-4.0"
243
  ]
244
  ],
245
  "note": "the sample was drawn from this earlier build; test_copyright_sample_matches_the_release reproduces it from the released ids plus rows_dropped_since, each of which must be a copyright drop"
246
+ },
247
+ "strata_are": "the labels by last revision the release carried before the relabel by contribution (v2#110): CC-BY-SA-3.0 for a page last edited before 2023-06-07, CC-BY-SA-4.0 from that day (src/fetch_wikipedia.py license_for_revision)"
248
  },
249
  "not_checked": [
250
  "pastes from copyrighted sources beyond the sample above",
251
+ "whether a small post-cutoff edit is a contribution of its own: any added word makes the row CC-BY-SA-3.0 AND CC-BY-SA-4.0, with no threshold",
252
+ "text moved or merged from an older page into a page created after the cutoff (labelled CC-BY-SA-4.0 alone)",
253
+ "the time of day of the switch (76 pages created on 2023-06-07 labelled CC-BY-SA-4.0 alone)",
254
  "text imported from elsewhere under another licence or with extra attribution requirements (Terms of Use, Re-use); template notices are removed by the conversion",
255
  "text first contributed under GFDL before the 2009 move to CC BY-SA (0 pages last edited before 2009); GFDL dual licensing; only the CC BY-SA grant is relied on",
256
  "quotations inside articles (Art. 29 of the Polish copyright act)",
257
+ "deletion discussions and maintenance notices other than {{NPA}} and {{ek}}; their reasons are not read, except the deletion logs of pages deleted since the dump (deleted_since_dump)",
258
+ "pages deleted from plwiki after the stub dump (2026-10-01), and other pages by the authors of the 7 deleted for copyright",
259
+ "Teatr Piosenki Młyn (wikipedia_4033410), deleted for copyright on 2017-05-23 and recreated by 2017-07-14: the released text was not compared with the deleted one",
260
  "personal data (NERGAL scrub runs before release)"
261
+ ],
262
+ "deleted_since_dump": {
263
+ "checked_at": "2026-10-18",
264
+ "method": "released pages missing from the stub dump plwiki-20261001-stub-meta-history.xml.gz; the deletion log of each read from the pl.wikipedia API (list=logevents by title), classed by its latest deletion entry",
265
+ "missing_from_stub": 104,
266
+ "latest_deletion": {
267
+ "copyright violation (withheld, COPIED_PAGES)": 7,
268
+ "after a deletion discussion (Poczekalnia)": 88,
269
+ "duplicate, needless disambiguation, advertising, spam or nonsense": 7,
270
+ "for a history merge or a move, then restored": 2
271
+ },
272
+ "kept": "pages deleted for a reason other than copyright stay in the release: a quality call, not a rights one"
273
+ }
274
  }
data/wikipedia/wikipedia.md CHANGED
@@ -6,7 +6,7 @@ Polish Wikipedia
6
  - **Source (upstream):** https://dumps.wikimedia.org/plwiki/20260901/
7
  - **Domain:** encyclopedic
8
  - **Language:** Polish (pl)
9
- - **License:** `CC-BY-SA-3.0` or `CC-BY-SA-4.0` per record (by last-revision date)
10
  - **Created (range):** 2010-11-12, 2026-09-01 (date of the page's last revision in the dump)
11
  - **Added:** 2026-06-15; rebuilt 2026-10-05 (UTC) from the official Wikimedia dump
12
 
@@ -14,25 +14,45 @@ Polish Wikipedia
14
  Wikipedia contributors license their text under CC BY-SA 4.0 under the Wikimedia
15
  [Terms of Use](https://foundation.wikimedia.org/w/index.php?title=Policy:Terms_of_Use&oldid=554823) in effect since 7 June 2023, and under CC BY-SA 3.0 under the
16
  [2014-2023 Terms of Use](https://foundation.wikimedia.org/w/index.php?title=Policy:Terms_of_Use&oldid=98524) (both read 2026-10-05 UTC). The pl.wikipedia site licence
17
- (`rightsinfo`) links BY-SA 4.0. Each row is labelled by its page's last revision in the
18
- dump:
19
-
20
- | last revision (UTC) | `license` | documents | tokens | share of tokens |
21
- |---|---|---:|---:|---:|
22
- | before 2023-06-07 | `CC-BY-SA-3.0` | 190,836 | 81,022,938 | 6.6% |
23
- | 2023-06-07 or later | `CC-BY-SA-4.0` | 1,277,818 | 1,145,889,253 | 93.4% |
24
-
25
- A page last edited on or after the cutoff can still hold 3.0 text from earlier edits;
26
- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/legalcode) §4(b)(ii) lets such an adaptation be licensed under "a later
27
- version of this License with the same License Elements", so it is labelled 4.0. The Terms
28
- of Use give the day of the switch, not the time. The cutoff is midnight UTC, so the
29
- 184 pages last edited on 2023-06-07 itself are labelled 4.0. If the switch came later
30
- that day, those last edited before it are 3.0 text under a 4.0 label; a 2023-06-08 cutoff
31
- (the rights audit's suggestion) would instead put that day's 4.0 edits under a 3.0 label,
32
- which [4.0](https://creativecommons.org/licenses/by-sa/4.0/legalcode) §3(b)(1) ("this version or later") does not allow. Neither choice is
33
- exact without the time of the switch. The rule is `license_for_revision` in `src/fetch_wikipedia.py`,
34
- tested at the cutoff second, across time zones, and on a missing timestamp, which stops the
35
- build. v0.2.0-v0.2.5 labelled every row `CC-BY-SA-3.0`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  Text pasted into an article from a copyrighted source is under neither licence. The
38
  fetcher drops the 35 pages that carry plwiki's copyright-violation
@@ -47,9 +67,10 @@ template's codes `npa`, `plagiat`, `copypaste`, `kopiuj-wklej`, or free text wit
47
  scan found 3 inside HTML comments, which MediaWiki does not show and the build does not
48
  count. A paste without either notice cannot be detected by the build.
49
 
50
- To measure undetected pastes, 40 released pages per label (seed
51
  20261006, page-id order) were run through Earwig's Copyvio Detector (web search and
52
- the page's external links) on 2026-10-05. Every page whose best match reached
 
53
  confidence 0.10 or a "possible"/"suspected" verdict was compared by hand
54
  with the page history and the date of the matching text (see `wikipedia.copyvio-sample.jsonl`):
55
 
@@ -66,11 +87,19 @@ why each is classed so). Both are dropped from this release: `COPIED_PAGES` in
66
  `src/fetch_wikipedia.py` lists them by page id with the reason, and the build stops if one is
67
  not found. The sample was drawn before that drop, from the 1,468,656 documents of Hub PR 68
68
  commit 3393e05; the test reproduces the draw from the release plus the dropped rows. The share of such pages is below 12.9% (`CC-BY-SA-3.0`) and
69
- 12.9% (`CC-BY-SA-4.0`), 95% Wilson upper bounds; the labels hold
70
  6.6% and 93.4% of the tokens. The bounds cover only
71
  what the detector can find: print sources, translations and paraphrase scoring below the
72
  hand-check threshold cannot match.
73
 
 
 
 
 
 
 
 
 
74
  Evidence: `wikipedia.license-evidence.json`.
75
 
76
  ## Attribution
@@ -78,7 +107,9 @@ Each row's `author` is `Wikipedia contributors, <page URL>`, e.g.
78
  `Wikipedia contributors, https://pl.wikipedia.org/wiki/Warszawa`. The page history names the contributors; the Terms of Use
79
  (section 7) accept a link or URL to the page as attribution.
80
  `wikipedia.attribution.jsonl` has one line per row: `id`, `pageid`, `revid` (the revision
81
- in the dump), `title`, `url`, `last_revision_at`, `license`. The row `id` is
 
 
82
  `wikipedia_<page id>` and `created` is the date of `last_revision_at`.
83
 
84
  The text is modified: wiki markup is converted to plain text (see Provenance).
@@ -102,19 +133,23 @@ pages with the same text (sha1 of the stripped text), the lower page id is kept.
102
  2,877,278 pages scanned → 2,304,425 in namespace 0 → 598,071 redirects,
103
  0 empty pages and 35 with a copyright-violation notice skipped
104
  (0 parser failures) → 1,706,319 converted →
105
- 382 exact duplicates, 2 copied pages (`COPIED_PAGES`) and 0 copyright `{{ek}}`
106
- pages dropped → 1,705,935 read by the build →
107
- 1,468,654 released.
 
108
 
109
  Not cleaned: appendix headings ("Zobacz też", "Uwagi", "Przypisy", "Bibliografia", "Linki
110
- zewnętrzne") stay in 828,388 documents (56.405%), with what is left of those sections
111
  after the conversion (2.96% of all characters from the first such heading to the end);
112
- 174,668 documents (11.893%) have whitespace-only lines.
 
 
 
113
 
114
  ## Statistics
115
  | documents | characters | tokens (tiktoken proxy) |
116
  |---:|---:|---:|
117
- | 1,468,654 | 3,140,838,409 | 1,226,912,191 |
118
 
119
  v0.2.5 (SpeakLeash snapshot) had 1,171,897 documents, 1,844,707,761 characters and
120
  707,194,207 tokens. The SpeakLeash extraction is not documented. Its text drops the
@@ -125,30 +160,38 @@ in v0.2.5 and 59,133 here.
125
  ## Per-document license metadata
126
  | license | documents |
127
  |---|---:|
128
- | `CC-BY-SA-3.0` | 190,836 |
129
- | `CC-BY-SA-4.0` | 1,277,818 |
 
130
 
131
- Author metadata present for **1,468,654** documents.
132
 
133
  ## Filters applied (build_dynaword.py)
134
  - drop documents < 200 chars: **231,717**
135
  - drop non-Polish (diacritic ratio): **5,564**
136
  - exact cross-source dedup (sha1): **0** (the fetcher already dropped 382)
137
  - OCR alpha-ratio < 0.70 (OCR sources only): **0**
138
- - read 1,705,935 → kept 1,468,654
139
 
140
  Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
141
  Llama-3 count is computed at release.
142
 
143
  ## Not checked
144
  - pastes from copyrighted sources beyond the sample above
145
- - the 3.0 → 4.0 label of pages edited after the cutoff (a reading of 3.0 §4(b)(ii), not a
146
- lawyer's opinion), and the time of day of the switch (184 pages last edited on 2023-06-07)
 
 
147
  - text imported from elsewhere under another licence or with extra attribution
148
  requirements (Terms of Use, Re-use); notices kept in templates are removed by the conversion
149
  - text first contributed under GFDL before the 2009 move to CC BY-SA, and GFDL dual
150
  licensing; only the CC BY-SA grant is relied on
151
  - quotations inside articles (Art. 29 of the Polish copyright act)
152
  - deletion discussions and maintenance notices other than `{{NPA}}` and `{{ek}}`; their
153
- reasons are not read
 
 
 
 
 
154
  - personal data (the NERGAL scrub runs before release)
 
6
  - **Source (upstream):** https://dumps.wikimedia.org/plwiki/20260901/
7
  - **Domain:** encyclopedic
8
  - **Language:** Polish (pl)
9
+ - **License:** `CC-BY-SA-3.0`, `CC-BY-SA-4.0` or both per record (by contribution date)
10
  - **Created (range):** 2010-11-12, 2026-09-01 (date of the page's last revision in the dump)
11
  - **Added:** 2026-06-15; rebuilt 2026-10-05 (UTC) from the official Wikimedia dump
12
 
 
14
  Wikipedia contributors license their text under CC BY-SA 4.0 under the Wikimedia
15
  [Terms of Use](https://foundation.wikimedia.org/w/index.php?title=Policy:Terms_of_Use&oldid=554823) in effect since 7 June 2023, and under CC BY-SA 3.0 under the
16
  [2014-2023 Terms of Use](https://foundation.wikimedia.org/w/index.php?title=Policy:Terms_of_Use&oldid=98524) (both read 2026-10-05 UTC). The pl.wikipedia site licence
17
+ (`rightsinfo`) links BY-SA 4.0.
18
+ Each contribution keeps the licence it was made under: `CC-BY-SA-3.0` before 2023-06-07, `CC-BY-SA-4.0` from that day.
19
+ Each row is labelled by the contributions its text holds:
20
+
21
+ | `license` | documents | tokens | share of tokens |
22
+ |---|---:|---:|---:|
23
+ | `CC-BY-SA-3.0` | 719,119 | 364,335,667 | 29.7% |
24
+ | `CC-BY-SA-3.0 AND CC-BY-SA-4.0` | 629,454 | 765,350,761 | 62.4% |
25
+ | `CC-BY-SA-4.0` | 120,074 | 97,219,687 | 7.9% |
26
+
27
+ A row labelled `CC-BY-SA-3.0 AND CC-BY-SA-4.0` holds text under each licence. It is not split by contribution;
28
+ its page history tells the two apart. The basis of each label is the sidecar's `license_basis`:
29
+
30
+ | `license_basis` | `license` | documents | rule |
31
+ |---|---|---:|---|
32
+ | `shipped_before_cutoff` | `CC-BY-SA-3.0` | 190,836 | the shipped revision predates the cutoff |
33
+ | `same_revision_text` | `CC-BY-SA-3.0` | 5,028 | the shipped revision has the sha1 of the last pre-cutoff one in the stub dump (e.g. a revert) |
34
+ | `identical_text` | `CC-BY-SA-3.0` | 492,757 | the last pre-cutoff revision converts to the shipped text, whitespace aside |
35
+ | `no_text_added` | `CC-BY-SA-3.0` | 30,498 | later edits only removed words: the shipped words are a subsequence of the pre-cutoff ones |
36
+ | `created_after_cutoff` | `CC-BY-SA-4.0` | 120,074 | the page has no revision before the cutoff |
37
+ | `changed_after_cutoff` | `CC-BY-SA-3.0 AND CC-BY-SA-4.0` | 629,338 | later edits added at least one word |
38
+ | `page_not_in_dump` | `CC-BY-SA-3.0 AND CC-BY-SA-4.0` | 85 | the page is not in the stub dump (deleted since), so its history is not known |
39
+ | `pre_text_hidden` | `CC-BY-SA-3.0 AND CC-BY-SA-4.0` | 31 | the API returns no text for the last pre-cutoff revision (hidden or missing) |
40
+ | `pre_text_unparseable` | `CC-BY-SA-3.0 AND CC-BY-SA-4.0` | 0 | the last pre-cutoff revision does not convert |
41
+
42
+ The page histories come from the stub dump `plwiki-20261001-stub-meta-history.xml.gz` (7,039,541,375 bytes, sha1 `47fd7549026521bd02c174ee418c63a93f7e4118`,
43
+ matched against its `dumpstatus.json`; revision metadata, no text). For each row shipped from a revision made on or
44
+ after 2023-06-07, the text of the page's last revision before that day (`pre_cutoff_revid`) was fetched from the
45
+ MediaWiki API, converted with the same `strip_article` as the release and compared with the shipped text, whitespace
46
+ folded. Where they differ, a word diff (Python `difflib`) counts the words the later edits added; any added
47
+ word, however few, makes the row `CC-BY-SA-3.0 AND CC-BY-SA-4.0`. Text moved into a page created after the cutoff from an
48
+ older page is not traced, so that page is `CC-BY-SA-4.0` alone. `src/wiki_history.py` (`download`, `scan`, `fetch`,
49
+ `compare`) does this; `src/fetch_wikipedia.py relabel` writes the labels.
50
+
51
+ The Terms of Use give the day of the switch, not the time. The cutoff is midnight UTC, so revisions made on
52
+ 2023-06-07 itself count as `CC-BY-SA-4.0`. Pages labelled `CC-BY-SA-4.0` alone and created that day: 76.
53
+ If the switch came later that day, their first edits may be 3.0 text under a 4.0 label.
54
+ v0.2.0-v0.2.5 labelled every row `CC-BY-SA-3.0`; before this relabel, main labelled each row by its page's last
55
+ revision alone (`CC-BY-SA-4.0` from 2023-06-07).
56
 
57
  Text pasted into an article from a copyrighted source is under neither licence. The
58
  fetcher drops the 35 pages that carry plwiki's copyright-violation
 
67
  scan found 3 inside HTML comments, which MediaWiki does not show and the build does not
68
  count. A paste without either notice cannot be detected by the build.
69
 
70
+ To measure undetected pastes, 40 released pages per stratum (seed
71
  20261006, page-id order) were run through Earwig's Copyvio Detector (web search and
72
+ the page's external links) on 2026-10-05. The strata are the labels by last revision the release
73
+ carried then: `CC-BY-SA-3.0` for a page last edited before 2023-06-07, `CC-BY-SA-4.0` from that day. Every page whose best match reached
74
  confidence 0.10 or a "possible"/"suspected" verdict was compared by hand
75
  with the page history and the date of the matching text (see `wikipedia.copyvio-sample.jsonl`):
76
 
 
87
  `src/fetch_wikipedia.py` lists them by page id with the reason, and the build stops if one is
88
  not found. The sample was drawn before that drop, from the 1,468,656 documents of Hub PR 68
89
  commit 3393e05; the test reproduces the draw from the release plus the dropped rows. The share of such pages is below 12.9% (`CC-BY-SA-3.0`) and
90
+ 12.9% (`CC-BY-SA-4.0`), 95% Wilson upper bounds; the strata hold
91
  6.6% and 93.4% of the tokens. The bounds cover only
92
  what the detector can find: print sources, translations and paraphrase scoring below the
93
  hand-check threshold cannot match.
94
 
95
+ Pages deleted from plwiki for a copyright violation after the dump are dropped too. Of the released
96
+ pages, 104 are missing from the stub dump `plwiki-20261001-stub-meta-history.xml.gz`; their deletion logs, read
97
+ on 2026-10-18, give a copyright violation as the reason for 7. `COPIED_PAGES` lists them with the log's
98
+ reason, and `fetch_wikipedia.py withhold` dropped them from this release as a rebuild would, adding them
99
+ to the sample's dropped rows. Of the other 97, 88 were deleted after a deletion discussion,
100
+ 7 as duplicates, needless disambiguations, advertising, spam or nonsense, and 2 were deleted
101
+ for a history merge or a move and restored. They are kept: a quality call, not a rights one.
102
+
103
  Evidence: `wikipedia.license-evidence.json`.
104
 
105
  ## Attribution
 
107
  `Wikipedia contributors, https://pl.wikipedia.org/wiki/Warszawa`. The page history names the contributors; the Terms of Use
108
  (section 7) accept a link or URL to the page as attribution.
109
  `wikipedia.attribution.jsonl` has one line per row: `id`, `pageid`, `revid` (the revision
110
+ in the dump), `title`, `url`, `last_revision_at`, `license`,
111
+ `license_basis` (how the label was decided, see Licensing) and `pre_cutoff_revid` (the page's last revision
112
+ before the cutoff, null for a page created after it or edited after it and since deleted; its text is at `https://pl.wikipedia.org/w/index.php?oldid=<pre_cutoff_revid>`). The row `id` is
113
  `wikipedia_<page id>` and `created` is the date of `last_revision_at`.
114
 
115
  The text is modified: wiki markup is converted to plain text (see Provenance).
 
133
  2,877,278 pages scanned → 2,304,425 in namespace 0 → 598,071 redirects,
134
  0 empty pages and 35 with a copyright-violation notice skipped
135
  (0 parser failures) → 1,706,319 converted →
136
+ 382 exact duplicates, 9 copied pages (`COPIED_PAGES`: 2 found by the copyright sample,
137
+ 7 deleted from plwiki for a copyright violation after the dump) and 0 copyright `{{ek}}`
138
+ pages dropped → 1,705,928 read by the build →
139
+ 1,468,647 released.
140
 
141
  Not cleaned: appendix headings ("Zobacz też", "Uwagi", "Przypisy", "Bibliografia", "Linki
142
+ zewnętrzne") stay in 828,386 documents (56.405%), with what is left of those sections
143
  after the conversion (2.96% of all characters from the first such heading to the end);
144
+ 174,668 documents (11.893%) have whitespace-only lines. Malformed links leave markup: 14
145
+ documents hold a category link on a line of its own (`wikipedia_103834`), 13 an unclosed file
146
+ link (`[[Plik:...|thumb|...`, `wikipedia_13010`); 363 contain `<ref`. Other lines starting
147
+ `Kategoria:` are content, mostly flattened medal tables (`Kategoria:Złoto:Srebro:Brąz:...`).
148
 
149
  ## Statistics
150
  | documents | characters | tokens (tiktoken proxy) |
151
  |---:|---:|---:|
152
+ | 1,468,647 | 3,140,823,417 | 1,226,906,115 |
153
 
154
  v0.2.5 (SpeakLeash snapshot) had 1,171,897 documents, 1,844,707,761 characters and
155
  707,194,207 tokens. The SpeakLeash extraction is not documented. Its text drops the
 
160
  ## Per-document license metadata
161
  | license | documents |
162
  |---|---:|
163
+ | `CC-BY-SA-3.0` | 719,119 |
164
+ | `CC-BY-SA-3.0 AND CC-BY-SA-4.0` | 629,454 |
165
+ | `CC-BY-SA-4.0` | 120,074 |
166
 
167
+ Author metadata present for **1,468,647** documents.
168
 
169
  ## Filters applied (build_dynaword.py)
170
  - drop documents < 200 chars: **231,717**
171
  - drop non-Polish (diacritic ratio): **5,564**
172
  - exact cross-source dedup (sha1): **0** (the fetcher already dropped 382)
173
  - OCR alpha-ratio < 0.70 (OCR sources only): **0**
174
+ - read 1,705,928 → kept 1,468,647
175
 
176
  Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
177
  Llama-3 count is computed at release.
178
 
179
  ## Not checked
180
  - pastes from copyrighted sources beyond the sample above
181
+ - whether a small post-cutoff edit is a contribution of its own: any added word makes the row
182
+ `CC-BY-SA-3.0 AND CC-BY-SA-4.0`, with no threshold
183
+ - text moved or merged from an older page into a page created after the cutoff (labelled `CC-BY-SA-4.0` alone)
184
+ - the time of day of the switch (see Licensing)
185
  - text imported from elsewhere under another licence or with extra attribution
186
  requirements (Terms of Use, Re-use); notices kept in templates are removed by the conversion
187
  - text first contributed under GFDL before the 2009 move to CC BY-SA, and GFDL dual
188
  licensing; only the CC BY-SA grant is relied on
189
  - quotations inside articles (Art. 29 of the Polish copyright act)
190
  - deletion discussions and maintenance notices other than `{{NPA}}` and `{{ek}}`; their
191
+ reasons are not read, except the deletion logs above
192
+ - pages deleted from plwiki after the stub dump (2026-10-01), and other pages by the authors
193
+ of the 7 deleted for copyright
194
+ - "Teatr Piosenki Młyn" (`wikipedia_4033410`), deleted for copyright on 2017-05-23 and recreated
195
+ by 2017-07-14: the released text was not compared with the deleted one (it is among the
196
+ 88 deleted after a discussion in 2026)
197
  - personal data (the NERGAL scrub runs before release)
data/wikipedia/wikipedia.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f4abfff711b207691d1278efc28d8af18551454143f3d8f2292ec3ddcefc314a
3
- size 1462846393
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6fec912de221285b1d3de1e813b66aca9ebfb62782e64a73bf48783e8a013fa9
3
+ size 1462886095
data/wikipedia/wikipedia.stats.json CHANGED
@@ -1,17 +1,18 @@
1
  {
2
- "read": 1705935,
3
- "kept": 1468654,
4
  "drop_short": 231717,
5
  "drop_lang": 5564,
6
  "drop_dup": 0,
7
  "drop_ocr": 0,
8
- "chars": 3140838409,
9
- "tokens": 1226912191,
10
  "licenses": {
11
- "CC-BY-SA-4.0": 1277818,
12
- "CC-BY-SA-3.0": 190836
 
13
  },
14
- "authors_with_value": 1468654,
15
  "secs": 34.6,
16
- "license": "CC BY-SA (3.0 or 4.0 per record, by last-revision date)"
17
  }
 
1
  {
2
+ "read": 1705928,
3
+ "kept": 1468647,
4
  "drop_short": 231717,
5
  "drop_lang": 5564,
6
  "drop_dup": 0,
7
  "drop_ocr": 0,
8
+ "chars": 3140823417,
9
+ "tokens": 1226906115,
10
  "licenses": {
11
+ "CC-BY-SA-3.0": 719119,
12
+ "CC-BY-SA-3.0 AND CC-BY-SA-4.0": 629454,
13
+ "CC-BY-SA-4.0": 120074
14
  },
15
+ "authors_with_value": 1468647,
16
  "secs": 34.6,
17
+ "license": "CC BY-SA (3.0, 4.0 or both per record, by contribution date)"
18
  }
src/fetch_wikimedia.py CHANGED
@@ -453,9 +453,23 @@ def relabel(out: Path, data_dir: Path, key: str) -> None:
453
  `license` column, the sidecar (wiki_history.apply_labels), stats `licenses` and `license`,
454
  build.json (`attribution_sha256`, `licence_labels`) and the licence evidence's labels and tokens.
455
  Text, ids and every other column are unchanged; rerunning changes nothing."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
  import pyarrow.parquet as pq
457
  from wiki_history import STUB_DATE, apply_labels
458
- site = SITES[key]
459
 
460
  def path(name):
461
  return data_dir / f"{key}.{name}"
@@ -470,21 +484,16 @@ def relabel(out: Path, data_dir: Path, key: str) -> None:
470
  stats = load(path("stats.json"))
471
  stats.update(licenses=docs, license=SOURCES[key]["license"])
472
  path("stats.json").write_text(json.dumps(stats, indent=2)) # build_dynaword's format
473
- day = site["cutoff"].date().isoformat()
474
  build = load(path("build.json"))
475
  build["attribution_sha256"] = digest(path("attribution.jsonl").read_bytes())
476
  build["licence_labels"] = {
477
- "stub": load(out / f"{site['wiki']}-{STUB_DATE}-stub-meta-history.xml.gz.json"),
478
  "cases": dict(Counter(lab["case"] for lab in labels)),
479
  "created_on_cutoff_day": sum(lab["case"] == "created_after_cutoff" and lab["first_at"].startswith(day) for lab in labels),
480
  }
481
  save(path("build.json"), build)
482
- ev = load(path("license-evidence.json"))
483
- ev["license"] = f"{site['before']}, {site['after']} or both per record, by contribution date"
484
- ev["review_scope"] = f"licence of contributors' text on {site['host']} and its version per contribution; not independent legal advice"
485
- ev["release_scope"].update(labels=docs, tokens=tokens)
486
- save(path("license-evidence.json"), ev)
487
- print(f"{key}: relabelled, {docs}")
488
 
489
 
490
  def share(part: int, whole: int) -> str:
@@ -528,12 +537,14 @@ def licensing_text(key: str, ev: dict) -> str:
528
 
529
 
530
  def contribution_text(key: str, build: dict, ev: dict, tok: int) -> str:
531
- """The labels of a release relabelled by contribution, and how they were decided."""
532
- from wiki_history import CASES
533
- site, lab, scope, stub = SITES[key], build["licence_labels"], ev["release_scope"], build["licence_labels"]["stub"]
534
- if "SA" not in site["after"]: # wikinews: 2.5 and the known switch time need their own text (v2#110)
 
535
  raise NotImplementedError(f"{key}: no card text for contribution labels yet")
536
- before, after, day = site["before"], site["after"], site["cutoff"].date().isoformat()
 
537
  licence = {"before": before, "after": after, "mixed": f"{before} AND {after}"}
538
  labels = "\n".join(f"| `{lic}` | {scope['labels'].get(lic, 0):,} | {scope['tokens'].get(lic, 0):,} | {share(scope['tokens'].get(lic, 0), tok)} |"
539
  for lic in (before, licence["mixed"], after))
@@ -555,11 +566,11 @@ its page history tells the two apart. The basis of each label is the sidecar's `
555
  The page histories come from the stub dump `{stub['name']}` ({stub['size']:,} bytes, sha1 `{stub['sha1']}`,
556
  matched against its `dumpstatus.json`; revision metadata, no text). For each row shipped from a revision made on or
557
  after {day}, the text of the page's last revision before that day (`pre_cutoff_revid`) was fetched from the
558
- MediaWiki API, converted with the same `strip` as the release and compared with the shipped text, whitespace
559
  folded. Where they differ, a word diff (Python `difflib`) counts the words the later edits added; any added
560
  word, however few, makes the row `{licence['mixed']}`. Text moved into a page created after the cutoff from an
561
  older page is not traced, so that page is `{after}` alone. `src/wiki_history.py` (`download`, `scan`, `fetch`,
562
- `compare`) does this; `src/fetch_wikimedia.py relabel` writes the labels.
563
 
564
  The Terms of Use give the day of the switch, not the time. The cutoff is midnight UTC, so revisions made on
565
  {day} itself count as `{after}`. Pages labelled `{after}` alone and created that day: {lab['created_on_cutoff_day']}.
 
453
  `license` column, the sidecar (wiki_history.apply_labels), stats `licenses` and `license`,
454
  build.json (`attribution_sha256`, `licence_labels`) and the licence evidence's labels and tokens.
455
  Text, ids and every other column are unchanged; rerunning changes nothing."""
456
+ site = SITES[key]
457
+ docs, tokens = write_labels(out, data_dir, key, site["wiki"], site["cutoff"])
458
+ path = data_dir / f"{key}.license-evidence.json"
459
+ ev = load(path)
460
+ ev["license"] = f"{site['before']}, {site['after']} or both per record, by contribution date"
461
+ ev["review_scope"] = f"licence of contributors' text on {site['host']} and its version per contribution; not independent legal advice"
462
+ ev["release_scope"].update(labels=docs, tokens=tokens)
463
+ save(path, ev)
464
+ print(f"{key}: relabelled, {docs}")
465
+
466
+
467
+ def write_labels(out: Path, data_dir: Path, key: str, wiki: str, cutoff) -> tuple[dict, dict]:
468
+ """relabel's rewrite of the parquet, sidecar, stats and build record, shared with
469
+ fetch_wikipedia.py relabel; `wiki` names the stub dump, `cutoff` is the licence switch.
470
+ Returns (documents, tokens) per label."""
471
  import pyarrow.parquet as pq
472
  from wiki_history import STUB_DATE, apply_labels
 
473
 
474
  def path(name):
475
  return data_dir / f"{key}.{name}"
 
484
  stats = load(path("stats.json"))
485
  stats.update(licenses=docs, license=SOURCES[key]["license"])
486
  path("stats.json").write_text(json.dumps(stats, indent=2)) # build_dynaword's format
487
+ day = cutoff.date().isoformat()
488
  build = load(path("build.json"))
489
  build["attribution_sha256"] = digest(path("attribution.jsonl").read_bytes())
490
  build["licence_labels"] = {
491
+ "stub": load(out / f"{wiki}-{STUB_DATE}-stub-meta-history.xml.gz.json"),
492
  "cases": dict(Counter(lab["case"] for lab in labels)),
493
  "created_on_cutoff_day": sum(lab["case"] == "created_after_cutoff" and lab["first_at"].startswith(day) for lab in labels),
494
  }
495
  save(path("build.json"), build)
496
+ return docs, tokens
 
 
 
 
 
497
 
498
 
499
  def share(part: int, whole: int) -> str:
 
537
 
538
 
539
  def contribution_text(key: str, build: dict, ev: dict, tok: int) -> str:
540
+ """The labels of a release relabelled by contribution, and how they were decided (also in
541
+ data/wikipedia/wikipedia.md, which is written by hand)."""
542
+ from wiki_history import CASES, CONVERTERS, WIKIS
543
+ cfg, lab, scope, stub = WIKIS[key], build["licence_labels"], ev["release_scope"], build["licence_labels"]["stub"]
544
+ if "SA" not in cfg["after"]: # wikinews: 2.5 and the known switch time need their own text (v2#110)
545
  raise NotImplementedError(f"{key}: no card text for contribution labels yet")
546
+ before, after, day = cfg["before"], cfg["after"], cfg["cutoff"][:10]
547
+ module, convert = CONVERTERS[key]
548
  licence = {"before": before, "after": after, "mixed": f"{before} AND {after}"}
549
  labels = "\n".join(f"| `{lic}` | {scope['labels'].get(lic, 0):,} | {scope['tokens'].get(lic, 0):,} | {share(scope['tokens'].get(lic, 0), tok)} |"
550
  for lic in (before, licence["mixed"], after))
 
566
  The page histories come from the stub dump `{stub['name']}` ({stub['size']:,} bytes, sha1 `{stub['sha1']}`,
567
  matched against its `dumpstatus.json`; revision metadata, no text). For each row shipped from a revision made on or
568
  after {day}, the text of the page's last revision before that day (`pre_cutoff_revid`) was fetched from the
569
+ MediaWiki API, converted with the same `{convert}` as the release and compared with the shipped text, whitespace
570
  folded. Where they differ, a word diff (Python `difflib`) counts the words the later edits added; any added
571
  word, however few, makes the row `{licence['mixed']}`. Text moved into a page created after the cutoff from an
572
  older page is not traced, so that page is `{after}` alone. `src/wiki_history.py` (`download`, `scan`, `fetch`,
573
+ `compare`) does this; `src/{module}.py relabel` writes the labels.
574
 
575
  The Terms of Use give the day of the switch, not the time. The cutoff is midnight UTC, so revisions made on
576
  {day} itself count as `{after}`. Pages labelled `{after}` alone and created that day: {lab['created_on_cutoff_day']}.
src/fetch_wikipedia.py CHANGED
@@ -13,6 +13,18 @@ checked against the sha1 in dumpstatus.json and in the dump's sha1sums.txt.
13
  # COPIED_PAGES, copyright {{ek}} pages
14
  python3 src/build_dynaword.py --sources wikipedia --speakleash-dir $B --out .
15
  python3 src/fetch_wikipedia.py attribution --out $B # data/wikipedia sidecars
 
 
 
 
 
 
 
 
 
 
 
 
16
  """
17
  from __future__ import annotations
18
 
@@ -59,15 +71,33 @@ EK_RE = re.compile(r"\{\{\s*(?:(?i:szablon|template)\s*:\s*)?"
59
  EK_NAMES = {"Ek", "EK", "Ekspresowe kasowanko", "Usuń", "Speedy", "Delete"}
60
  # The build records every template redirect to these, so the alias lists above can be checked against the dump.
61
  TAG_TEMPLATES = {"Szablon:NPA", "Szablon:Ek"}
62
- # Pages the copyright sample (data/wikipedia/wikipedia.copyvio-sample.jsonl) found to hold text
63
- # copied or closely paraphrased from a copyrighted source. Keyed on the wiki page id, which is
64
- # stable across dumps (the dataset id is derived from it). prepare fails if one is not reached.
 
 
 
 
 
 
 
 
 
65
  COPIED_PAGES = {
66
  833396: "Obnażyć prawdę: the 'Opis fabuły' paragraph closely paraphrases Filmweb's production "
67
  "description of the film; added in revision 15302011 (2008-12-26), which cites Filmweb",
68
  1126780: "Czarnka: the lake paragraph (revision 42979631, 2015-06-19) closely paraphrases the "
69
  "Drawieński Park Narodowy page dpn.pl/czarne, archived 2012-01-25; whether Art. 4 of the "
70
  "Polish copyright act (official materials) applies was not assessed",
 
 
 
 
 
 
 
 
 
71
  }
72
  # {{ek}} reasons that state a copyright violation: the template's own codes that render as
73
  # "naruszenie praw autorskich" (npa, plagiat, copypaste, kopiuj-wklej) and free text naming one
@@ -352,9 +382,80 @@ def attribution(out: Path, data_dir: Path) -> None:
352
  print(f"attribution rows: {n}")
353
 
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  def main() -> None:
356
  ap = argparse.ArgumentParser()
357
- ap.add_argument("step", choices=["discover", "acquire", "extract", "prepare", "attribution"])
358
  ap.add_argument("--out", required=True, type=Path)
359
  ap.add_argument("--data-dir", type=Path, default=Path(__file__).resolve().parent.parent / "data" / SOURCE)
360
  ap.add_argument("--workers", type=int, default=8)
@@ -362,7 +463,8 @@ def main() -> None:
362
  a.out.mkdir(parents=True, exist_ok=True)
363
  {"discover": lambda: discover(a.out), "acquire": lambda: acquire(a.out),
364
  "extract": lambda: extract(a.out, a.workers), "prepare": lambda: prepare(a.out),
365
- "attribution": lambda: attribution(a.out, a.data_dir)}[a.step]()
 
366
 
367
 
368
  if __name__ == "__main__":
 
13
  # COPIED_PAGES, copyright {{ek}} pages
14
  python3 src/build_dynaword.py --sources wikipedia --speakleash-dir $B --out .
15
  python3 src/fetch_wikipedia.py attribution --out $B # data/wikipedia sidecars
16
+ python3 src/fetch_wikipedia.py withhold --out $B # drops pages added to COPIED_PAGES since
17
+
18
+ Labels by contribution (slayerlabs/polish-dynaword-v2#110, option B) replace the last-revision
19
+ labels on the committed release; the pages-articles dump is not re-read. H=<history dir, never committed>
20
+ python3 src/wiki_history.py download --dump plwiki --out $H
21
+ python3 src/wiki_history.py scan --stub $H/plwiki-20261001-stub-meta-history.xml.gz \\
22
+ --sidecar wikipedia=data/wikipedia/wikipedia.attribution.jsonl --out $H
23
+ python3 src/wiki_history.py fetch --source wikipedia --history $H/wikipedia.history.jsonl --out $H
24
+ python3 src/wiki_history.py compare --source wikipedia --sidecar data/wikipedia/wikipedia.attribution.jsonl \\
25
+ --history $H/wikipedia.history.jsonl --fetched $H/wikipedia --parquet data/wikipedia/wikipedia.parquet \\
26
+ --out $H/wikipedia.labels.jsonl
27
+ python3 src/fetch_wikipedia.py relabel --out $H # data/wikipedia; the card is edited by hand
28
  """
29
  from __future__ import annotations
30
 
 
71
  EK_NAMES = {"Ek", "EK", "Ekspresowe kasowanko", "Usuń", "Speedy", "Delete"}
72
  # The build records every template redirect to these, so the alias lists above can be checked against the dump.
73
  TAG_TEMPLATES = {"Szablon:NPA", "Szablon:Ek"}
74
+
75
+
76
+ def _deleted(day: str, reason: str = "[[Wikipedia:Prawa autorskie|naruszenie praw autorskich]]") -> str:
77
+ """A COPIED_PAGES reason for a page deleted from plwiki for copyright: the day and the log's reason."""
78
+ return f'deleted from plwiki on {day} for a copyright violation, deletion log: "{reason}"'
79
+
80
+
81
+ # Pages that hold text copied or closely paraphrased from a copyrighted source: found by the
82
+ # copyright sample (data/wikipedia/wikipedia.copyvio-sample.jsonl), or deleted from plwiki for a
83
+ # copyright violation after the dump (Special:Log/delete). Keyed on the wiki page id, which is
84
+ # stable across dumps (the dataset id is derived from it). prepare fails if one is not reached;
85
+ # `withhold` drops one added after the build from the committed release.
86
  COPIED_PAGES = {
87
  833396: "Obnażyć prawdę: the 'Opis fabuły' paragraph closely paraphrases Filmweb's production "
88
  "description of the film; added in revision 15302011 (2008-12-26), which cites Filmweb",
89
  1126780: "Czarnka: the lake paragraph (revision 42979631, 2015-06-19) closely paraphrases the "
90
  "Drawieński Park Narodowy page dpn.pl/czarne, archived 2012-01-25; whether Art. 4 of the "
91
  "Polish copyright act (official materials) applies was not assessed",
92
+ 4095632: "Brzezina (opowiadanie): " + _deleted("2026-09-01", ( # the link's tracking query left out
93
+ "Naruszenie praw autorskich: https://www.studocu.com/pl/document/uniwersytet-jagiellonski/"
94
+ "filologia-polska/proza-poetycka-i-awangardowa-iwaszkiewicz-jasienski-choromanski/74568413")),
95
+ 6131122: "Edmund Bielecki: " + _deleted("2026-09-05"),
96
+ 6131594: "Ryszard Cyffer: " + _deleted("2026-09-05"),
97
+ 6131631: "Stanisław Czarnomski: " + _deleted("2026-09-05"),
98
+ 6131646: "Mikołaj Dmochowski: " + _deleted("2026-09-05"),
99
+ 6132108: "Włodzimierz Daszkiewicz: " + _deleted("2026-09-06"),
100
+ 6132151: "Konstanty Jankowski (oficer): " + _deleted("2026-09-06"),
101
  }
102
  # {{ek}} reasons that state a copyright violation: the template's own codes that render as
103
  # "naruszenie praw autorskich" (npa, plagiat, copypaste, kopiuj-wklej) and free text naming one
 
382
  print(f"attribution rows: {n}")
383
 
384
 
385
+ def withhold(data_dir: Path) -> None:
386
+ """Drop from the committed release the pages added to COPIED_PAGES after the build, as prepare
387
+ would on a rebuild, without re-reading the dump: the parquet and sidecar rows, stats, build.json
388
+ (`prepare.counts` and `copied_pages`, attribution rows and sha) and the evidence's release scope.
389
+ Each is added to the copyright sample's `rows_dropped_since` with its stratum, so the sample's
390
+ draw still reproduces. Run before `relabel`; rerunning changes nothing."""
391
+ import pyarrow as pa
392
+ import pyarrow.compute as pc
393
+ import pyarrow.parquet as pq
394
+ from fetch_wikimedia import label_totals # not at the top: fetch_wikimedia imports this module
395
+
396
+ def path(name):
397
+ return data_dir / f"{SOURCE}.{name}"
398
+
399
+ side = [json.loads(line) for line in path("attribution.jsonl").open(encoding="utf-8")]
400
+ held = [rec for rec in side if rec["pageid"] in COPIED_PAGES]
401
+ if not held:
402
+ print(f"{SOURCE}: nothing to withhold")
403
+ return
404
+ build = load(path("build.json"))
405
+ if "licence_labels" in build: # ponytail: relabel's case counts would keep the withheld rows
406
+ raise ValueError(f"{SOURCE}: withhold before relabel, then filter the labels to the sidecar")
407
+ held_ids = {rec["id"] for rec in held}
408
+ table = pq.read_table(path("parquet"))
409
+ table = table.filter(pc.invert(pc.is_in(table["id"], pa.array(sorted(held_ids)))))
410
+ groups = pq.ParquetFile(path("parquet")).metadata.row_group(0).num_rows # build_dynaword's batches, kept
411
+ pq.write_table(table, path("parquet"), compression="zstd", row_group_size=groups)
412
+ side = [rec for rec in side if rec["id"] not in held_ids]
413
+ path("attribution.jsonl").write_text("".join(json.dumps(r, ensure_ascii=False) + "\n" for r in side), encoding="utf-8")
414
+
415
+ docs, tokens = label_totals(table["license"].to_pylist(), table["token_count"].to_pylist())
416
+ stats = load(path("stats.json"))
417
+ stats.update(read=stats["read"] - len(held), kept=table.num_rows, chars=pc.sum(pc.utf8_length(table["text"])).as_py(),
418
+ tokens=sum(tokens.values()), licenses=docs, authors_with_value=table.num_rows)
419
+ path("stats.json").write_text(json.dumps(stats, indent=2)) # build_dynaword's format
420
+ prep = build["prepare"]
421
+ prep["counts"]["copied_page"] += len(held)
422
+ for rec in held: # prepare's per-row label is the last revision's
423
+ prep["counts"][license_for_revision(rec["last_revision_at"])] -= 1
424
+ prep["copied_pages"] += [{"pageid": str(rec["pageid"]), "title": rec["title"], "reason": COPIED_PAGES[rec["pageid"]]}
425
+ for rec in held]
426
+ build.update(attribution_rows=len(side), attribution_sha256=digest(path("attribution.jsonl").read_bytes()))
427
+ save(path("build.json"), build)
428
+ ev = load(path("license-evidence.json"))
429
+ scope = ev["release_scope"]
430
+ scope.update(labels=docs, tokens_by_label=tokens, copied_pages=len(prep["copied_pages"]), documents_released=table.num_rows)
431
+ ev["copyright_sample"]["population"]["rows_dropped_since"] += [
432
+ [rec["id"], license_for_revision(rec["last_revision_at"])] for rec in held]
433
+ path("license-evidence.json").write_text(json.dumps(ev, ensure_ascii=False, indent=1) + "\n", encoding="utf-8") # the file's format
434
+ print(f"{SOURCE}: withheld {sorted(held_ids)}, {stats['kept']} rows left")
435
+
436
+
437
+ def relabel(out: Path, data_dir: Path) -> None:
438
+ """Label each row by contribution (v2#110) from out/wikipedia.labels.jsonl (wiki_history.py
439
+ compare): fetch_wikimedia.write_labels rewrites the parquet `license` column, the sidecar,
440
+ stats and build record; this updates the licence evidence's labels and tokens. Text, ids and
441
+ every other column are unchanged; rerunning changes nothing."""
442
+ from fetch_wikimedia import write_labels # not at the top: fetch_wikimedia imports this module
443
+ docs, tokens = write_labels(out, data_dir, SOURCE, "plwiki", BY_SA_4_CUTOFF)
444
+ path = data_dir / f"{SOURCE}.license-evidence.json"
445
+ ev = load(path)
446
+ ev["license"] = "CC-BY-SA-3.0, CC-BY-SA-4.0 or both per record, by contribution date"
447
+ ev["review_scope"] = ("licence of contributors' text on pl.wikipedia and its version per contribution; "
448
+ "copyright pastes estimated by sample; not independent legal advice")
449
+ scope = ev["release_scope"]
450
+ scope.pop("tokens_by_label", None) # the wikimedia sources' name, so their card text applies
451
+ scope.update(labels=docs, tokens=tokens)
452
+ path.write_text(json.dumps(ev, ensure_ascii=False, indent=1) + "\n", encoding="utf-8") # the file's format
453
+ print(f"{SOURCE}: relabelled, {docs}")
454
+
455
+
456
  def main() -> None:
457
  ap = argparse.ArgumentParser()
458
+ ap.add_argument("step", choices=["discover", "acquire", "extract", "prepare", "attribution", "withhold", "relabel"])
459
  ap.add_argument("--out", required=True, type=Path)
460
  ap.add_argument("--data-dir", type=Path, default=Path(__file__).resolve().parent.parent / "data" / SOURCE)
461
  ap.add_argument("--workers", type=int, default=8)
 
463
  a.out.mkdir(parents=True, exist_ok=True)
464
  {"discover": lambda: discover(a.out), "acquire": lambda: acquire(a.out),
465
  "extract": lambda: extract(a.out, a.workers), "prepare": lambda: prepare(a.out),
466
+ "attribution": lambda: attribution(a.out, a.data_dir), "withhold": lambda: withhold(a.data_dir),
467
+ "relabel": lambda: relabel(a.out, a.data_dir)}[a.step]()
468
 
469
 
470
  if __name__ == "__main__":
src/sources.py CHANGED
@@ -131,24 +131,31 @@ SOURCES = {
131
  "dump's sha1sums.txt) by src/fetch_wikipedia.py. Articles (namespace 0) "
132
  "only, no redirects; one document per page, id from the page id. "
133
  "v0.2.0-v0.2.5 used the SpeakLeash plwiki snapshot; that intermediary "
134
- "was removed in the v0.2.6 rebuild.",
 
 
135
  "legal_note": "Pages carrying the plwiki copyright-violation notice {{NPA}} (or its "
136
  "redirects {{Copyvio}}, {{Plagiat}}) in the dump are dropped, as are "
137
  "pages whose speedy-deletion notice {{ek}} gives a copyright reason and "
138
- "the pages the copyright sample found copied (COPIED_PAGES in "
 
139
  "src/fetch_wikipedia.py). Other text pasted into an article cannot be "
140
  "detected; the stratified web sample is recorded in "
141
  "wikipedia.license-evidence.json.",
142
- "license": "CC BY-SA (3.0 or 4.0 per record, by last-revision date)",
143
  "license_spdx": "MIXED",
144
- "traceable": "Contributors license their text under CC BY-SA 4.0 since the Wikimedia "
145
- "Terms of Use of 2023-06-07, under CC BY-SA 3.0 before. A page whose "
146
- "last revision predates 2023-06-07 is labelled CC-BY-SA-3.0; a page "
147
- "revised on or after that day is an adaptation of the 3.0 text, which "
148
- "3.0 §4(b)(ii) allows under 4.0, and is labelled CC-BY-SA-4.0. Each "
149
- "row's author field links its page, whose history names the "
150
- "contributors; wikipedia.attribution.jsonl gives page id, revision id, "
151
- "title and last-revision time per row.",
 
 
 
 
152
  "upstream": "https://dumps.wikimedia.org/plwiki/20260901/",
153
  "domain": "encyclopedic",
154
  "created": "2010-11-12, 2026-09-01",
 
131
  "dump's sha1sums.txt) by src/fetch_wikipedia.py. Articles (namespace 0) "
132
  "only, no redirects; one document per page, id from the page id. "
133
  "v0.2.0-v0.2.5 used the SpeakLeash plwiki snapshot; that intermediary "
134
+ "was removed in the v0.2.6 rebuild. The licence labels come from the "
135
+ "page histories (stub-meta-history dump plwiki-20261001, "
136
+ "src/wiki_history.py).",
137
  "legal_note": "Pages carrying the plwiki copyright-violation notice {{NPA}} (or its "
138
  "redirects {{Copyvio}}, {{Plagiat}}) in the dump are dropped, as are "
139
  "pages whose speedy-deletion notice {{ek}} gives a copyright reason and "
140
+ "the pages found to hold copied text, by the copyright sample or by a "
141
+ "plwiki deletion for copyright after the dump (COPIED_PAGES in "
142
  "src/fetch_wikipedia.py). Other text pasted into an article cannot be "
143
  "detected; the stratified web sample is recorded in "
144
  "wikipedia.license-evidence.json.",
145
+ "license": "CC BY-SA (3.0, 4.0 or both per record, by contribution date)",
146
  "license_spdx": "MIXED",
147
+ "traceable": "Contributors license their text under CC BY-SA 4.0 since the "
148
+ "Wikimedia Terms of Use of 2023-06-07, under CC BY-SA 3.0 before, "
149
+ "and each contribution keeps the licence it was made under. A row "
150
+ "whose text was all contributed before 2023-06-07 is labelled "
151
+ "CC-BY-SA-3.0, a page created on or after that day CC-BY-SA-4.0, "
152
+ "and a row holding text from both sides, or whose text before that "
153
+ "day cannot be compared (a hidden revision or a page deleted "
154
+ "since), 'CC-BY-SA-3.0 AND CC-BY-SA-4.0'. Each row's author field "
155
+ "links its page, whose history names the contributors; "
156
+ "wikipedia.attribution.jsonl gives page id, revision id, title, "
157
+ "last-revision time, the basis of the label and the page's last "
158
+ "revision before 2023-06-07 per row.",
159
  "upstream": "https://dumps.wikimedia.org/plwiki/20260901/",
160
  "domain": "encyclopedic",
161
  "created": "2010-11-12, 2026-09-01",
src/test_wiki_history.py CHANGED
@@ -247,6 +247,12 @@ def test_compare(tmp_path):
247
  assert out[3]["first_at"] == "2025-01-01T00:00:00Z" and out[2]["first_at"] is None # page 2 is not in the dump
248
  # page 1 was deleted after the build: its shipped revision is still its last before the cutoff
249
  assert (out[1]["pre_revid"], out[1]["pre_at"]) == (19, "2020-01-01T00:00:00Z") and out[2]["pre_revid"] is None
 
 
 
 
 
 
250
  recs.pop(80)
251
  (fetched_dir / "00000.jsonl.zst").unlink()
252
  wh.fetch("wikinews", [(0, r) for r in sorted(recs)], tmp_path, session=API(), log=lambda m: None)
@@ -281,6 +287,25 @@ def test_download_checks_a_present_file(tmp_path):
281
  wh.download("plwikivoyage", tmp_path, Status("0" * 40, "in-progress"))
282
 
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  def test_apply_labels():
285
  import pyarrow as pa
286
  side = [{"id": f"w_{i}", "last_revision_at": f"2025-01-0{i}T00:00:00Z", "license": "old"} for i in (1, 2)]
 
247
  assert out[3]["first_at"] == "2025-01-01T00:00:00Z" and out[2]["first_at"] is None # page 2 is not in the dump
248
  # page 1 was deleted after the build: its shipped revision is still its last before the cutoff
249
  assert (out[1]["pre_revid"], out[1]["pre_at"]) == (19, "2020-01-01T00:00:00Z") and out[2]["pre_revid"] is None
250
+ # sidecar slices, run apart and joined in order, give the same records
251
+ lines, joined = side.read_text().splitlines(keepends=True), []
252
+ for k, part in enumerate((lines[:5], lines[5:])):
253
+ (piece := tmp_path / f"side{k}.jsonl").write_text("".join(part))
254
+ joined += wh.compare("wikinews", piece, hist, fetched_dir, parquet, convert)
255
+ assert joined == list(out.values())
256
  recs.pop(80)
257
  (fetched_dir / "00000.jsonl.zst").unlink()
258
  wh.fetch("wikinews", [(0, r) for r in sorted(recs)], tmp_path, session=API(), log=lambda m: None)
 
287
  wh.download("plwikivoyage", tmp_path, Status("0" * 40, "in-progress"))
288
 
289
 
290
+ def test_download_takes_a_big_wiki_file_from_the_recombine_job(tmp_path):
291
+ body = b"stub"
292
+ name = "plwiki-20261001-stub-meta-history.xml.gz"
293
+ (tmp_path / name).write_bytes(body)
294
+
295
+ class Status:
296
+ def __init__(self, state):
297
+ self.state = state
298
+
299
+ def get(self, url, headers, timeout):
300
+ return FakeResp({"jobs": {
301
+ "xmlstubsdump": {"status": "done", "files": {"plwiki-20261001-stub-meta-history1.xml.gz": {}}},
302
+ "xmlstubsdumprecombine": {"status": self.state, "files": {name: {"size": 4, "sha1": hashlib.sha1(body).hexdigest()}}}}})
303
+
304
+ assert wh.download("plwiki", tmp_path, Status("done"))["name"] == name
305
+ with pytest.raises(ValueError, match="plwiki xmlstubsdumprecombine not done"):
306
+ wh.download("plwiki", tmp_path, Status("in-progress"))
307
+
308
+
309
  def test_apply_labels():
310
  import pyarrow as pa
311
  side = [{"id": f"w_{i}", "last_revision_at": f"2025-01-0{i}T00:00:00Z", "license": "old"} for i in (1, 2)]
src/test_wikimedia_contract.py CHANGED
@@ -526,6 +526,22 @@ def test_attribution_fails_when_the_parquet_has_a_row_the_dump_does_not(tmp_path
526
 
527
  # --- the contract on a released source -----------------------------------------------------
528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  def check_released(key, tmp_path, dropped=(0, 0, 0)):
530
  """Checks that hold for any source built by fetch_wikimedia.py; counts specific to a source live in its own test file.
531
  `dropped` is (documents, characters, tokens) of the v0.2.5 rows that DROPPED_PAGES[key] withholds."""
@@ -575,16 +591,11 @@ def check_released(key, tmp_path, dropped=(0, 0, 0)):
575
  # every row's date, author and id follow the page's last revision; its label too, until the
576
  # release is relabelled by contribution (relabel), then the basis recorded per row
577
  by_contribution = build.get("licence_labels")
578
- licence = {"before": site["before"], "after": site["after"], "mixed": f"{site['before']} AND {site['after']}"}
 
579
  for row_id, created, label, author in zip(cols["id"], cols["created"], cols["license"], cols["author"]):
580
  m = meta[row_id]
581
- if by_contribution:
582
- basis = m["license_basis"]
583
- assert label == m["license"] == licence[wh.CASES[basis]]
584
- assert (basis == "shipped_before_cutoff") == (m["last_revision_at"] < wh.WIKIS[key]["cutoff"])
585
- assert (m["pre_cutoff_revid"] is None) == (basis in ("created_after_cutoff", "page_not_in_dump"))
586
- assert basis != "shipped_before_cutoff" or m["pre_cutoff_revid"] == int(m["revid"])
587
- else:
588
  assert label == m["license"] == fm.label(key, m["last_revision_at"]) and label in (site["before"], site["after"])
589
  assert created == m["last_revision_at"][:10]
590
  assert m["url"] == fm.page_url(key, m["title"]) and author == f"{site['author']}, {m['url']}"
@@ -594,10 +605,6 @@ def check_released(key, tmp_path, dropped=(0, 0, 0)):
594
  for label, tok in zip(cols["license"], cols["token_count"]):
595
  tokens[label] += tok
596
  assert stats["licenses"] == dict(Counter(cols["license"])) == scope["labels"] and scope["tokens"] == dict(tokens)
597
- if by_contribution:
598
- assert by_contribution["cases"] == dict(Counter(m["license_basis"] for m in meta.values()))
599
- stub = by_contribution["stub"]
600
- assert stub["name"] == f"{site['wiki']}-{wh.STUB_DATE}-stub-meta-history.xml.gz" and SHA1.fullmatch(stub["sha1"])
601
  assert scope["created_range"] == [min(cols["created"]), max(cols["created"])]
602
  day = site["cutoff"].date().isoformat()
603
  on_day = [m["last_revision_at"] for m in meta.values() if m["last_revision_at"].startswith(day)]
 
526
 
527
  # --- the contract on a released source -----------------------------------------------------
528
 
529
+ def check_contribution_labels(key, cols, meta, build):
530
+ """The labels by contribution (v2#110) on a released source relabelled from wiki_history.compare:
531
+ each row's label follows its recorded basis, and the build record counts the bases."""
532
+ cfg, labels = wh.WIKIS[key], build["licence_labels"]
533
+ licence = {"before": cfg["before"], "after": cfg["after"], "mixed": f"{cfg['before']} AND {cfg['after']}"}
534
+ for row_id, label in zip(cols["id"], cols["license"]):
535
+ m = meta[row_id]
536
+ basis = m["license_basis"]
537
+ assert label == m["license"] == licence[wh.CASES[basis]]
538
+ assert (basis == "shipped_before_cutoff") == (m["last_revision_at"] < cfg["cutoff"])
539
+ assert (m["pre_cutoff_revid"] is None) == (basis in ("created_after_cutoff", "page_not_in_dump"))
540
+ assert basis != "shipped_before_cutoff" or m["pre_cutoff_revid"] == int(m["revid"])
541
+ assert labels["cases"] == dict(Counter(m["license_basis"] for m in meta.values()))
542
+ assert labels["stub"]["name"] == f"{cfg['dump']}-{wh.STUB_DATE}-stub-meta-history.xml.gz" and SHA1.fullmatch(labels["stub"]["sha1"])
543
+
544
+
545
  def check_released(key, tmp_path, dropped=(0, 0, 0)):
546
  """Checks that hold for any source built by fetch_wikimedia.py; counts specific to a source live in its own test file.
547
  `dropped` is (documents, characters, tokens) of the v0.2.5 rows that DROPPED_PAGES[key] withholds."""
 
591
  # every row's date, author and id follow the page's last revision; its label too, until the
592
  # release is relabelled by contribution (relabel), then the basis recorded per row
593
  by_contribution = build.get("licence_labels")
594
+ if by_contribution:
595
+ check_contribution_labels(key, cols, meta, build)
596
  for row_id, created, label, author in zip(cols["id"], cols["created"], cols["license"], cols["author"]):
597
  m = meta[row_id]
598
+ if not by_contribution:
 
 
 
 
 
 
599
  assert label == m["license"] == fm.label(key, m["last_revision_at"]) and label in (site["before"], site["after"])
600
  assert created == m["last_revision_at"][:10]
601
  assert m["url"] == fm.page_url(key, m["title"]) and author == f"{site['author']}, {m['url']}"
 
605
  for label, tok in zip(cols["license"], cols["token_count"]):
606
  tokens[label] += tok
607
  assert stats["licenses"] == dict(Counter(cols["license"])) == scope["labels"] and scope["tokens"] == dict(tokens)
 
 
 
 
608
  assert scope["created_range"] == [min(cols["created"]), max(cols["created"])]
609
  day = site["cutoff"].date().isoformat()
610
  on_day = [m["last_revision_at"] for m in meta.values() if m["last_revision_at"].startswith(day)]
src/test_wikipedia_contract.py CHANGED
@@ -13,8 +13,10 @@ import pyarrow as pa
13
  import pyarrow.parquet as pq
14
  import pytest
15
 
 
16
  import fetch_wikipedia as fw
17
  from sources import SOURCES
 
18
  from verify_paper_claims import license_family
19
 
20
  ROOT = Path(__file__).resolve().parents[1]
@@ -195,13 +197,84 @@ def test_prepare_fails_when_a_listed_page_is_not_reached(tmp_path, monkeypatch):
195
  fw.prepare(tmp_path)
196
 
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  # --- released data -------------------------------------------------------------------------
199
 
200
  def _released():
201
- table = pq.read_table(DATA / "wikipedia.parquet", columns=["id", "source", "created", "license", "author"])
202
  return table, table.to_pydict()
203
 
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  def test_registry_entry():
206
  entry = SOURCES["wikipedia"]
207
  assert entry["file_key"] == "wikipedia" and "speakleash_key" not in entry
@@ -253,23 +326,29 @@ def test_tag_template_aliases_match_the_dump():
253
  assert fw.ek_tag("{{%s|npa}}" % name) == {"reason": "npa", "source": ""}
254
 
255
 
256
- def test_every_row_label_follows_its_last_revision():
257
  table, cols = _released()
258
- meta = {}
259
- with (DATA / "wikipedia.attribution.jsonl").open(encoding="utf-8") as fh:
260
- for line in fh:
261
- row = json.loads(line)
262
- meta[row["id"]] = row
263
  assert len(meta) == table.num_rows
264
- for row_id, created, label, author in zip(cols["id"], cols["created"], cols["license"], cols["author"]):
265
  m = meta[row_id]
266
- assert label == m["license"] == fw.license_for_revision(m["last_revision_at"])
267
  assert created == m["last_revision_at"][:10]
268
  assert author == f"{fw.AUTHOR}, {m['url']}"
269
  assert row_id == f"wikipedia_{m['pageid']}"
270
- stats = json.loads((DATA / "wikipedia.stats.json").read_text(encoding="utf-8"))
271
- evidence = json.loads((DATA / "wikipedia.license-evidence.json").read_text(encoding="utf-8"))
272
- assert stats["licenses"] == dict(Counter(cols["license"])) == evidence["release_scope"]["labels"]
 
 
 
 
 
 
 
 
 
 
 
273
 
274
 
275
  def test_copyright_sample_matches_the_release():
@@ -282,11 +361,13 @@ def test_copyright_sample_matches_the_release():
282
  sample = json.loads((DATA / "wikipedia.license-evidence.json").read_text(encoding="utf-8"))["copyright_sample"]
283
  rows = [json.loads(line) for line in (DATA / sample["file"]).read_text(encoding="utf-8").splitlines()]
284
  _, cols = _released()
285
- prepare = json.loads((DATA / "wikipedia.build.json").read_text(encoding="utf-8"))["prepare"]
 
286
  copyright_drops = {f"wikipedia_{p['pageid']}" for p in prepare["copied_pages"] + prepare["ek_copyright"]}
287
  dropped = dict(sample["population"]["rows_dropped_since"])
288
  assert set(dropped) <= copyright_drops and not set(dropped) & set(cols["id"])
289
- population = list(zip(cols["id"], cols["license"])) + list(dropped.items())
 
290
  random.seed(sample["seed"])
291
  expected = []
292
  for label in sorted(sample["per_stratum"]):
 
13
  import pyarrow.parquet as pq
14
  import pytest
15
 
16
+ import fetch_wikimedia as fm
17
  import fetch_wikipedia as fw
18
  from sources import SOURCES
19
+ from test_wikimedia_contract import check_contribution_labels
20
  from verify_paper_claims import license_family
21
 
22
  ROOT = Path(__file__).resolve().parents[1]
 
197
  fw.prepare(tmp_path)
198
 
199
 
200
+ def test_withhold_drops_pages_added_after_the_build(tmp_path, monkeypatch):
201
+ monkeypatch.setattr(fw, "COPIED_PAGES", {20: "Kret: copied", 30: "Mysz: deleted"})
202
+ rows = [("wikipedia_10", 10, "Ala ma kota.", "2010-01-01T00:00:00Z", 4),
203
+ ("wikipedia_30", 30, "Mysz é", "2024-01-01T00:00:00Z", 3),
204
+ ("wikipedia_40", 40, "Kret", "2025-01-01T00:00:00Z", 2)]
205
+ lic = [fw.license_for_revision(r[3]) for r in rows]
206
+ pq.write_table(pa.table({"id": [r[0] for r in rows], "text": [r[2] for r in rows], "license": lic,
207
+ "token_count": [r[4] for r in rows]}), tmp_path / "wikipedia.parquet")
208
+ (tmp_path / "wikipedia.attribution.jsonl").write_text("".join(json.dumps(
209
+ {"id": i, "pageid": p, "title": t[:4], "last_revision_at": at, "license": label}) + "\n"
210
+ for (i, p, t, at, _), label in zip(rows, lic)))
211
+ (tmp_path / "wikipedia.stats.json").write_text(json.dumps(
212
+ {"read": 5, "kept": 3, "chars": 22, "tokens": 9, "licenses": {}, "authors_with_value": 3, "secs": 1}))
213
+ fw.save(tmp_path / "wikipedia.build.json", {"prepare": {
214
+ "counts": {"extracted": 6, "exact_duplicate": 0, "copied_page": 1, "ek_copyright": 0,
215
+ "CC-BY-SA-3.0": 2, "CC-BY-SA-4.0": 3},
216
+ "copied_pages": [{"pageid": "20", "title": "Kret", "reason": "Kret: copied"}]}, "attribution_rows": 3})
217
+ fw.save(tmp_path / "wikipedia.license-evidence.json", {
218
+ "release_scope": {"labels": {}, "tokens_by_label": {}, "copied_pages": 1, "documents_released": 3},
219
+ "copyright_sample": {"population": {"documents": 4, "rows_dropped_since": [["wikipedia_20", "CC-BY-SA-3.0"]]}}})
220
+
221
+ fw.withhold(tmp_path)
222
+ assert pq.read_table(tmp_path / "wikipedia.parquet")["id"].to_pylist() == ["wikipedia_10", "wikipedia_40"]
223
+ assert [json.loads(line)["id"] for line in (tmp_path / "wikipedia.attribution.jsonl").read_text().splitlines()] == [
224
+ "wikipedia_10", "wikipedia_40"]
225
+ stats = json.loads((tmp_path / "wikipedia.stats.json").read_text())
226
+ assert stats == {"read": 4, "kept": 2, "chars": 16, "tokens": 6, "authors_with_value": 2, "secs": 1,
227
+ "licenses": {"CC-BY-SA-3.0": 1, "CC-BY-SA-4.0": 1}}
228
+ build = fw.load(tmp_path / "wikipedia.build.json")
229
+ counts = build["prepare"]["counts"]
230
+ assert counts == {"extracted": 6, "exact_duplicate": 0, "copied_page": 2, "ek_copyright": 0,
231
+ "CC-BY-SA-3.0": 2, "CC-BY-SA-4.0": 2}
232
+ # the release's read arithmetic still holds
233
+ assert stats["read"] == counts["extracted"] - counts["exact_duplicate"] - counts["copied_page"] - counts["ek_copyright"]
234
+ assert [p["pageid"] for p in build["prepare"]["copied_pages"]] == ["20", "30"]
235
+ assert build["prepare"]["copied_pages"][1]["reason"] == "Mysz: deleted"
236
+ assert build["attribution_rows"] == 2
237
+ assert build["attribution_sha256"] == fm.digest((tmp_path / "wikipedia.attribution.jsonl").read_bytes())
238
+ ev = fw.load(tmp_path / "wikipedia.license-evidence.json")
239
+ assert ev["release_scope"] == {"labels": {"CC-BY-SA-3.0": 1, "CC-BY-SA-4.0": 1},
240
+ "tokens_by_label": {"CC-BY-SA-3.0": 4, "CC-BY-SA-4.0": 2},
241
+ "copied_pages": 2, "documents_released": 2}
242
+ assert ev["copyright_sample"]["population"] == {
243
+ "documents": 4, "rows_dropped_since": [["wikipedia_20", "CC-BY-SA-3.0"], ["wikipedia_30", "CC-BY-SA-4.0"]]}
244
+
245
+ before = {p.name: p.read_bytes() for p in tmp_path.iterdir()}
246
+ fw.withhold(tmp_path) # rerun: nothing left to withhold
247
+ assert {p.name: p.read_bytes() for p in tmp_path.iterdir()} == before
248
+
249
+ monkeypatch.setattr(fw, "COPIED_PAGES", {10: "Ala: deleted"})
250
+ fw.save(tmp_path / "wikipedia.build.json", {**build, "licence_labels": {}})
251
+ with pytest.raises(ValueError, match="before relabel"):
252
+ fw.withhold(tmp_path)
253
+
254
+
255
  # --- released data -------------------------------------------------------------------------
256
 
257
  def _released():
258
+ table = pq.read_table(DATA / "wikipedia.parquet", columns=["id", "source", "created", "token_count", "license", "author"])
259
  return table, table.to_pydict()
260
 
261
 
262
+ def _meta():
263
+ with (DATA / "wikipedia.attribution.jsonl").open(encoding="utf-8") as fh:
264
+ return {r["id"]: r for r in map(json.loads, fh)}
265
+
266
+
267
+ def _read(name):
268
+ return json.loads((DATA / f"wikipedia.{name}.json").read_text(encoding="utf-8"))
269
+
270
+
271
+ # the release's labels by contribution (v2#110), from the stub dump plwiki-20261001-stub-meta-history.xml.gz
272
+ LABELS = {"CC-BY-SA-3.0": 719119, "CC-BY-SA-3.0 AND CC-BY-SA-4.0": 629454, "CC-BY-SA-4.0": 120074}
273
+ CASES = {"shipped_before_cutoff": 190836, "same_revision_text": 5028, "identical_text": 492757, "no_text_added": 30498,
274
+ "created_after_cutoff": 120074, "changed_after_cutoff": 629338, "page_not_in_dump": 85, "pre_text_hidden": 31}
275
+ STUB_SHA1 = "47fd7549026521bd02c174ee418c63a93f7e4118"
276
+
277
+
278
  def test_registry_entry():
279
  entry = SOURCES["wikipedia"]
280
  assert entry["file_key"] == "wikipedia" and "speakleash_key" not in entry
 
326
  assert fw.ek_tag("{{%s|npa}}" % name) == {"reason": "npa", "source": ""}
327
 
328
 
329
+ def test_every_row_is_labelled_by_contribution():
330
  table, cols = _released()
331
+ meta = _meta()
 
 
 
 
332
  assert len(meta) == table.num_rows
333
+ for row_id, created, author in zip(cols["id"], cols["created"], cols["author"]):
334
  m = meta[row_id]
 
335
  assert created == m["last_revision_at"][:10]
336
  assert author == f"{fw.AUTHOR}, {m['url']}"
337
  assert row_id == f"wikipedia_{m['pageid']}"
338
+ stats, build, ev = _read("stats"), _read("build"), _read("license-evidence")
339
+ check_contribution_labels("wikipedia", cols, meta, build)
340
+ assert build["attribution_sha256"] == fm.digest((DATA / "wikipedia.attribution.jsonl").read_bytes())
341
+ tokens = Counter()
342
+ for label, tok in zip(cols["license"], cols["token_count"]):
343
+ tokens[label] += tok
344
+ scope = ev["release_scope"]
345
+ assert stats["licenses"] == dict(Counter(cols["license"])) == scope["labels"] and scope["tokens"] == dict(tokens)
346
+ assert stats["license"] == SOURCES["wikipedia"]["license"]
347
+ assert stats["licenses"] == LABELS and build["licence_labels"]["cases"] == CASES
348
+ assert build["licence_labels"]["stub"]["sha1"] == STUB_SHA1
349
+ # the card's account of the labels is the one the wikimedia cards carry
350
+ card = (DATA / "wikipedia.md").read_text(encoding="utf-8")
351
+ assert fm.contribution_text("wikipedia", build, ev, stats["tokens"]) in card
352
 
353
 
354
  def test_copyright_sample_matches_the_release():
 
361
  sample = json.loads((DATA / "wikipedia.license-evidence.json").read_text(encoding="utf-8"))["copyright_sample"]
362
  rows = [json.loads(line) for line in (DATA / sample["file"]).read_text(encoding="utf-8").splitlines()]
363
  _, cols = _released()
364
+ meta = _meta()
365
+ prepare = _read("build")["prepare"]
366
  copyright_drops = {f"wikipedia_{p['pageid']}" for p in prepare["copied_pages"] + prepare["ek_copyright"]}
367
  dropped = dict(sample["population"]["rows_dropped_since"])
368
  assert set(dropped) <= copyright_drops and not set(dropped) & set(cols["id"])
369
+ # the strata are the labels by last revision the release carried before v2#110
370
+ population = [(i, fw.license_for_revision(meta[i]["last_revision_at"])) for i in cols["id"]] + list(dropped.items())
371
  random.seed(sample["seed"])
372
  expected = []
373
  for label in sorted(sample["per_stratum"]):
src/wiki_history.py CHANGED
@@ -84,9 +84,12 @@ def download(dump: str, out: Path, session=None) -> dict:
84
  session = session or requests.Session()
85
  base = f"https://dumps.wikimedia.org/{dump}/{STUB_DATE}"
86
  name = f"{dump}-{STUB_DATE}-stub-meta-history.xml.gz"
87
- status = session.get(f"{base}/dumpstatus.json", headers={"User-Agent": UA}, timeout=60).json()["jobs"]["xmlstubsdump"]
 
 
 
88
  if status["status"] != "done":
89
- raise ValueError(f"{dump} xmlstubsdump not done: {status['status']}")
90
  meta, dst = status["files"][name], out / name
91
  if not dst.exists() or dst.stat().st_size != meta["size"]:
92
  subprocess.run(["curl", "-fsSL", "--retry", "8", "-C", "-", "-A", UA, "-o", str(dst), f"{base}/{name}"], check=True)
@@ -383,8 +386,11 @@ def compare(source: str, sidecar: Path, history: Path, fetched: Path, parquet: P
383
  cfg = WIKIS[source]
384
  convert = convert or _converter(source)
385
  side = [json.loads(line) for line in open(sidecar, encoding="utf-8")]
386
- hist = {r["pageid"]: r for r in map(json.loads, open(history, encoding="utf-8"))}
387
- pre = {r["revid"]: r for r in read_texts(fetched)}
 
 
 
388
  need = [r["id"] for r in side if r["last_revision_at"] >= cfg["cutoff"]]
389
  shipped = dict(zip(*pq.read_table(parquet, columns=["id", "text"], filters=[("id", "in", need)] if need else None)
390
  .to_pydict().values())) if need else {}
 
84
  session = session or requests.Session()
85
  base = f"https://dumps.wikimedia.org/{dump}/{STUB_DATE}"
86
  name = f"{dump}-{STUB_DATE}-stub-meta-history.xml.gz"
87
+ jobs = session.get(f"{base}/dumpstatus.json", headers={"User-Agent": UA}, timeout=60).json()["jobs"]
88
+ # a big wiki (plwiki) is dumped in parts, and the whole file comes from the recombine job
89
+ job = "xmlstubsdumprecombine" if name in jobs.get("xmlstubsdumprecombine", {}).get("files", {}) else "xmlstubsdump"
90
+ status = jobs[job]
91
  if status["status"] != "done":
92
+ raise ValueError(f"{dump} {job} not done: {status['status']}")
93
  meta, dst = status["files"][name], out / name
94
  if not dst.exists() or dst.stat().st_size != meta["size"]:
95
  subprocess.run(["curl", "-fsSL", "--retry", "8", "-C", "-", "-A", UA, "-o", str(dst), f"{base}/{name}"], check=True)
 
386
  cfg = WIKIS[source]
387
  convert = convert or _converter(source)
388
  side = [json.loads(line) for line in open(sidecar, encoding="utf-8")]
389
+ # only this sidecar's pages and revisions, so a big source can run as sidecar slices in parallel
390
+ pageids = {int(r["pageid"]) for r in side}
391
+ hist = {r["pageid"]: r for r in map(json.loads, open(history, encoding="utf-8")) if r["pageid"] in pageids}
392
+ revids = {h["pre_revid"] for h in hist.values()}
393
+ pre = {r["revid"]: r for r in read_texts(fetched) if r["revid"] in revids}
394
  need = [r["id"] for r in side if r["last_revision_at"] >= cfg["cutoff"]]
395
  shipped = dict(zip(*pq.read_table(parquet, columns=["id", "text"], filters=[("id", "in", need)] if need else None)
396
  .to_pydict().values())) if need else {}