Datasets:
biblioteka_nauki: per-record licence versions from the API (42,068 -> 42,055 docs, v2#57) (#81)
Browse files- biblioteka_nauki: per-record licence versions from the API (42,068 -> 42,055 docs, v0.2.6, v2#57) (38c3442a1269dbf3a701d4a9f5b7371579920608)
- biblioteka_nauki: say where the text came from (SpeakLeash), not "direct rebuild" (v2#57) (fed6b6b61d927132910c42cddc0543708b98ad5f)
- biblioteka_nauki: withhold 71 rows by id, relabel articles_2011995 (maintainer 2026-10-06, v2#57) (5fb1715a69eb87c302cbe6002648dddbc75f289d)
- artifacts/source_findings.md +40 -0
- data/biblioteka_nauki/biblioteka_nauki.license-api.json +0 -0
- data/biblioteka_nauki/biblioteka_nauki.license-evidence.json +155 -0
- data/biblioteka_nauki/biblioteka_nauki.md +62 -20
- data/biblioteka_nauki/biblioteka_nauki.parquet +2 -2
- data/biblioteka_nauki/biblioteka_nauki.stats.json +101 -7
- data/biblioteka_nauki/recover_license_versions.py +238 -0
- src/clean_biblioteka_nauki.py +165 -5
- src/sources.py +23 -8
- src/test_biblioteka_nauki_contract.py +324 -16
artifacts/source_findings.md
CHANGED
|
@@ -2174,3 +2174,43 @@ rights audit action "check live site manually (CAPTCHA); resolve 3.0 vs 4.0".
|
|
| 2174 |
|
| 2175 |
**Lesson:** the audit found the live site behind a verification page, yet a plain read-only
|
| 2176 |
GET returned it on 2026-10-06. Retry that before routing a check to a human.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2174 |
|
| 2175 |
**Lesson:** the audit found the live site behind a verification page, yet a plain read-only
|
| 2176 |
GET returned it on 2026-10-06. Retry that before routing a check to a human.
|
| 2177 |
+
|
| 2178 |
+
## biblioteka_nauki — licence versions restored from the API (2026-10-06)
|
| 2179 |
+
|
| 2180 |
+
**Verdict** — `added`, kept for v0.2.6 minus 83 rows (polish-dynaword-v2#57; maintainer approval
|
| 2181 |
+
2026-10-06). 42,068 → 41,985 documents, 673,112,676 → 669,909,430 tokens (−3,203,246),
|
| 2182 |
+
1,747,387,478 → 1,739,004,913 characters. The `license` column now carries the version the API
|
| 2183 |
+
gives per record: CC-BY-4.0 17,768, CC-BY-3.0-PL 8,098, CC-BY-3.0 2,413, CC-BY-2.0 1, CC-BY-SA-4.0
|
| 2184 |
+
10,944, CC-BY-SA-3.0-PL 2,754, CC-BY-SA-3.0 7. Before, 28,335 rows said `cc-by` and 13,733
|
| 2185 |
+
`cc-by-sa`, and the card said 4.0 for all. Only that column changed: same ids in the same
|
| 2186 |
+
order, same text hashes for the 41,985 shipped rows (digest in `stats.json` and the evidence file).
|
| 2187 |
+
|
| 2188 |
+
**Method** — `data/biblioteka_nauki/recover_license_versions.py` asked
|
| 2189 |
+
`bibliotekanauki.pl/api/{type}/{id}` once per row of the previous release (2026-10-05/06, one
|
| 2190 |
+
request clock, 3 workers, back-off on 429/5xx, stop on 403). 42,056 answered 200; no block, no
|
| 2191 |
+
CAPTCHA. The responses are committed as `biblioteka_nauki.license-api.json`. The cleaner labels
|
| 2192 |
+
a row only when the `creativecommons.org` URL, the English name and the icon agree with each other
|
| 2193 |
+
and with the earlier label, for CC BY / BY-SA 2.0 to 4.0 (generic or PL); anything else is withheld.
|
| 2194 |
+
|
| 2195 |
+
**Withheld (83)** — 12 rows the API now answers with 404 (`articles_512191`, `604103`, `605338`,
|
| 2196 |
+
`694689`, `699376`, `699392`, `699396`, `699422`, `699424`, `699432`, `699440`, `699442`; asked
|
| 2197 |
+
again by hand, 404 again); 56 rows whose text prints an NC or ND licence (Krytyka Prawa 2019 21,
|
| 2198 |
+
Journal of Health Sciences 2014 12, 23 others) and 15 rows whose text says it is reprinted or
|
| 2199 |
+
translated by permission of a publisher (Oxford University Press 3, others 12), both lists decided
|
| 2200 |
+
by the maintainer on 2026-10-06 and kept by id, with a reason per id, in
|
| 2201 |
+
`src/clean_biblioteka_nauki.py`. `articles_2011995`, whose API licence is CC BY-SA 4.0 while the
|
| 2202 |
+
earlier recovery said CC BY, is kept as CC-BY-SA-4.0. Why the platform dropped the 12 records, and
|
| 2203 |
+
whether it changed that licence after the first recovery, is not known.
|
| 2204 |
+
|
| 2205 |
+
**Not resolved** — the 3 Public Domain Mark rows were already gone (Hub PR 62). The 128 rows
|
| 2206 |
+
the earlier review found with "all rights reserved" in the text could not be reproduced exactly (regex variants give
|
| 2207 |
+
121 to 137, 127 for the whitespace-tolerant one; 4 of the 127 are among the withheld rows). All of them have a CC BY or CC BY-SA licence in
|
| 2208 |
+
the API, none is all-rights-reserved there. They stay in; the footer-versus-API conflict is a
|
| 2209 |
+
rights decision. 5 kept rows carry `reprintPublication` (2) or `translationPublication` (3);
|
| 2210 |
+
none has `restricted`. The card and registry say the text came from the SpeakLeash
|
| 2211 |
+
redistribution (Hub PR 11) with licence and attribution recovered per document from the API; the
|
| 2212 |
+
text-assembly script (`build_parquet.py`) is not in the repo or on the Hub, so how the text layer
|
| 2213 |
+
was assembled is not re-verified.
|
| 2214 |
+
|
| 2215 |
+
**Lesson** — a label that drops the version is not a licence. 28,280 rows are CC BY and
|
| 2216 |
+
13,705 CC BY-SA, and 13,273 of the 41,985 rows are not 4.0.
|
data/biblioteka_nauki/biblioteka_nauki.license-api.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/biblioteka_nauki/biblioteka_nauki.license-evidence.json
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "biblioteka_nauki",
|
| 3 |
+
"checked_at": "2026-10-06",
|
| 4 |
+
"status": "admitted: per-record CC BY / CC BY-SA, version carried per row",
|
| 5 |
+
"license_spdx": "MIXED (per row: CC-BY-2.0, CC-BY-3.0, CC-BY-3.0-PL, CC-BY-4.0, CC-BY-SA-3.0, CC-BY-SA-3.0-PL, CC-BY-SA-4.0)",
|
| 6 |
+
"review_scope": "Licence name, URL and version of every one of the 42,068 rows of the previous release (v0.2.5 after the Public Domain Mark drop, Hub PR 62), read from the platform API. Not a review of the texts, of the authors' standing to license, or of third-party material inside the items.",
|
| 7 |
+
"finding": "The API gives CC BY 2.0 / 3.0 / 3.0 PL / 4.0 and CC BY-SA 3.0 / 3.0 PL / 4.0 per record; v0.2.5 and the first v0.2.6 build collapsed all of them to 4.0 by keeping only license.iconId. The `license` column now holds the API's version. 12 rows the API no longer serves (HTTP 404) are withheld; so are, by the maintainer's decision of 2026-10-06, 56 rows whose text prints a NonCommercial or NoDerivatives licence and 15 rows whose text says it is reprinted or translated by permission of a publisher. articles_2011995 (API: CC BY-SA 4.0; earlier recovery: CC BY) is kept, labelled CC-BY-SA-4.0. No row's text changed.",
|
| 8 |
+
"upstream_api": "https://bibliotekanauki.pl/api/{articles|books|chapters}/{id}",
|
| 9 |
+
"retrieved": "2026-10-05..2026-10-06",
|
| 10 |
+
"retrieval_script": "data/biblioteka_nauki/recover_license_versions.py (one global request clock, 3 workers, 0.15 s between request starts, back-off on 429/5xx, stops on 403 or a non-JSON 200; no CAPTCHA or terms page was met)",
|
| 11 |
+
"sidecar": "data/biblioteka_nauki/biblioteka_nauki.license-api.json",
|
| 12 |
+
"sidecar_sha256": "51e0bf7900e016f4b0102eecfd5032f3969a566899bf8ba094abad9f4f4578b5",
|
| 13 |
+
"api_licenses": [
|
| 14 |
+
{
|
| 15 |
+
"api_license_id": 21,
|
| 16 |
+
"label": "CC-BY-2.0",
|
| 17 |
+
"nameEn": "CC BY: Creative Commons Attribution 2.0 Generic",
|
| 18 |
+
"urlEn": "https://creativecommons.org/licenses/by/2.0/legalcode",
|
| 19 |
+
"api_rows": 13,
|
| 20 |
+
"shipped": 1
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"api_license_id": 14,
|
| 24 |
+
"label": "CC-BY-3.0",
|
| 25 |
+
"nameEn": "CC BY: Creative Commons Attribution 3.0 Unported",
|
| 26 |
+
"urlEn": "https://creativecommons.org/licenses/by/3.0/legalcode",
|
| 27 |
+
"api_rows": 2413,
|
| 28 |
+
"shipped": 2413
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"api_license_id": 7,
|
| 32 |
+
"label": "CC-BY-3.0-PL",
|
| 33 |
+
"nameEn": "CC BY: Creative Commons Attribution 3.0 PL",
|
| 34 |
+
"urlEn": "https://creativecommons.org/licenses/by/3.0/pl/legalcode",
|
| 35 |
+
"api_rows": 8104,
|
| 36 |
+
"shipped": 8098
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"api_license_id": 1,
|
| 40 |
+
"label": "CC-BY-4.0",
|
| 41 |
+
"nameEn": "CC BY: Creative Commons Attribution 4.0",
|
| 42 |
+
"urlEn": "https://creativecommons.org/licenses/by/4.0/legalcode.en",
|
| 43 |
+
"api_rows": 17800,
|
| 44 |
+
"shipped": 17768
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"api_license_id": 15,
|
| 48 |
+
"label": "CC-BY-SA-3.0",
|
| 49 |
+
"nameEn": "CC BY-SA: Creative Commons Attribution-ShareAlike 3.0 Unported",
|
| 50 |
+
"urlEn": "https://creativecommons.org/licenses/by-sa/3.0/legalcode",
|
| 51 |
+
"api_rows": 7,
|
| 52 |
+
"shipped": 7
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"api_license_id": 8,
|
| 56 |
+
"label": "CC-BY-SA-3.0-PL",
|
| 57 |
+
"nameEn": "CC BY-SA: Creative Commons Attribution-ShareAlike 3.0 PL",
|
| 58 |
+
"urlEn": "https://creativecommons.org/licenses/by-sa/3.0/pl/legalcode",
|
| 59 |
+
"api_rows": 2761,
|
| 60 |
+
"shipped": 2754
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"api_license_id": 2,
|
| 64 |
+
"label": "CC-BY-SA-4.0",
|
| 65 |
+
"nameEn": "CC BY-SA: Creative Commons Attribution-ShareAlike 4.0",
|
| 66 |
+
"urlEn": "https://creativecommons.org/licenses/by-sa/4.0/legalcode.en",
|
| 67 |
+
"api_rows": 10958,
|
| 68 |
+
"shipped": 10944
|
| 69 |
+
}
|
| 70 |
+
],
|
| 71 |
+
"withheld": 83,
|
| 72 |
+
"withheld_reasons": {
|
| 73 |
+
"API: http404": 12,
|
| 74 |
+
"text prints a NonCommercial or NoDerivatives licence (maintainer decision 2026-10-06)": 56,
|
| 75 |
+
"text says it is reprinted or translated by permission of a publisher (maintainer decision 2026-10-06)": 15
|
| 76 |
+
},
|
| 77 |
+
"maintainer_decision": "2026-10-06 (polish-dynaword-v2#57, Hub PR 81): keep the 12 HTTP 404 rows withheld; relabel articles_2011995 to CC-BY-SA-4.0 and keep it; withhold 56 rows whose text prints an NC or ND licence and 15 rows whose text says it is reprinted or translated by permission of a publisher; keep rows whose wording is a citation, a quoted work's notice, prose about licence types, a permission for a figure or table, or a translation permitted by the author alone. The ids and one reason per id are in src/clean_biblioteka_nauki.py (TEXT_NC_ND, TEXT_REPRINT) and in the stats `withheld`.",
|
| 78 |
+
"flagged": {
|
| 79 |
+
"translationPublication": 3,
|
| 80 |
+
"reprintPublication": 2
|
| 81 |
+
},
|
| 82 |
+
"flagged_action": "kept; the flags (reprintPublication, translationPublication) are not a licence signal and restricted is set on no row",
|
| 83 |
+
"public_domain_mark": "3 rows (API licence id 22) already dropped in Hub PR 62; absent from the shard and from the sidecar",
|
| 84 |
+
"all_rights_reserved_text_phrase": {
|
| 85 |
+
"note": "Rows whose text contains the phrase. The earlier review counted 128 (88 cc-by, 40 cc-by-sa); this scan could not reproduce that exactly: four regex variants give 121, 126, 127 (87 CC BY, 40 CC BY-SA) and 137. Every one of them has a CC BY or CC BY-SA licence in the API; none is all-rights-reserved there. Kept; undecided. Counted on the 42,068 rows of Hub PR 62; of them 2 (cs) and 4 (ci, ws_ci) are among the 71 rows withheld on 2026-10-06, so the shipped shard has 119 / 122 / 123 (ws_ci_hyph not recomputed).",
|
| 86 |
+
"api_licenses_by_variant": {
|
| 87 |
+
"cs": {
|
| 88 |
+
"pattern": "case-sensitive 'Wszelkie prawa zastrzeżone' | 'All rights reserved'",
|
| 89 |
+
"rows": 121,
|
| 90 |
+
"api_licenses": {
|
| 91 |
+
"CC-BY-3.0-PL": 55,
|
| 92 |
+
"CC-BY-4.0": 29,
|
| 93 |
+
"CC-BY-SA-3.0-PL": 18,
|
| 94 |
+
"CC-BY-SA-4.0": 19
|
| 95 |
+
}
|
| 96 |
+
},
|
| 97 |
+
"ci": {
|
| 98 |
+
"pattern": "same, case-insensitive",
|
| 99 |
+
"rows": 126,
|
| 100 |
+
"api_licenses": {
|
| 101 |
+
"CC-BY-3.0-PL": 57,
|
| 102 |
+
"CC-BY-4.0": 30,
|
| 103 |
+
"CC-BY-SA-3.0-PL": 18,
|
| 104 |
+
"CC-BY-SA-4.0": 21
|
| 105 |
+
}
|
| 106 |
+
},
|
| 107 |
+
"ws_ci": {
|
| 108 |
+
"pattern": "case-insensitive, any whitespace between words (NFKC text)",
|
| 109 |
+
"rows": 127,
|
| 110 |
+
"api_licenses": {
|
| 111 |
+
"CC-BY-3.0-PL": 57,
|
| 112 |
+
"CC-BY-4.0": 30,
|
| 113 |
+
"CC-BY-SA-3.0-PL": 19,
|
| 114 |
+
"CC-BY-SA-4.0": 21
|
| 115 |
+
}
|
| 116 |
+
},
|
| 117 |
+
"ws_ci_hyph": {
|
| 118 |
+
"pattern": "as ws_ci, plus a hyphenated line break and 'wszystkie prawa zastrzeżone'",
|
| 119 |
+
"rows": 137,
|
| 120 |
+
"api_licenses": {
|
| 121 |
+
"CC-BY-3.0-PL": 59,
|
| 122 |
+
"CC-BY-4.0": 31,
|
| 123 |
+
"CC-BY-SA-3.0-PL": 24,
|
| 124 |
+
"CC-BY-SA-4.0": 23
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
},
|
| 129 |
+
"unchanged_vs_pr62": {
|
| 130 |
+
"pr62_parquet_sha256": "6b57b8eec198c9899198a73cea1af372df09b43783a49474a856ccbf83c97da4",
|
| 131 |
+
"rows_compared": 41985,
|
| 132 |
+
"rule": "same ids in the same order, same SHA-256 of every text, every column except `license` equal; digest from src/clean_biblioteka_nauki.py content_digest, taken over PR 62's rows minus the 83 withheld ids",
|
| 133 |
+
"content_sha256": "cc4ad9ce16aaef3c7bc5197743ad58182e3d5011f78cbf53896083e7a8541954"
|
| 134 |
+
},
|
| 135 |
+
"verified": [
|
| 136 |
+
"V: license object (id, iconId, nameEn, urlEn, creativeCommons) of all 42,068 rows fetched via the API on 2026-10-05/06; 42,056 answered 200, 12 answered 404 (re-asked once by hand, 404 again)",
|
| 137 |
+
"V: for each kept row the creativecommons.org URL, English name and icon agree and match the label recovered earlier",
|
| 138 |
+
"V: ids, order, text and all non-license columns equal to Hub PR 62 for the 41,985 shipped rows",
|
| 139 |
+
"V: the 3 Public Domain Mark ids are absent from the shard",
|
| 140 |
+
"V: the contract test asserts that none of the 71 text-based withheld ids is in the shard and that articles_2011995 is labelled CC-BY-SA-4.0"
|
| 141 |
+
],
|
| 142 |
+
"inferred": [
|
| 143 |
+
"I: that the API `license` field states the licence the rights holder granted for the full text in the corpus"
|
| 144 |
+
],
|
| 145 |
+
"not_checked": [
|
| 146 |
+
"Whether the licence field matches the licence printed in each PDF or publisher page; about 120 shipped texts contain 'all rights reserved' although the API says CC",
|
| 147 |
+
"Authors' and publishers' standing to license, and third-party material (figures, quotations) inside CC items",
|
| 148 |
+
"Why 12 records answer 404 now (deleted, withdrawn, or an API change) and why articles_2011995 changed from the earlier CC BY label to CC BY-SA 4.0",
|
| 149 |
+
"Whether the earlier licence recovery was run before a licence change on the platform: its date is not recorded",
|
| 150 |
+
"The text-assembly script of the v0.2.4 build is not in the repository; the text comes from the SpeakLeash redistribution (Hub PR 11) and how it was assembled was not re-verified",
|
| 151 |
+
"Attribution strings were not re-fetched in this change",
|
| 152 |
+
"Reprint / translation flagged rows (5) were not separately reviewed",
|
| 153 |
+
"The text-based withheld classes rest on one reader's pass over about 300 characters of context around regex hits (a CC licence URL or name with NC or ND; permission wording near 'reprint', 'translated', 'za zgodą'); other spellings, other languages and wordings the regexes do not match were not searched"
|
| 154 |
+
]
|
| 155 |
+
}
|
data/biblioteka_nauki/biblioteka_nauki.md
CHANGED
|
@@ -6,29 +6,62 @@ Biblioteka Nauki — Polish open-access scholarly corpus (scientific articles, b
|
|
| 6 |
- **Source (upstream):** https://bibliotekanauki.pl (operated by ICM, University of Warsaw — Centrum Otwartej Nauki)
|
| 7 |
- **Domain:** academic (scientific articles, books, chapters)
|
| 8 |
- **Language:** Polish (pl)
|
| 9 |
-
- **License:** per-document — CC BY 4.0 28,
|
| 10 |
- **Created (range):** per-document publication year, from each item's bibliotekanauki.pl metadata
|
| 11 |
- **Added:** 2026-06-27
|
| 12 |
|
| 13 |
## Licensing — traceable basis
|
| 14 |
-
The
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
| license | documents |
|
| 20 |
-
|---|---:|
|
| 21 |
-
| CC
|
| 22 |
-
| CC
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
The
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
Three items labelled "Domena publiczna" were dropped for v0.2.6 (`src/clean_biblioteka_nauki.py`,
|
| 27 |
polish-dynaword-v2#52): `books_2142716`, `books_2147851`, `articles_2097363` (376,155 tokens).
|
| 28 |
Biblioteka Nauki gives them API licence id 22, the CC Public Domain Mark 1.0, which is a label, not a
|
| 29 |
waiver or a licence. They are original works first published 2019-2022, so the Polish life+70 term has
|
| 30 |
-
not run out, and `books_2147851` itself prints "Copyright by Jerzy Zając 2019".
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
## Attribution
|
| 34 |
Per-document attribution (author · year · title · publisher) was re-fetched 1:1 from
|
|
@@ -36,14 +69,17 @@ bibliotekanauki.pl (43,576 / 43,576 ok) and is carried in the parquet `attributi
|
|
| 36 |
satisfying the CC BY / CC BY-SA attribution requirement that applies to every document here.
|
| 37 |
|
| 38 |
## Provenance
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
## Statistics
|
| 44 |
| documents | characters | tokens (tiktoken proxy) |
|
| 45 |
|---:|---:|---:|
|
| 46 |
-
|
|
| 47 |
|
| 48 |
## Filters applied (build_dynaword.py)
|
| 49 |
Minimal, per Dynaword guidelines (heavy filtering left to downstream use):
|
|
@@ -52,15 +88,21 @@ Minimal, per Dynaword guidelines (heavy filtering left to downstream use):
|
|
| 52 |
- exact cross-source dedup (sha1): **180**
|
| 53 |
- OCR alpha-ratio < 0.70 (OCR source): **400**
|
| 54 |
- licence not an established grant, CC Public Domain Mark (`src/clean_biblioteka_nauki.py`): **3**
|
| 55 |
-
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
|
| 58 |
Llama-3 count is computed at release.
|
| 59 |
|
| 60 |
## Limitations
|
| 61 |
-
- **Mixed license.** Roughly one third of the documents are CC BY-SA 4.0
|
| 62 |
-
per-document
|
| 63 |
-
for those documents.
|
|
|
|
|
|
|
|
|
|
| 64 |
- **OCR / extraction noise.** Text is extracted from publisher PDFs; some layout and hyphenation
|
| 65 |
artefacts remain after the alpha-ratio filter.
|
| 66 |
- **Per-document dates.** `created` is the publication year from upstream metadata; finer-grained
|
|
|
|
| 6 |
- **Source (upstream):** https://bibliotekanauki.pl (operated by ICM, University of Warsaw — Centrum Otwartej Nauki)
|
| 7 |
- **Domain:** academic (scientific articles, books, chapters)
|
| 8 |
- **Language:** Polish (pl)
|
| 9 |
+
- **License:** per-document, with the version the upstream API gives for each record — CC BY (2.0, 3.0, 3.0 PL, 4.0) 28,280 · CC BY-SA (3.0, 3.0 PL, 4.0) 13,705; table below
|
| 10 |
- **Created (range):** per-document publication year, from each item's bibliotekanauki.pl metadata
|
| 11 |
- **Added:** 2026-06-27
|
| 12 |
|
| 13 |
## Licensing — traceable basis
|
| 14 |
+
The upstream collection includes all-rights-reserved items, so a per-item gate is mandatory. Each row's
|
| 15 |
+
licence was read from the bibliotekanauki.pl API (`bibliotekanauki.pl/api/{type}/{id}` → `license`:
|
| 16 |
+
name, URL, icon) on 2026-10-05/06, one request per row of the previous release
|
| 17 |
+
(`data/biblioteka_nauki/recover_license_versions.py`). The API responses are committed as
|
| 18 |
+
`biblioteka_nauki.license-api.json`. The earlier recovery stored only `license.iconId` (`cc-by` /
|
| 19 |
+
`cc-by-sa`), which drops the version, so v0.2.5 labelled every row 4.0 although the API gives 2.0, 3.0,
|
| 20 |
+
3.0 PL and 4.0 (polish-dynaword-v2#57).
|
| 21 |
|
| 22 |
+
| `license` label | documents | API licence (`nameEn`) |
|
| 23 |
+
|---|---:|---|
|
| 24 |
+
| CC-BY-2.0 | 1 | CC BY: Creative Commons Attribution 2.0 Generic |
|
| 25 |
+
| CC-BY-3.0 | 2,413 | CC BY: Creative Commons Attribution 3.0 Unported |
|
| 26 |
+
| CC-BY-3.0-PL | 8,098 | CC BY: Creative Commons Attribution 3.0 PL |
|
| 27 |
+
| CC-BY-4.0 | 17,768 | CC BY: Creative Commons Attribution 4.0 |
|
| 28 |
+
| CC-BY-SA-3.0 | 7 | CC BY-SA: Creative Commons Attribution-ShareAlike 3.0 Unported |
|
| 29 |
+
| CC-BY-SA-3.0-PL | 2,754 | CC BY-SA: Creative Commons Attribution-ShareAlike 3.0 PL |
|
| 30 |
+
| CC-BY-SA-4.0 | 10,944 | CC BY-SA: Creative Commons Attribution-ShareAlike 4.0 |
|
| 31 |
|
| 32 |
+
The label is carried in the parquet `license` column. `src/clean_biblioteka_nauki.py` accepts a row only
|
| 33 |
+
when the API licence is a Creative Commons BY or BY-SA licence of version 2.0 to 4.0 (generic or the
|
| 34 |
+
Polish port), its `creativecommons.org` URL, English name and icon agree, and the kind matches the
|
| 35 |
+
label recovered earlier. Anything else is withheld, not guessed (12 rows the API now answers with
|
| 36 |
+
HTTP 404). `articles_2011995` is the one row whose API licence (CC BY-SA 4.0) differs from the earlier
|
| 37 |
+
recovery (CC BY); it is kept and labelled CC-BY-SA-4.0 (maintainer decision 2026-10-06). Only the
|
| 38 |
+
`license` column differs from the previous release; ids, order and text are unchanged for the 41,985
|
| 39 |
+
rows shipped.
|
| 40 |
|
| 41 |
Three items labelled "Domena publiczna" were dropped for v0.2.6 (`src/clean_biblioteka_nauki.py`,
|
| 42 |
polish-dynaword-v2#52): `books_2142716`, `books_2147851`, `articles_2097363` (376,155 tokens).
|
| 43 |
Biblioteka Nauki gives them API licence id 22, the CC Public Domain Mark 1.0, which is a label, not a
|
| 44 |
waiver or a licence. They are original works first published 2019-2022, so the Polish life+70 term has
|
| 45 |
+
not run out, and `books_2147851` itself prints "Copyright by Jerzy Zając 2019".
|
| 46 |
+
|
| 47 |
+
The API also flags 5 kept rows as a reprint (2) or translation (3) publication; none has `restricted`
|
| 48 |
+
set. The licence check does not look at those flags.
|
| 49 |
+
|
| 50 |
+
## Withheld rows
|
| 51 |
+
83 of the 42,068 rows of the previous release are not shipped. The ids, with one reason per id, are in
|
| 52 |
+
`biblioteka_nauki.stats.json` (`withheld`) and, for the two text-based classes, in
|
| 53 |
+
`src/clean_biblioteka_nauki.py`, whose build fails if a listed id is not reached. The text-based
|
| 54 |
+
classes were decided by the maintainer on 2026-10-06 (polish-dynaword-v2#57, Hub PR 81).
|
| 55 |
+
|
| 56 |
+
| reason class | rows | what it is |
|
| 57 |
+
|---|---:|---|
|
| 58 |
+
| API HTTP 404 | 12 | the API no longer serves the record, so its licence cannot be confirmed; why is not known |
|
| 59 |
+
| text prints a NonCommercial or NoDerivatives licence | 56 | the text itself (front matter, colophon or a licence URL) prints CC BY-NC, BY-NC-SA, BY-NC-ND or BY-ND while the API says CC BY or CC BY-SA: Krytyka Prawa 2019 (21), Journal of Health Sciences 2014 (12), 23 others |
|
| 60 |
+
| text says it is reprinted or translated by permission of a publisher | 15 | "reprinted by permission of ..." on the whole text (Oxford University Press 3, other publishers or journals 12); nothing shows that the permission covers redistribution under CC |
|
| 61 |
+
|
| 62 |
+
Rows are kept when the wording is only a citation, a quoted work's own notice, prose about licence
|
| 63 |
+
types, a permission for a figure or table, or a translation permitted by the author alone. These
|
| 64 |
+
readings are one reader's judgement of about 300 characters of context around each match.
|
| 65 |
|
| 66 |
## Attribution
|
| 67 |
Per-document attribution (author · year · title · publisher) was re-fetched 1:1 from
|
|
|
|
| 69 |
satisfying the CC BY / CC BY-SA attribution requirement that applies to every document here.
|
| 70 |
|
| 71 |
## Provenance
|
| 72 |
+
Text from the SpeakLeash redistribution; licence and attribution recovered per document from the
|
| 73 |
+
Biblioteka Nauki API (Hub PR 11); assembly script not in the repository. Hub PR 11, which added this
|
| 74 |
+
source, says the SpeakLeash blob has no per-document licence and that the Parquet ships ready-built;
|
| 75 |
+
the key is `biblioteka_nauki_pl_corpus`. This release only filters and relabels the shipped Parquet
|
| 76 |
+
(`src/clean_biblioteka_nauki.py`, pinned to the v0.2.5 file by SHA-256); how the text layer was
|
| 77 |
+
assembled is not re-verified here.
|
| 78 |
|
| 79 |
## Statistics
|
| 80 |
| documents | characters | tokens (tiktoken proxy) |
|
| 81 |
|---:|---:|---:|
|
| 82 |
+
| 41,985 | 1,739,004,913 | 669,909,430 |
|
| 83 |
|
| 84 |
## Filters applied (build_dynaword.py)
|
| 85 |
Minimal, per Dynaword guidelines (heavy filtering left to downstream use):
|
|
|
|
| 88 |
- exact cross-source dedup (sha1): **180**
|
| 89 |
- OCR alpha-ratio < 0.70 (OCR source): **400**
|
| 90 |
- licence not an established grant, CC Public Domain Mark (`src/clean_biblioteka_nauki.py`): **3**
|
| 91 |
+
- licence not confirmed by the API as an allowlisted CC BY / BY-SA version, HTTP 404 (`src/clean_biblioteka_nauki.py`): **12**
|
| 92 |
+
- text prints a NonCommercial or NoDerivatives licence (`src/clean_biblioteka_nauki.py`): **56**
|
| 93 |
+
- text says it is reprinted or translated by permission of a publisher (`src/clean_biblioteka_nauki.py`): **15**
|
| 94 |
+
- read 43,576 → kept 41,985
|
| 95 |
|
| 96 |
Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
|
| 97 |
Llama-3 count is computed at release.
|
| 98 |
|
| 99 |
## Limitations
|
| 100 |
+
- **Mixed license.** Roughly one third of the documents are CC BY-SA (3.0, 3.0 PL or 4.0; share-alike);
|
| 101 |
+
the exact per-document licence and version is in the `license` column. Downstream redistribution must
|
| 102 |
+
respect share-alike for those documents, under their own version.
|
| 103 |
+
- **Licence is the API's word.** About 120 texts contain the phrase "all rights reserved" although
|
| 104 |
+
their API licence is CC BY or CC BY-SA. The rows are kept; the conflict between a footer in the
|
| 105 |
+
extracted text and the platform's licence field is not resolved here.
|
| 106 |
- **OCR / extraction noise.** Text is extracted from publisher PDFs; some layout and hyphenation
|
| 107 |
artefacts remain after the alpha-ratio filter.
|
| 108 |
- **Per-document dates.** `created` is the publication year from upstream metadata; finer-grained
|
data/biblioteka_nauki/biblioteka_nauki.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d829f835c20ec5ed578552b9adcea6a0de457404066734cec858cc7b57bfd768
|
| 3 |
+
size 1070808754
|
data/biblioteka_nauki/biblioteka_nauki.stats.json
CHANGED
|
@@ -1,18 +1,112 @@
|
|
| 1 |
{
|
| 2 |
"read": 43576,
|
| 3 |
-
"kept":
|
| 4 |
"drop_short": 0,
|
| 5 |
"drop_lang": 925,
|
| 6 |
"drop_dup": 180,
|
| 7 |
"drop_ocr": 400,
|
| 8 |
-
"chars":
|
| 9 |
-
"tokens":
|
| 10 |
"secs": 484.1,
|
| 11 |
-
"license": "CC-BY-4.0 / CC-BY-SA-4.0",
|
| 12 |
"drop_rights": 3,
|
| 13 |
"licenses": {
|
| 14 |
-
"
|
| 15 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
},
|
| 17 |
-
"input_sha256": "cc93cdd5ca3e6576a1da0aa294df1308e879b8516ac30911289e430c69a07b26"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"read": 43576,
|
| 3 |
+
"kept": 41985,
|
| 4 |
"drop_short": 0,
|
| 5 |
"drop_lang": 925,
|
| 6 |
"drop_dup": 180,
|
| 7 |
"drop_ocr": 400,
|
| 8 |
+
"chars": 1739004913,
|
| 9 |
+
"tokens": 669909430,
|
| 10 |
"secs": 484.1,
|
| 11 |
+
"license": "CC-BY-2.0 / CC-BY-3.0 / CC-BY-3.0-PL / CC-BY-4.0 / CC-BY-SA-3.0 / CC-BY-SA-3.0-PL / CC-BY-SA-4.0",
|
| 12 |
"drop_rights": 3,
|
| 13 |
"licenses": {
|
| 14 |
+
"CC-BY-2.0": 1,
|
| 15 |
+
"CC-BY-3.0": 2413,
|
| 16 |
+
"CC-BY-3.0-PL": 8098,
|
| 17 |
+
"CC-BY-4.0": 17768,
|
| 18 |
+
"CC-BY-SA-3.0": 7,
|
| 19 |
+
"CC-BY-SA-3.0-PL": 2754,
|
| 20 |
+
"CC-BY-SA-4.0": 10944
|
| 21 |
},
|
| 22 |
+
"input_sha256": "cc93cdd5ca3e6576a1da0aa294df1308e879b8516ac30911289e430c69a07b26",
|
| 23 |
+
"drop_license_unverified": 12,
|
| 24 |
+
"withheld": {
|
| 25 |
+
"biblioteka_nauki_articles_1032116": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 26 |
+
"biblioteka_nauki_articles_1032173": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 27 |
+
"biblioteka_nauki_articles_1032215": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 28 |
+
"biblioteka_nauki_articles_1032225": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 29 |
+
"biblioteka_nauki_articles_1032276": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 30 |
+
"biblioteka_nauki_articles_1032302": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 31 |
+
"biblioteka_nauki_articles_1032351": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 32 |
+
"biblioteka_nauki_articles_1032417": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 33 |
+
"biblioteka_nauki_articles_1032461": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 34 |
+
"biblioteka_nauki_articles_1032495": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 35 |
+
"biblioteka_nauki_articles_1032501": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 36 |
+
"biblioteka_nauki_articles_1032509": "Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence",
|
| 37 |
+
"biblioteka_nauki_articles_1191739": "the text prints CC BY-NC-SA 4.0",
|
| 38 |
+
"biblioteka_nauki_articles_1621507": "translated by permission of the author and the publisher (Darton, Longman and Todd)",
|
| 39 |
+
"biblioteka_nauki_articles_1622259": "reprinted by permission of the University of Arkansas Press, via The Permissions Company",
|
| 40 |
+
"biblioteka_nauki_articles_1622298": "Polish translation published by permission of the author and Oxford University Press; further reproduction needs the publisher's consent",
|
| 41 |
+
"biblioteka_nauki_articles_1917546": "translated and published by permission of the author and of the journal's publisher (Nova et Vetera)",
|
| 42 |
+
"biblioteka_nauki_articles_1963167": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 43 |
+
"biblioteka_nauki_articles_1963170": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 44 |
+
"biblioteka_nauki_articles_1963181": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 45 |
+
"biblioteka_nauki_articles_1963183": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 46 |
+
"biblioteka_nauki_articles_1963187": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 47 |
+
"biblioteka_nauki_articles_1963190": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 48 |
+
"biblioteka_nauki_articles_1963193": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 49 |
+
"biblioteka_nauki_articles_1963195": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 50 |
+
"biblioteka_nauki_articles_1964252": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 51 |
+
"biblioteka_nauki_articles_1964253": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 52 |
+
"biblioteka_nauki_articles_1964255": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 53 |
+
"biblioteka_nauki_articles_1964257": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 54 |
+
"biblioteka_nauki_articles_1966144": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 55 |
+
"biblioteka_nauki_articles_1991243": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 56 |
+
"biblioteka_nauki_articles_1992050": "translated and published by permission of the author and of the journal's publisher (Nova et Vetera)",
|
| 57 |
+
"biblioteka_nauki_articles_2040728": "the text prints CC BY-NC-ND 4.0",
|
| 58 |
+
"biblioteka_nauki_articles_2040731": "the text prints CC BY-NC-ND 4.0",
|
| 59 |
+
"biblioteka_nauki_articles_2057193": "the text prints a CC-BY-NC-ND 4.0 licence URL",
|
| 60 |
+
"biblioteka_nauki_articles_2057203": "the text prints a CC-BY-NC-ND 4.0 licence URL",
|
| 61 |
+
"biblioteka_nauki_articles_2082818": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 62 |
+
"biblioteka_nauki_articles_2082821": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 63 |
+
"biblioteka_nauki_articles_2082824": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 64 |
+
"biblioteka_nauki_articles_2082827": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 65 |
+
"biblioteka_nauki_articles_2082829": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 66 |
+
"biblioteka_nauki_articles_2082837": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 67 |
+
"biblioteka_nauki_articles_2082857": "Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0",
|
| 68 |
+
"biblioteka_nauki_articles_2089605": "the text prints CC BY-NC-ND 4.0",
|
| 69 |
+
"biblioteka_nauki_articles_2089606": "the text prints CC BY-NC-ND 4.0",
|
| 70 |
+
"biblioteka_nauki_articles_2089607": "the text prints CC BY-NC-ND 4.0",
|
| 71 |
+
"biblioteka_nauki_articles_2089616": "the text prints CC BY-NC-ND 4.0",
|
| 72 |
+
"biblioteka_nauki_articles_486876": "the issue colophon prints CC BY-NC-ND 4.0",
|
| 73 |
+
"biblioteka_nauki_articles_487021": "the text prints CC BY-NC-ND 4.0",
|
| 74 |
+
"biblioteka_nauki_articles_512191": "API: http404",
|
| 75 |
+
"biblioteka_nauki_articles_520085": "the text prints CC BY-NC-ND 2.0 and says it is translated by permission of the author",
|
| 76 |
+
"biblioteka_nauki_articles_604103": "API: http404",
|
| 77 |
+
"biblioteka_nauki_articles_605338": "API: http404",
|
| 78 |
+
"biblioteka_nauki_articles_623064": "reprinted by permission of Sage",
|
| 79 |
+
"biblioteka_nauki_articles_623121": "translated and reproduced with permission of International Affairs",
|
| 80 |
+
"biblioteka_nauki_articles_630597": "reprinted with the editors' permission",
|
| 81 |
+
"biblioteka_nauki_articles_634914": "translated and reprinted by permission of Oxford University Press (for the Oral History Association); limited-rights notice with a licence number",
|
| 82 |
+
"biblioteka_nauki_articles_634916": "translated and reprinted by permission of Oxford University Press (for the Oral History Association); limited-rights notice with a licence number",
|
| 83 |
+
"biblioteka_nauki_articles_634918": "reprinted from the Oral History Review by permission of the Oral History Association",
|
| 84 |
+
"biblioteka_nauki_articles_643727": "\"Reprinted by Permission of SAGE Publications\"",
|
| 85 |
+
"biblioteka_nauki_articles_643809": "\"Reprinted by Permission of SAGE Publications\"",
|
| 86 |
+
"biblioteka_nauki_articles_643825": "reprinted by permission of Indiana University Press",
|
| 87 |
+
"biblioteka_nauki_articles_694180": "reprinted by permission of Westview Press",
|
| 88 |
+
"biblioteka_nauki_articles_694689": "API: http404",
|
| 89 |
+
"biblioteka_nauki_articles_699376": "API: http404",
|
| 90 |
+
"biblioteka_nauki_articles_699392": "API: http404",
|
| 91 |
+
"biblioteka_nauki_articles_699396": "API: http404",
|
| 92 |
+
"biblioteka_nauki_articles_699422": "API: http404",
|
| 93 |
+
"biblioteka_nauki_articles_699424": "API: http404",
|
| 94 |
+
"biblioteka_nauki_articles_699432": "API: http404",
|
| 95 |
+
"biblioteka_nauki_articles_699440": "API: http404",
|
| 96 |
+
"biblioteka_nauki_articles_699442": "API: http404",
|
| 97 |
+
"biblioteka_nauki_books_1076493": "the colophon prints CC BY-NC-ND 3.0 PL",
|
| 98 |
+
"biblioteka_nauki_books_1191609": "the colophon prints CC BY-NC-ND 3.0 PL",
|
| 99 |
+
"biblioteka_nauki_books_1377755": "the colophon prints CC BY-NC-ND 3.0 PL",
|
| 100 |
+
"biblioteka_nauki_books_1396563": "the front page prints CC BY-NC-SA 4.0 (its colophon says CC BY-SA 4.0)",
|
| 101 |
+
"biblioteka_nauki_books_1396571": "the colophon prints CC BY-NC 3.0 PL",
|
| 102 |
+
"biblioteka_nauki_books_1409913": "the colophon prints CC BY-ND 3.0 PL",
|
| 103 |
+
"biblioteka_nauki_books_1788278": "the colophon prints CC BY-NC 3.0 PL; the text and the attribution field name different works",
|
| 104 |
+
"biblioteka_nauki_books_2010681": "the colophon prints a NonCommercial licence, contradicting its own CC BY-SA 4.0 abbreviation",
|
| 105 |
+
"biblioteka_nauki_books_2028459": "the text prints CC BY-NC-SA 4.0",
|
| 106 |
+
"biblioteka_nauki_books_2143725": "the text prints CC BY-NC 3.0 PL (its foreword says CC BY)",
|
| 107 |
+
"biblioteka_nauki_books_2159317": "the text prints CC BY-NC-SA 4.0"
|
| 108 |
+
},
|
| 109 |
+
"content_sha256": "cc4ad9ce16aaef3c7bc5197743ad58182e3d5011f78cbf53896083e7a8541954",
|
| 110 |
+
"drop_text_nc_nd": 56,
|
| 111 |
+
"drop_text_reprint": 15
|
| 112 |
}
|
data/biblioteka_nauki/recover_license_versions.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Re-fetch the licence name, URL and version of every shipped Biblioteka Nauki row.
|
| 3 |
+
|
| 4 |
+
recover_licenses.py kept only `license.iconId` (cc-by / cc-by-sa), which drops the licence version
|
| 5 |
+
(polish-dynaword-v2#57). This asks `GET bibliotekanauki.pl/api/{type}/{id}` once per row of the
|
| 6 |
+
shipped Parquet and stores the API's own `license` object. It judges nothing: the allowlist and the
|
| 7 |
+
fail-closed handling live in src/clean_biblioteka_nauki.py.
|
| 8 |
+
|
| 9 |
+
Polite by construction: one global request clock (`--interval`), a few workers, back-off on
|
| 10 |
+
429/5xx and connection errors (Retry-After honoured), and a circuit breaker. The run stops, and
|
| 11 |
+
exits 2, on a 403, on a 200 that is not the JSON record (an interstitial or CAPTCHA page), or after
|
| 12 |
+
`--max-failures` consecutive requests that exhausted their retries. It never works around a block.
|
| 13 |
+
The cache is append-only JSONL, so a stopped run resumes where it left off.
|
| 14 |
+
|
| 15 |
+
python3 data/biblioteka_nauki/recover_license_versions.py fetch --cache CACHE.jsonl --parquet SHARD
|
| 16 |
+
python3 data/biblioteka_nauki/recover_license_versions.py export --cache CACHE.jsonl --parquet SHARD
|
| 17 |
+
|
| 18 |
+
The committed sidecar covers the 42,068 rows of the shard before the 13 unverifiable rows were withheld
|
| 19 |
+
(Hub PR 62, SHA-256 6b57b8eec198c9899198a73cea1af372df09b43783a49474a856ccbf83c97da4). Pass that file as
|
| 20 |
+
SHARD to reproduce it; the default, the shipped shard, no longer has those 13 rows.
|
| 21 |
+
"""
|
| 22 |
+
from __future__ import annotations
|
| 23 |
+
|
| 24 |
+
import argparse
|
| 25 |
+
import json
|
| 26 |
+
import os
|
| 27 |
+
import random
|
| 28 |
+
import re
|
| 29 |
+
import sys
|
| 30 |
+
import threading
|
| 31 |
+
import time
|
| 32 |
+
from collections import Counter
|
| 33 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 34 |
+
from datetime import datetime, timezone
|
| 35 |
+
from pathlib import Path
|
| 36 |
+
|
| 37 |
+
import pyarrow.parquet as pq
|
| 38 |
+
import requests
|
| 39 |
+
|
| 40 |
+
SOURCE = "biblioteka_nauki"
|
| 41 |
+
HERE = Path(__file__).resolve().parent
|
| 42 |
+
PARQUET = HERE / f"{SOURCE}.parquet"
|
| 43 |
+
SIDECAR = HERE / f"{SOURCE}.license-api.json"
|
| 44 |
+
API = "https://bibliotekanauki.pl/api/{type}/{id}"
|
| 45 |
+
USER_AGENT = "polish-dynaword-rights-recheck/1.0 (+https://huggingface.co/datasets/SlayerLab/polish-dynaword)"
|
| 46 |
+
ROW_ID = re.compile(rf"^{SOURCE}_(articles|books|chapters)_(\d+)$")
|
| 47 |
+
FINAL = {"ok", "http404", "http410", "id_mismatch"} # a restart does not ask again
|
| 48 |
+
FLAGS = ("restricted", "reprintPublication", "translationPublication")
|
| 49 |
+
LICENSE_FIELDS = ("id", "iconId", "nameEn", "urlEn", "creativeCommons")
|
| 50 |
+
MAX_RETRY = 6
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class Blocked(Exception):
|
| 54 |
+
"""The host refused us or answered with something other than the JSON record. Stop and report."""
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def parse_row_id(row_id: str) -> tuple[str, int]:
|
| 58 |
+
match = ROW_ID.match(row_id)
|
| 59 |
+
if not match:
|
| 60 |
+
raise ValueError(f"not a {SOURCE} row id: {row_id!r}")
|
| 61 |
+
return match.group(1), int(match.group(2))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class Clock:
|
| 65 |
+
"""Hands out request slots at least `interval` seconds apart across all threads."""
|
| 66 |
+
|
| 67 |
+
def __init__(self, interval: float):
|
| 68 |
+
self.interval, self._next, self._lock = interval, 0.0, threading.Lock()
|
| 69 |
+
|
| 70 |
+
def wait(self) -> None:
|
| 71 |
+
with self._lock:
|
| 72 |
+
now = time.monotonic()
|
| 73 |
+
slot = max(now, self._next)
|
| 74 |
+
self._next = slot + self.interval
|
| 75 |
+
time.sleep(max(0.0, slot - now))
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def fetch_one(session, clock: Clock, row_id: str, sleep=time.sleep) -> dict | None:
|
| 79 |
+
"""One cache line for `row_id`, or None when retries ran out (not final, asked again on restart)."""
|
| 80 |
+
typ, num = parse_row_id(row_id)
|
| 81 |
+
for attempt in range(MAX_RETRY):
|
| 82 |
+
clock.wait()
|
| 83 |
+
try:
|
| 84 |
+
resp = session.get(API.format(type=typ, id=num), timeout=30)
|
| 85 |
+
except requests.RequestException:
|
| 86 |
+
sleep(min(2 ** attempt, 60) + random.random())
|
| 87 |
+
continue
|
| 88 |
+
if resp.status_code in (404, 410):
|
| 89 |
+
return {"id": row_id, "status": f"http{resp.status_code}", "license": None, "flags": []}
|
| 90 |
+
if resp.status_code == 403:
|
| 91 |
+
raise Blocked(f"HTTP 403 on {row_id}")
|
| 92 |
+
if resp.status_code == 429 or resp.status_code >= 500:
|
| 93 |
+
retry_after = resp.headers.get("Retry-After", "")
|
| 94 |
+
sleep(float(retry_after) if retry_after.isdigit() else min(2 ** attempt, 60) + random.random())
|
| 95 |
+
continue
|
| 96 |
+
if resp.status_code != 200:
|
| 97 |
+
raise Blocked(f"HTTP {resp.status_code} on {row_id}")
|
| 98 |
+
try:
|
| 99 |
+
record = resp.json()
|
| 100 |
+
except ValueError:
|
| 101 |
+
raise Blocked(f"HTTP 200 but not JSON on {row_id}: {resp.text[:80]!r}") from None
|
| 102 |
+
if not isinstance(record, dict) or "license" not in record:
|
| 103 |
+
raise Blocked(f"HTTP 200 but no `license` key on {row_id}")
|
| 104 |
+
lic = record["license"]
|
| 105 |
+
return {
|
| 106 |
+
"id": row_id,
|
| 107 |
+
"status": "ok" if record.get("id") == num else "id_mismatch",
|
| 108 |
+
"api_id": record.get("id"),
|
| 109 |
+
"license": {k: lic.get(k) for k in LICENSE_FIELDS} if isinstance(lic, dict) else None,
|
| 110 |
+
"flags": [k for k in FLAGS if record.get(k)],
|
| 111 |
+
"fetched": datetime.now(timezone.utc).strftime("%Y-%m-%d"),
|
| 112 |
+
}
|
| 113 |
+
return None
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def read_cache(path: Path) -> dict[str, dict]:
|
| 117 |
+
cache: dict[str, dict] = {}
|
| 118 |
+
if path.exists():
|
| 119 |
+
for line in path.read_text(encoding="utf-8").splitlines():
|
| 120 |
+
if line.strip():
|
| 121 |
+
row = json.loads(line)
|
| 122 |
+
cache[row["id"]] = row
|
| 123 |
+
return cache
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def fetch(args) -> int:
|
| 127 |
+
ids = pq.read_table(args.parquet, columns=["id"]).column("id").to_pylist()
|
| 128 |
+
cache = read_cache(args.cache)
|
| 129 |
+
pending = [i for i in ids if cache.get(i, {}).get("status") not in FINAL]
|
| 130 |
+
todo = pending[: args.limit]
|
| 131 |
+
print(f"rows={len(ids)} cached={len(ids) - len(pending)} todo={len(todo)} "
|
| 132 |
+
f"workers={args.workers} interval={args.interval}s", flush=True)
|
| 133 |
+
session_local, clock, lock = threading.local(), Clock(args.interval), threading.Lock()
|
| 134 |
+
state = {"done": 0, "failures": 0, "stop": None}
|
| 135 |
+
counts: Counter = Counter()
|
| 136 |
+
started = time.time()
|
| 137 |
+
out = args.cache.open("a", encoding="utf-8")
|
| 138 |
+
|
| 139 |
+
def work(row_id: str) -> None:
|
| 140 |
+
if state["stop"]:
|
| 141 |
+
return
|
| 142 |
+
if not hasattr(session_local, "s"):
|
| 143 |
+
session_local.s = requests.Session()
|
| 144 |
+
session_local.s.headers.update({"User-Agent": USER_AGENT, "Accept": "application/json"})
|
| 145 |
+
try:
|
| 146 |
+
line = fetch_one(session_local.s, clock, row_id)
|
| 147 |
+
except Blocked as exc:
|
| 148 |
+
state["stop"] = str(exc)
|
| 149 |
+
return
|
| 150 |
+
with lock:
|
| 151 |
+
if line is None:
|
| 152 |
+
state["failures"] += 1
|
| 153 |
+
if state["failures"] >= args.max_failures:
|
| 154 |
+
state["stop"] = f"{state['failures']} consecutive requests exhausted their retries"
|
| 155 |
+
return
|
| 156 |
+
state["failures"] = 0
|
| 157 |
+
out.write(json.dumps(line, ensure_ascii=False) + "\n")
|
| 158 |
+
counts[line["status"]] += 1
|
| 159 |
+
state["done"] += 1
|
| 160 |
+
if state["done"] % 500 == 0:
|
| 161 |
+
out.flush()
|
| 162 |
+
rate = state["done"] / (time.time() - started)
|
| 163 |
+
print(f"{state['done']}/{len(todo)} {rate:.1f}/s ETA {(len(todo) - state['done']) / rate / 60:.0f}m "
|
| 164 |
+
f"{dict(counts)}", flush=True)
|
| 165 |
+
|
| 166 |
+
try:
|
| 167 |
+
with ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 168 |
+
list(pool.map(work, todo))
|
| 169 |
+
finally:
|
| 170 |
+
out.close()
|
| 171 |
+
print(f"fetched {state['done']} of {len(todo)} {dict(counts)}", flush=True)
|
| 172 |
+
if state["stop"]:
|
| 173 |
+
print(f"STOPPED: {state['stop']}. Not retrying; report to the maintainer. Rerun resumes.", file=sys.stderr)
|
| 174 |
+
return 2
|
| 175 |
+
return 0
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def export(args) -> int:
|
| 179 |
+
ids = pq.read_table(args.parquet, columns=["id"]).column("id").to_pylist()
|
| 180 |
+
cache = read_cache(args.cache)
|
| 181 |
+
if missing := [i for i in ids if cache.get(i, {}).get("status") not in FINAL]:
|
| 182 |
+
raise SystemExit(f"{len(missing)} rows not fetched yet, e.g. {missing[:3]}; run `fetch` first")
|
| 183 |
+
licenses: dict[str, dict] = {}
|
| 184 |
+
rows: dict[str, int] = {}
|
| 185 |
+
unresolved: dict[str, str] = {}
|
| 186 |
+
flagged: dict[str, list[str]] = {}
|
| 187 |
+
for row_id in ids:
|
| 188 |
+
line = cache[row_id]
|
| 189 |
+
if line["flags"]:
|
| 190 |
+
flagged[row_id] = line["flags"]
|
| 191 |
+
lic = line["license"]
|
| 192 |
+
if line["status"] != "ok":
|
| 193 |
+
unresolved[row_id] = line["status"]
|
| 194 |
+
elif not lic or lic.get("id") is None:
|
| 195 |
+
unresolved[row_id] = "no_license"
|
| 196 |
+
else:
|
| 197 |
+
key = str(lic["id"])
|
| 198 |
+
if licenses.setdefault(key, lic) != lic:
|
| 199 |
+
raise SystemExit(f"API licence id {key} came back with two different bodies: {licenses[key]} vs {lic}")
|
| 200 |
+
rows[row_id] = lic["id"]
|
| 201 |
+
dates = sorted({line["fetched"] for line in cache.values() if line.get("fetched")})
|
| 202 |
+
sidecar = {
|
| 203 |
+
"api": API,
|
| 204 |
+
"retrieved": dates[0] if len(dates) == 1 else f"{dates[0]}..{dates[-1]}",
|
| 205 |
+
"rows_total": len(ids),
|
| 206 |
+
"licenses": dict(sorted(licenses.items(), key=lambda kv: int(kv[0]))),
|
| 207 |
+
"unresolved": unresolved,
|
| 208 |
+
"flagged": flagged,
|
| 209 |
+
"rows": rows,
|
| 210 |
+
}
|
| 211 |
+
tmp = args.out.with_name(args.out.name + ".tmp")
|
| 212 |
+
tmp.write_text(json.dumps(sidecar, ensure_ascii=False, separators=(",", ":")) + "\n", encoding="utf-8")
|
| 213 |
+
os.replace(tmp, args.out)
|
| 214 |
+
print(f"{args.out}: {len(rows)} rows, {len(licenses)} licences, {len(unresolved)} unresolved, {len(flagged)} flagged")
|
| 215 |
+
return 0
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def main() -> int:
|
| 219 |
+
parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
| 220 |
+
sub = parser.add_subparsers(dest="cmd", required=True)
|
| 221 |
+
for name, fn in (("fetch", fetch), ("export", export)):
|
| 222 |
+
p = sub.add_parser(name)
|
| 223 |
+
p.add_argument("--parquet", type=Path, default=PARQUET)
|
| 224 |
+
p.add_argument("--cache", type=Path, required=True)
|
| 225 |
+
p.set_defaults(fn=fn)
|
| 226 |
+
if name == "fetch":
|
| 227 |
+
p.add_argument("--workers", type=int, default=3)
|
| 228 |
+
p.add_argument("--interval", type=float, default=0.15, help="seconds between request starts, all workers")
|
| 229 |
+
p.add_argument("--max-failures", type=int, default=10)
|
| 230 |
+
p.add_argument("--limit", type=int, default=None, help="fetch at most this many rows (smoke test)")
|
| 231 |
+
else:
|
| 232 |
+
p.add_argument("--out", type=Path, default=SIDECAR)
|
| 233 |
+
args = parser.parse_args()
|
| 234 |
+
return args.fn(args)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
if __name__ == "__main__":
|
| 238 |
+
sys.exit(main())
|
src/clean_biblioteka_nauki.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
-
"""Drop Biblioteka Nauki rows whose licence is not an established grant.
|
| 3 |
|
| 4 |
Kept: `cc-by`, `cc-by-sa` and `cc0` (none in v0.2.5), the per-item Creative Commons licence read from
|
| 5 |
bibliotekanauki.pl/api/{type}/{id} (`license.iconId`) by data/biblioteka_nauki/recover_licenses.py.
|
|
@@ -9,6 +9,24 @@ a waiver or a licence, and the 3 tagged items are original works first published
|
|
| 9 |
the Polish life+70 term cannot have run out (polish-dynaword-v2#52,
|
| 10 |
artifacts/rights_audit_2026-10/reports/academic.md). Any other licence value fails the run.
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
The v0.2.4 assembly script (build_parquet.py) was never committed, so this filters the shipped
|
| 13 |
v0.2.5 Parquet, pinned by SHA-256, and updates the stats file in place. Rerun:
|
| 14 |
git checkout v0.2.5 -- data/biblioteka_nauki/biblioteka_nauki.parquet
|
|
@@ -20,6 +38,7 @@ import argparse
|
|
| 20 |
import hashlib
|
| 21 |
import json
|
| 22 |
import os
|
|
|
|
| 23 |
from collections import Counter
|
| 24 |
from pathlib import Path
|
| 25 |
|
|
@@ -32,6 +51,58 @@ DATA = Path(__file__).resolve().parents[1] / "data" / SOURCE
|
|
| 32 |
INPUT_SHA256 = "cc93cdd5ca3e6576a1da0aa294df1308e879b8516ac30911289e430c69a07b26" # v0.2.5
|
| 33 |
KEEP = {"cc-by", "cc-by-sa", "cc0"} # = CLEAN in data/biblioteka_nauki/recover_attribution.py
|
| 34 |
DROP = {"public-domain"} # CC Public Domain Mark: a label, not a grant (see docstring)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
def filter_table(table: pa.Table) -> pa.Table:
|
|
@@ -41,30 +112,119 @@ def filter_table(table: pa.Table) -> pa.Table:
|
|
| 41 |
return table.filter(pc.is_in(table.column("license"), pa.array(sorted(KEEP))))
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def build(input_path: Path, out_dir: Path) -> dict:
|
| 45 |
with input_path.open("rb") as stream:
|
| 46 |
if hashlib.file_digest(stream, "sha256").hexdigest() != INPUT_SHA256:
|
| 47 |
raise SystemExit(f"{input_path} is not the v0.2.5 Parquet; restore it with "
|
| 48 |
f"`git checkout v0.2.5 -- data/{SOURCE}/{SOURCE}.parquet`")
|
| 49 |
table = pq.read_table(input_path)
|
| 50 |
-
|
| 51 |
-
dropped = sorted(set(table.column("id").to_pylist()) - set(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
stats_path = out_dir / f"{SOURCE}.stats.json"
|
| 54 |
stats = json.loads(stats_path.read_text(encoding="utf-8")) # keeps build_dynaword's read/drop_* counts
|
| 55 |
stats.update(
|
| 56 |
kept=kept.num_rows,
|
| 57 |
-
drop_rights=table.num_rows -
|
|
|
|
|
|
|
|
|
|
| 58 |
chars=pc.sum(pc.utf8_length(kept.column("text"))).as_py(),
|
| 59 |
tokens=pc.sum(kept.column("token_count")).as_py(),
|
|
|
|
| 60 |
licenses=dict(sorted(Counter(kept.column("license").to_pylist()).items())),
|
|
|
|
| 61 |
input_sha256=INPUT_SHA256,
|
| 62 |
)
|
| 63 |
parquet_tmp = out_dir / f"{SOURCE}.parquet.tmp"
|
| 64 |
stats_tmp = out_dir / f"{SOURCE}.stats.json.tmp"
|
| 65 |
pq.write_table(kept, parquet_tmp)
|
| 66 |
-
stats_tmp.write_text(json.dumps(stats, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
| 67 |
os.replace(parquet_tmp, out_dir / f"{SOURCE}.parquet")
|
|
|
|
|
|
|
| 68 |
os.replace(stats_tmp, stats_path)
|
| 69 |
return {**stats, "dropped_ids": dropped}
|
| 70 |
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
"""Drop Biblioteka Nauki rows whose licence is not an established grant, and label the rest per record.
|
| 3 |
|
| 4 |
Kept: `cc-by`, `cc-by-sa` and `cc0` (none in v0.2.5), the per-item Creative Commons licence read from
|
| 5 |
bibliotekanauki.pl/api/{type}/{id} (`license.iconId`) by data/biblioteka_nauki/recover_licenses.py.
|
|
|
|
| 9 |
the Polish life+70 term cannot have run out (polish-dynaword-v2#52,
|
| 10 |
artifacts/rights_audit_2026-10/reports/academic.md). Any other licence value fails the run.
|
| 11 |
|
| 12 |
+
Relabel (polish-dynaword-v2#57): `iconId` drops the licence version, so v0.2.5 and the first v0.2.6
|
| 13 |
+
build said cc-by / cc-by-sa while the API gives 2.0, 3.0, 3.0 PL and 4.0. The `license` column now
|
| 14 |
+
carries the API's own licence, e.g. `CC-BY-3.0-PL`, read from the sidecar
|
| 15 |
+
data/biblioteka_nauki/biblioteka_nauki.license-api.json (written by recover_license_versions.py from one
|
| 16 |
+
API call per row). Only CC BY / CC BY-SA 2.0-4.0, generic or Poland port, whose URL, name and icon agree
|
| 17 |
+
with each other and with the stored label are labelled. A row the API did not resolve, or whose licence is
|
| 18 |
+
anything else, is withheld (dropped and listed in stats `withheld`), never kept under a guessed label.
|
| 19 |
+
No other column changes.
|
| 20 |
+
|
| 21 |
+
Maintainer decisions of 2026-10-06 (polish-dynaword-v2#57, Hub PR 81), applied by id, one reason per id:
|
| 22 |
+
API_OVERRIDES `articles_2011995` is labelled with the API's current CC BY-SA 4.0 although the earlier
|
| 23 |
+
recovery stored cc-by; the row is kept.
|
| 24 |
+
TEXT_NC_ND 56 rows whose own text prints a NonCommercial and/or NoDerivatives licence while the API
|
| 25 |
+
says CC BY or CC BY-SA. Withheld.
|
| 26 |
+
TEXT_REPRINT 15 rows whose text says it is a translation or reprint published by a publisher's
|
| 27 |
+
permission (Oxford University Press and 12 other publishers or journals). Withheld.
|
| 28 |
+
The build fails if a listed id is not reached, i.e. not among the rows that would otherwise be kept.
|
| 29 |
+
|
| 30 |
The v0.2.4 assembly script (build_parquet.py) was never committed, so this filters the shipped
|
| 31 |
v0.2.5 Parquet, pinned by SHA-256, and updates the stats file in place. Rerun:
|
| 32 |
git checkout v0.2.5 -- data/biblioteka_nauki/biblioteka_nauki.parquet
|
|
|
|
| 38 |
import hashlib
|
| 39 |
import json
|
| 40 |
import os
|
| 41 |
+
import re
|
| 42 |
from collections import Counter
|
| 43 |
from pathlib import Path
|
| 44 |
|
|
|
|
| 51 |
INPUT_SHA256 = "cc93cdd5ca3e6576a1da0aa294df1308e879b8516ac30911289e430c69a07b26" # v0.2.5
|
| 52 |
KEEP = {"cc-by", "cc-by-sa", "cc0"} # = CLEAN in data/biblioteka_nauki/recover_attribution.py
|
| 53 |
DROP = {"public-domain"} # CC Public Domain Mark: a label, not a grant (see docstring)
|
| 54 |
+
SIDECAR = DATA / f"{SOURCE}.license-api.json"
|
| 55 |
+
# creativecommons.org/licenses/by/3.0/pl/legalcode, .../by-sa/4.0/legalcode.en, .../by/2.0/legalcode
|
| 56 |
+
LICENSE_URL = re.compile(r"^https://creativecommons\.org/licenses/(by|by-sa)/(\d\.\d)/(?:([a-z]{2})/)?legalcode(?:\.[a-z]{2})?$")
|
| 57 |
+
VERSIONS = {"2.0", "2.5", "3.0", "4.0"}
|
| 58 |
+
JURISDICTIONS = {None, "pl"} # None = generic / Unported
|
| 59 |
+
API_OVERRIDES = {f"{SOURCE}_articles_2011995": "CC-BY-SA-4.0"} # {id: label the API's own licence must give}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _group(kind: str, numbers: str, reason: str) -> dict[str, str]:
|
| 63 |
+
return {f"{SOURCE}_{kind}_{number}": reason for number in numbers.split()}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# Printed licence read in the text (front or back matter) against a CC BY / CC BY-SA API label.
|
| 67 |
+
TEXT_NC_ND = {
|
| 68 |
+
**_group("articles", "1966144 2082824 1963195 1964252 1963167 1963170 1963181 1963183 1963187 1964253 1964257 "
|
| 69 |
+
"2082818 2082821 2082837 1963190 1991243 2082827 2082829 1964255 2082857 1963193",
|
| 70 |
+
"Krytyka Prawa 2019: the text prints CC BY-NC-ND 3.0"),
|
| 71 |
+
**_group("articles", "1032417 1032173 1032302 1032215 1032351 1032276 1032116 1032495 1032509 1032225 1032501 1032461",
|
| 72 |
+
"Journal of Health Sciences 2014 (Radom): the text prints the Creative Commons Attribution Noncommercial licence"),
|
| 73 |
+
**_group("articles", "2040728 2040731 2089607 2089605 2089606 2089616", "the text prints CC BY-NC-ND 4.0"),
|
| 74 |
+
**_group("articles", "2057203 2057193", "the text prints a CC-BY-NC-ND 4.0 licence URL"),
|
| 75 |
+
**_group("articles", "486876", "the issue colophon prints CC BY-NC-ND 4.0"),
|
| 76 |
+
**_group("articles", "520085", "the text prints CC BY-NC-ND 2.0 and says it is translated by permission of the author"),
|
| 77 |
+
**_group("articles", "1191739", "the text prints CC BY-NC-SA 4.0"),
|
| 78 |
+
**_group("articles", "487021", "the text prints CC BY-NC-ND 4.0"),
|
| 79 |
+
**_group("books", "1076493 1377755 1191609", "the colophon prints CC BY-NC-ND 3.0 PL"),
|
| 80 |
+
**_group("books", "1788278", "the colophon prints CC BY-NC 3.0 PL; the text and the attribution field name different works"),
|
| 81 |
+
**_group("books", "1396571", "the colophon prints CC BY-NC 3.0 PL"),
|
| 82 |
+
**_group("books", "1409913", "the colophon prints CC BY-ND 3.0 PL"),
|
| 83 |
+
**_group("books", "2010681", "the colophon prints a NonCommercial licence, contradicting its own CC BY-SA 4.0 abbreviation"),
|
| 84 |
+
**_group("books", "2159317 2028459", "the text prints CC BY-NC-SA 4.0"),
|
| 85 |
+
**_group("books", "2143725", "the text prints CC BY-NC 3.0 PL (its foreword says CC BY)"),
|
| 86 |
+
**_group("books", "1396563", "the front page prints CC BY-NC-SA 4.0 (its colophon says CC BY-SA 4.0)"),
|
| 87 |
+
}
|
| 88 |
+
# The text says it was translated or reprinted by permission of a publisher or journal; nothing shows that permission
|
| 89 |
+
# covers redistribution under CC BY / BY-SA.
|
| 90 |
+
TEXT_REPRINT = {
|
| 91 |
+
**_group("articles", "634914 634916", "translated and reprinted by permission of Oxford University Press (for the Oral History Association); "
|
| 92 |
+
"limited-rights notice with a licence number"),
|
| 93 |
+
**_group("articles", "1622298", "Polish translation published by permission of the author and Oxford University Press; "
|
| 94 |
+
"further reproduction needs the publisher's consent"),
|
| 95 |
+
**_group("articles", "1622259", "reprinted by permission of the University of Arkansas Press, via The Permissions Company"),
|
| 96 |
+
**_group("articles", "1621507", "translated by permission of the author and the publisher (Darton, Longman and Todd)"),
|
| 97 |
+
**_group("articles", "623064", "reprinted by permission of Sage"),
|
| 98 |
+
**_group("articles", "623121", "translated and reproduced with permission of International Affairs"),
|
| 99 |
+
**_group("articles", "643727 643809", "\"Reprinted by Permission of SAGE Publications\""),
|
| 100 |
+
**_group("articles", "643825", "reprinted by permission of Indiana University Press"),
|
| 101 |
+
**_group("articles", "694180", "reprinted by permission of Westview Press"),
|
| 102 |
+
**_group("articles", "630597", "reprinted with the editors' permission"),
|
| 103 |
+
**_group("articles", "634918", "reprinted from the Oral History Review by permission of the Oral History Association"),
|
| 104 |
+
**_group("articles", "1917546 1992050", "translated and published by permission of the author and of the journal's publisher (Nova et Vetera)"),
|
| 105 |
+
}
|
| 106 |
|
| 107 |
|
| 108 |
def filter_table(table: pa.Table) -> pa.Table:
|
|
|
|
| 112 |
return table.filter(pc.is_in(table.column("license"), pa.array(sorted(KEEP))))
|
| 113 |
|
| 114 |
|
| 115 |
+
def license_label(api_license: dict, stored: str) -> str:
|
| 116 |
+
"""SPDX-style label (CC-BY-3.0-PL) for one API licence object. Raises ValueError, with the reason, unless it
|
| 117 |
+
is an allowlisted CC BY / BY-SA whose URL, English name and icon agree with each other and with `stored`."""
|
| 118 |
+
if not api_license.get("creativeCommons"):
|
| 119 |
+
raise ValueError(f"API licence {api_license.get('id')} is not marked creativeCommons")
|
| 120 |
+
match = LICENSE_URL.match(api_license.get("urlEn") or "")
|
| 121 |
+
if not match:
|
| 122 |
+
raise ValueError(f"licence URL not allowlisted: {api_license.get('urlEn')!r}")
|
| 123 |
+
kind, version, port = match.groups()
|
| 124 |
+
if version not in VERSIONS or port not in JURISDICTIONS:
|
| 125 |
+
raise ValueError(f"licence version/port not allowlisted: {api_license['urlEn']!r}")
|
| 126 |
+
name = api_license.get("nameEn") or ""
|
| 127 |
+
if f" {version}" not in name or (port and f" {port.upper()}" not in name):
|
| 128 |
+
raise ValueError(f"licence name {name!r} disagrees with URL {api_license['urlEn']!r}")
|
| 129 |
+
if not (api_license.get("iconId") == stored == f"cc-{kind}"):
|
| 130 |
+
raise ValueError(f"API icon {api_license.get('iconId')!r}, URL kind {kind!r} and stored {stored!r} disagree")
|
| 131 |
+
return f"CC-{kind.upper()}-{version}" + (f"-{port.upper()}" if port else "")
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def relabel(table: pa.Table, sidecar: dict, overrides: dict[str, str] | None = None) -> tuple[pa.Table, dict[str, str]]:
|
| 135 |
+
"""Versioned `license` for every row from the API sidecar. Returns the table without withheld rows and
|
| 136 |
+
{id: reason} for them. Fails closed: unresolved, missing or non-allowlisted rows are withheld. Only `license` changes.
|
| 137 |
+
A row in `overrides` is labelled from its API licence alone (the earlier stored label may differ), which must
|
| 138 |
+
give the listed label; the run fails if such a row is not reached (absent, unresolved or not in the sidecar)."""
|
| 139 |
+
overrides = overrides or {}
|
| 140 |
+
ids, stored = table.column("id").to_pylist(), table.column("license").to_pylist()
|
| 141 |
+
reached: set[str] = set()
|
| 142 |
+
resolved: dict[tuple[int, str], str | None] = {} # (API licence id, stored label) -> label, None = withheld
|
| 143 |
+
reasons: dict[tuple[int, str], str] = {}
|
| 144 |
+
new, withheld = [], {}
|
| 145 |
+
for row_id, old in zip(ids, stored):
|
| 146 |
+
label = None
|
| 147 |
+
if row_id in sidecar["unresolved"]:
|
| 148 |
+
withheld[row_id] = f"API: {sidecar['unresolved'][row_id]}"
|
| 149 |
+
elif row_id not in sidecar["rows"]:
|
| 150 |
+
withheld[row_id] = "not in the API sidecar"
|
| 151 |
+
elif row_id in overrides:
|
| 152 |
+
reached.add(row_id)
|
| 153 |
+
api_license = sidecar["licenses"][str(sidecar["rows"][row_id])]
|
| 154 |
+
label = license_label(api_license, api_license["iconId"])
|
| 155 |
+
if label != overrides[row_id]:
|
| 156 |
+
raise SystemExit(f"{row_id}: the API gives {label}, the override expects {overrides[row_id]}")
|
| 157 |
+
else:
|
| 158 |
+
key = (sidecar["rows"][row_id], old)
|
| 159 |
+
if key not in resolved:
|
| 160 |
+
try:
|
| 161 |
+
resolved[key] = license_label(sidecar["licenses"][str(key[0])], old)
|
| 162 |
+
except ValueError as exc:
|
| 163 |
+
resolved[key], reasons[key] = None, str(exc)
|
| 164 |
+
label = resolved[key]
|
| 165 |
+
if label is None:
|
| 166 |
+
withheld[row_id] = reasons[key]
|
| 167 |
+
new.append(label)
|
| 168 |
+
if unreached := sorted(set(overrides) - reached):
|
| 169 |
+
raise SystemExit(f"override ids not reached: {unreached}")
|
| 170 |
+
index = table.schema.get_field_index("license")
|
| 171 |
+
relabelled = table.set_column(index, table.schema.field(index), pa.array(new, pa.string()))
|
| 172 |
+
return relabelled.filter(pa.array([label is not None for label in new])), withheld
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def withhold_listed(table: pa.Table, listed: dict[str, str]) -> tuple[pa.Table, dict[str, str]]:
|
| 176 |
+
"""The table without the rows in `listed` ({id: reason}). Fails if a listed id is not in `table`."""
|
| 177 |
+
if unreached := sorted(set(listed) - set(table.column("id").to_pylist())):
|
| 178 |
+
raise SystemExit(f"listed ids not reached: {unreached}")
|
| 179 |
+
return table.filter(pc.invert(pc.is_in(table.column("id"), pa.array(sorted(listed), pa.string())))), dict(listed)
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def content_digest(path: Path, skip: frozenset[str] = frozenset()) -> str:
|
| 183 |
+
"""SHA-256 over every (id, SHA-256 of text) in file order, minus ids in `skip`. Equal digests mean the same
|
| 184 |
+
rows in the same order with the same text, whatever the other columns say."""
|
| 185 |
+
digest = hashlib.sha256()
|
| 186 |
+
for batch in pq.ParquetFile(path).iter_batches(columns=["id", "text"], batch_size=2000):
|
| 187 |
+
for row_id, text in zip(batch.column("id").to_pylist(), batch.column("text").to_pylist()):
|
| 188 |
+
if row_id not in skip:
|
| 189 |
+
digest.update(f"{row_id}\t{hashlib.sha256(text.encode()).hexdigest()}\n".encode())
|
| 190 |
+
return digest.hexdigest()
|
| 191 |
+
|
| 192 |
+
|
| 193 |
def build(input_path: Path, out_dir: Path) -> dict:
|
| 194 |
with input_path.open("rb") as stream:
|
| 195 |
if hashlib.file_digest(stream, "sha256").hexdigest() != INPUT_SHA256:
|
| 196 |
raise SystemExit(f"{input_path} is not the v0.2.5 Parquet; restore it with "
|
| 197 |
f"`git checkout v0.2.5 -- data/{SOURCE}/{SOURCE}.parquet`")
|
| 198 |
table = pq.read_table(input_path)
|
| 199 |
+
granted = filter_table(table)
|
| 200 |
+
dropped = sorted(set(table.column("id").to_pylist()) - set(granted.column("id").to_pylist()))
|
| 201 |
+
labelled, api_withheld = relabel(granted, json.loads(SIDECAR.read_text(encoding="utf-8")), API_OVERRIDES)
|
| 202 |
+
labelled, nc_nd = withhold_listed(labelled, TEXT_NC_ND)
|
| 203 |
+
kept, reprint = withhold_listed(labelled, TEXT_REPRINT)
|
| 204 |
+
withheld = {**api_withheld, **nc_nd, **reprint}
|
| 205 |
+
assert len(withheld) == len(api_withheld) + len(nc_nd) + len(reprint)
|
| 206 |
|
| 207 |
stats_path = out_dir / f"{SOURCE}.stats.json"
|
| 208 |
stats = json.loads(stats_path.read_text(encoding="utf-8")) # keeps build_dynaword's read/drop_* counts
|
| 209 |
stats.update(
|
| 210 |
kept=kept.num_rows,
|
| 211 |
+
drop_rights=table.num_rows - granted.num_rows,
|
| 212 |
+
drop_license_unverified=len(api_withheld),
|
| 213 |
+
drop_text_nc_nd=len(nc_nd),
|
| 214 |
+
drop_text_reprint=len(reprint),
|
| 215 |
chars=pc.sum(pc.utf8_length(kept.column("text"))).as_py(),
|
| 216 |
tokens=pc.sum(kept.column("token_count")).as_py(),
|
| 217 |
+
license=" / ".join(sorted(set(kept.column("license").to_pylist()))),
|
| 218 |
licenses=dict(sorted(Counter(kept.column("license").to_pylist()).items())),
|
| 219 |
+
withheld=dict(sorted(withheld.items())),
|
| 220 |
input_sha256=INPUT_SHA256,
|
| 221 |
)
|
| 222 |
parquet_tmp = out_dir / f"{SOURCE}.parquet.tmp"
|
| 223 |
stats_tmp = out_dir / f"{SOURCE}.stats.json.tmp"
|
| 224 |
pq.write_table(kept, parquet_tmp)
|
|
|
|
| 225 |
os.replace(parquet_tmp, out_dir / f"{SOURCE}.parquet")
|
| 226 |
+
stats["content_sha256"] = content_digest(out_dir / f"{SOURCE}.parquet")
|
| 227 |
+
stats_tmp.write_text(json.dumps(stats, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
| 228 |
os.replace(stats_tmp, stats_path)
|
| 229 |
return {**stats, "dropped_ids": dropped}
|
| 230 |
|
src/sources.py
CHANGED
|
@@ -717,15 +717,30 @@ SOURCES = {
|
|
| 717 |
"pretty": "Biblioteka Nauki",
|
| 718 |
"license": "per-record upstream license",
|
| 719 |
"license_spdx": "MIXED",
|
| 720 |
-
"traceable": "
|
| 721 |
-
"
|
| 722 |
-
"
|
| 723 |
-
"
|
|
|
|
| 724 |
"upstream": "https://bibliotekanauki.pl/",
|
| 725 |
-
"provenance": "
|
| 726 |
-
"
|
| 727 |
-
"
|
| 728 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 729 |
"domain": "academic",
|
| 730 |
"created": "unknown",
|
| 731 |
"is_ocr": False,
|
|
|
|
| 717 |
"pretty": "Biblioteka Nauki",
|
| 718 |
"license": "per-record upstream license",
|
| 719 |
"license_spdx": "MIXED",
|
| 720 |
+
"traceable": "Every retained row carries the licence name and version that the "
|
| 721 |
+
"Biblioteka Nauki API gave for that record on 2026-10-05/06 "
|
| 722 |
+
"(CC BY 2.0, 3.0, 3.0 PL, 4.0; CC BY-SA 3.0, 3.0 PL, 4.0), checked "
|
| 723 |
+
"against the licence URL and icon. The API licence objects are "
|
| 724 |
+
"committed as biblioteka_nauki.license-api.json.",
|
| 725 |
"upstream": "https://bibliotekanauki.pl/",
|
| 726 |
+
"provenance": "Text from the SpeakLeash redistribution; licence and attribution "
|
| 727 |
+
"recovered per document from the Biblioteka Nauki API (Hub PR 11); "
|
| 728 |
+
"assembly script not in the repository. The per-record values come from "
|
| 729 |
+
"bibliotekanauki.pl/api/{type}/{id} "
|
| 730 |
+
"(recover_license_versions.py, recover_attribution.py); rows the API "
|
| 731 |
+
"did not resolve to an allowlisted CC BY or CC BY-SA licence are "
|
| 732 |
+
"withheld by clean_biblioteka_nauki.py.",
|
| 733 |
+
"legal_note": "The `license` column holds the per-record version, not a single "
|
| 734 |
+
"CC BY 4.0 / CC BY-SA 4.0 label: CC BY-SA rows (about one third) are "
|
| 735 |
+
"share-alike under their own version (3.0, 3.0 PL or 4.0). Dropped: "
|
| 736 |
+
"3 items carrying the CC Public Domain Mark (a label, not a grant; "
|
| 737 |
+
"v2#52), 12 rows the API no longer serves (HTTP 404), 56 rows whose own "
|
| 738 |
+
"text prints a NonCommercial or NoDerivatives licence and 15 rows whose "
|
| 739 |
+
"text says it is reprinted or translated by permission of a publisher "
|
| 740 |
+
"(maintainer decision 2026-10-06, v2#57). About 120 texts contain the "
|
| 741 |
+
"phrase \"all rights reserved\" although their API licence is CC; that is "
|
| 742 |
+
"not resolved here. How the text layer was assembled from the SpeakLeash "
|
| 743 |
+
"blob is not re-verified: the assembly script was not committed.",
|
| 744 |
"domain": "academic",
|
| 745 |
"created": "unknown",
|
| 746 |
"is_ocr": False,
|
src/test_biblioteka_nauki_contract.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
-
"""Contract checks for biblioteka_nauki
|
|
|
|
| 2 |
|
|
|
|
| 3 |
import importlib.util
|
| 4 |
import json
|
|
|
|
| 5 |
import sys
|
| 6 |
from collections import Counter
|
| 7 |
from pathlib import Path
|
|
@@ -13,17 +16,53 @@ import pytest
|
|
| 13 |
|
| 14 |
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 15 |
|
| 16 |
-
from clean_biblioteka_nauki import
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
PUBLIC_DOMAIN_MARK_IDS = {
|
| 19 |
"biblioteka_nauki_books_2142716",
|
| 20 |
"biblioteka_nauki_books_2147851",
|
| 21 |
"biblioteka_nauki_articles_2097363",
|
| 22 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
-
def
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
path = DATA / "biblioteka_nauki.parquet"
|
| 28 |
assert pq.read_schema(path).names == [
|
| 29 |
"id", "text", "source", "added", "created", "token_count", "license", "attribution"]
|
|
@@ -31,27 +70,116 @@ def test_shard_has_no_public_domain_rows_and_matches_stats():
|
|
| 31 |
ids = table.column("id").to_pylist()
|
| 32 |
licenses = Counter(table.column("license").to_pylist())
|
| 33 |
|
| 34 |
-
assert table.num_rows == stats["kept"]
|
| 35 |
assert len(set(ids)) == len(ids)
|
| 36 |
assert not PUBLIC_DOMAIN_MARK_IDS & set(ids)
|
| 37 |
-
assert
|
| 38 |
-
assert
|
| 39 |
assert set(table.column("source").to_pylist()) == {"biblioteka_nauki"}
|
| 40 |
assert pc.sum(table.column("token_count")).as_py() == stats["tokens"]
|
| 41 |
assert pc.min(table.column("token_count")).as_py() > 0
|
| 42 |
assert all(a and a.strip() for a in table.column("attribution").to_pylist())
|
| 43 |
-
drops = ("drop_short", "drop_lang", "drop_dup", "drop_ocr", "drop_rights"
|
|
|
|
| 44 |
assert stats["read"] - sum(stats[k] for k in drops) == stats["kept"]
|
| 45 |
assert stats["drop_rights"] == 3
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
-
def
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
card = (DATA / "biblioteka_nauki.md").read_text(encoding="utf-8")
|
| 51 |
assert f"| {stats['kept']:,} | {stats['chars']:,} | {stats['tokens']:,} |" in card
|
| 52 |
-
for
|
| 53 |
-
assert f"{docs:,}" in card,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
assert "| Public Domain |" not in card
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
def test_filter_drops_public_domain_and_fails_closed():
|
|
@@ -63,7 +191,187 @@ def test_filter_drops_public_domain_and_fails_closed():
|
|
| 63 |
|
| 64 |
|
| 65 |
def test_upstream_gate_matches_filter():
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contract checks for biblioteka_nauki: public-domain drop, per-record licence versions and the withheld rows
|
| 2 |
+
(src/clean_biblioteka_nauki.py, data/biblioteka_nauki/recover_license_versions.py)."""
|
| 3 |
|
| 4 |
+
import hashlib
|
| 5 |
import importlib.util
|
| 6 |
import json
|
| 7 |
+
import re
|
| 8 |
import sys
|
| 9 |
from collections import Counter
|
| 10 |
from pathlib import Path
|
|
|
|
| 16 |
|
| 17 |
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 18 |
|
| 19 |
+
from clean_biblioteka_nauki import (
|
| 20 |
+
API_OVERRIDES, DATA, KEEP, SIDECAR, TEXT_NC_ND, TEXT_REPRINT, content_digest, filter_table, license_label, relabel,
|
| 21 |
+
withhold_listed)
|
| 22 |
+
from sources import SOURCES
|
| 23 |
|
| 24 |
PUBLIC_DOMAIN_MARK_IDS = {
|
| 25 |
"biblioteka_nauki_books_2142716",
|
| 26 |
"biblioteka_nauki_books_2147851",
|
| 27 |
"biblioteka_nauki_articles_2097363",
|
| 28 |
}
|
| 29 |
+
PROVENANCE = (
|
| 30 |
+
"text from the speakleash redistribution; licence and attribution recovered per document "
|
| 31 |
+
"from the biblioteka nauki api (hub pr 11); assembly script not in the repository"
|
| 32 |
+
)
|
| 33 |
+
RELABELLED_ID = "biblioteka_nauki_articles_2011995"
|
| 34 |
+
LABEL = re.compile(r"^CC-(BY|BY-SA)-(2\.0|2\.5|3\.0|4\.0)(-PL)?$")
|
| 35 |
|
| 36 |
|
| 37 |
+
def load_script(name):
|
| 38 |
+
spec = importlib.util.spec_from_file_location(name, DATA / f"{name}.py")
|
| 39 |
+
module = importlib.util.module_from_spec(spec)
|
| 40 |
+
spec.loader.exec_module(module)
|
| 41 |
+
return module
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def api_license(lid, icon, version, url, port=""):
|
| 45 |
+
kind = "BY-SA: Creative Commons Attribution-ShareAlike" if icon == "cc-by-sa" else "BY: Creative Commons Attribution"
|
| 46 |
+
return {"id": lid, "iconId": icon, "nameEn": f"CC {kind} {version}{port}", "urlEn": url, "creativeCommons": True}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
BY_30_PL = api_license(7, "cc-by", "3.0", "https://creativecommons.org/licenses/by/3.0/pl/legalcode", " PL")
|
| 50 |
+
BY_40 = api_license(1, "cc-by", "4.0", "https://creativecommons.org/licenses/by/4.0/legalcode.en")
|
| 51 |
+
BYSA_40 = api_license(2, "cc-by-sa", "4.0", "https://creativecommons.org/licenses/by-sa/4.0/legalcode.en")
|
| 52 |
+
BY_20 = api_license(21, "cc-by", "2.0 Generic", "https://creativecommons.org/licenses/by/2.0/legalcode")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@pytest.fixture(scope="module")
|
| 56 |
+
def stats():
|
| 57 |
+
return json.loads((DATA / "biblioteka_nauki.stats.json").read_text(encoding="utf-8"))
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
@pytest.fixture(scope="module")
|
| 61 |
+
def sidecar():
|
| 62 |
+
return json.loads(SIDECAR.read_text(encoding="utf-8"))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def test_shard_has_no_public_domain_rows_and_matches_stats(stats):
|
| 66 |
path = DATA / "biblioteka_nauki.parquet"
|
| 67 |
assert pq.read_schema(path).names == [
|
| 68 |
"id", "text", "source", "added", "created", "token_count", "license", "attribution"]
|
|
|
|
| 70 |
ids = table.column("id").to_pylist()
|
| 71 |
licenses = Counter(table.column("license").to_pylist())
|
| 72 |
|
| 73 |
+
assert table.num_rows == stats["kept"]
|
| 74 |
assert len(set(ids)) == len(ids)
|
| 75 |
assert not PUBLIC_DOMAIN_MARK_IDS & set(ids)
|
| 76 |
+
assert licenses == stats["licenses"]
|
| 77 |
+
assert all(LABEL.match(label) for label in licenses), licenses
|
| 78 |
assert set(table.column("source").to_pylist()) == {"biblioteka_nauki"}
|
| 79 |
assert pc.sum(table.column("token_count")).as_py() == stats["tokens"]
|
| 80 |
assert pc.min(table.column("token_count")).as_py() > 0
|
| 81 |
assert all(a and a.strip() for a in table.column("attribution").to_pylist())
|
| 82 |
+
drops = ("drop_short", "drop_lang", "drop_dup", "drop_ocr", "drop_rights",
|
| 83 |
+
"drop_license_unverified", "drop_text_nc_nd", "drop_text_reprint")
|
| 84 |
assert stats["read"] - sum(stats[k] for k in drops) == stats["kept"]
|
| 85 |
assert stats["drop_rights"] == 3
|
| 86 |
+
assert stats["drop_license_unverified"] + stats["drop_text_nc_nd"] + stats["drop_text_reprint"] == len(stats["withheld"])
|
| 87 |
|
| 88 |
|
| 89 |
+
def test_maintainer_withholds_and_relabel_of_2026_10_06(stats):
|
| 90 |
+
"""Hub PR 81: 12 API 404s, 56 NC/ND rows and 15 reprint-by-permission rows are out; articles_2011995 stays, as CC BY-SA 4.0."""
|
| 91 |
+
table = pq.read_table(DATA / "biblioteka_nauki.parquet", columns=["id", "license"])
|
| 92 |
+
labels = dict(zip(table.column("id").to_pylist(), table.column("license").to_pylist()))
|
| 93 |
+
assert (len(TEXT_NC_ND), len(TEXT_REPRINT)) == (56, 15) and not set(TEXT_NC_ND) & set(TEXT_REPRINT)
|
| 94 |
+
assert not (set(TEXT_NC_ND) | set(TEXT_REPRINT)) & set(labels)
|
| 95 |
+
assert {i: stats["withheld"][i] for i in TEXT_NC_ND} == TEXT_NC_ND
|
| 96 |
+
assert {i: stats["withheld"][i] for i in TEXT_REPRINT} == TEXT_REPRINT
|
| 97 |
+
assert all(reason.strip() for reason in stats["withheld"].values())
|
| 98 |
+
api = {i: reason for i, reason in stats["withheld"].items() if i not in TEXT_NC_ND and i not in TEXT_REPRINT}
|
| 99 |
+
assert len(api) == stats["drop_license_unverified"] == 12 and set(api.values()) == {"API: http404"}
|
| 100 |
+
assert (stats["drop_text_nc_nd"], stats["drop_text_reprint"]) == (56, 15)
|
| 101 |
+
assert API_OVERRIDES == {RELABELLED_ID: "CC-BY-SA-4.0"}
|
| 102 |
+
assert labels[RELABELLED_ID] == "CC-BY-SA-4.0" and RELABELLED_ID not in stats["withheld"]
|
| 103 |
+
assert stats["kept"] == 42055 + 1 - 71
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_shard_labels_are_the_api_licences_in_the_sidecar(stats, sidecar):
|
| 107 |
+
"""Every row's label is the one its API licence gives, and every shipped or withheld id is in the sidecar."""
|
| 108 |
+
table = pq.read_table(DATA / "biblioteka_nauki.parquet", columns=["id", "license"])
|
| 109 |
+
ids = table.column("id").to_pylist()
|
| 110 |
+
for row_id, label in zip(ids, table.column("license").to_pylist()):
|
| 111 |
+
lic = sidecar["licenses"][str(sidecar["rows"][row_id])]
|
| 112 |
+
assert label == license_label(lic, lic["iconId"]), row_id
|
| 113 |
+
assert not set(ids) & set(stats["withheld"])
|
| 114 |
+
assert set(ids) | set(stats["withheld"]) == set(sidecar["rows"]) | set(sidecar["unresolved"])
|
| 115 |
+
assert sidecar["rows_total"] == len(sidecar["rows"]) + len(sidecar["unresolved"]) == len(ids) + len(stats["withheld"])
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def test_evidence_file_matches_sidecar_and_stats(stats, sidecar):
|
| 119 |
+
evidence = json.loads((DATA / "biblioteka_nauki.license-evidence.json").read_text(encoding="utf-8"))
|
| 120 |
+
assert evidence["sidecar_sha256"] == hashlib.sha256(SIDECAR.read_bytes()).hexdigest()
|
| 121 |
+
assert evidence["retrieved"] == sidecar["retrieved"]
|
| 122 |
+
by_id = {str(row["api_license_id"]): row for row in evidence["api_licenses"]}
|
| 123 |
+
assert set(by_id) == set(sidecar["licenses"])
|
| 124 |
+
rows_per_license = Counter(sidecar["rows"].values())
|
| 125 |
+
for lid, lic in sidecar["licenses"].items():
|
| 126 |
+
row = by_id[lid]
|
| 127 |
+
assert (row["nameEn"], row["urlEn"]) == (lic["nameEn"], lic["urlEn"])
|
| 128 |
+
assert row["label"] == license_label(lic, lic["iconId"])
|
| 129 |
+
assert row["api_rows"] == rows_per_license[int(lid)]
|
| 130 |
+
assert row["shipped"] == stats["licenses"].get(row["label"], 0)
|
| 131 |
+
assert evidence["withheld"] == len(stats["withheld"])
|
| 132 |
+
assert evidence["flagged"] == Counter(flag for flags in sidecar["flagged"].values() for flag in flags)
|
| 133 |
+
assert evidence["unchanged_vs_pr62"]["content_sha256"] == stats["content_sha256"]
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def test_shard_text_and_ids_match_the_recorded_digest(stats):
|
| 137 |
+
"""Text and ids are what PR 62 shipped: stats['content_sha256'] was equal to the PR 62 shard's digest
|
| 138 |
+
(evidence: unchanged_vs_pr62), and the shard on disk still hashes to it."""
|
| 139 |
+
assert content_digest(DATA / "biblioteka_nauki.parquet") == stats["content_sha256"]
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def test_content_digest_sees_text_ids_and_order_but_not_other_columns(tmp_path):
|
| 143 |
+
def digest(name, ids, texts, license_="cc-by", skip=frozenset()):
|
| 144 |
+
path = tmp_path / name
|
| 145 |
+
pq.write_table(pa.table({"id": ids, "text": texts, "license": [license_] * len(ids)}), path)
|
| 146 |
+
return content_digest(path, skip)
|
| 147 |
+
|
| 148 |
+
base = digest("a.parquet", ["x", "y"], ["tx", "ty"])
|
| 149 |
+
assert digest("b.parquet", ["x", "y"], ["tx", "ty"], license_="CC-BY-4.0") == base
|
| 150 |
+
assert digest("c.parquet", ["x", "y"], ["tx", "tY"]) != base
|
| 151 |
+
assert digest("d.parquet", ["x", "z"], ["tx", "ty"]) != base
|
| 152 |
+
assert digest("e.parquet", ["y", "x"], ["ty", "tx"]) != base
|
| 153 |
+
assert digest("f.parquet", ["x", "y", "w"], ["tx", "ty", "tw"], skip=frozenset({"w"})) == base
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def test_datasheet_counts_match_stats(stats):
|
| 157 |
card = (DATA / "biblioteka_nauki.md").read_text(encoding="utf-8")
|
| 158 |
assert f"| {stats['kept']:,} | {stats['chars']:,} | {stats['tokens']:,} |" in card
|
| 159 |
+
for label, docs in stats["licenses"].items():
|
| 160 |
+
assert f"| {label} | {docs:,} |" in card, label
|
| 161 |
+
classes = {
|
| 162 |
+
"API HTTP 404": stats["drop_license_unverified"],
|
| 163 |
+
"text prints a NonCommercial or NoDerivatives licence": stats["drop_text_nc_nd"],
|
| 164 |
+
"text says it is reprinted or translated by permission of a publisher": stats["drop_text_reprint"],
|
| 165 |
+
}
|
| 166 |
+
for name, count in classes.items():
|
| 167 |
+
assert f"| {name} | {count} |" in card, name
|
| 168 |
+
assert f"read {stats['read']:,} → kept {stats['kept']:,}" in card
|
| 169 |
assert "| Public Domain |" not in card
|
| 170 |
+
assert PROVENANCE in " ".join(card.lower().split())
|
| 171 |
+
assert "direct rebuild" not in card.lower()
|
| 172 |
+
assert "Pulled from SpeakLeash" not in card
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def test_registry_entry_says_per_record_versions_and_speakleash_text():
|
| 176 |
+
entry = SOURCES["biblioteka_nauki"]
|
| 177 |
+
assert entry["license_spdx"] == "MIXED"
|
| 178 |
+
assert "version" in entry["traceable"]
|
| 179 |
+
assert PROVENANCE in entry["provenance"].lower()
|
| 180 |
+
assert "direct rebuild" not in entry["provenance"].lower()
|
| 181 |
+
assert "not a SpeakLeash" not in entry["provenance"]
|
| 182 |
+
assert "recover_license_versions.py" in entry["provenance"]
|
| 183 |
|
| 184 |
|
| 185 |
def test_filter_drops_public_domain_and_fails_closed():
|
|
|
|
| 191 |
|
| 192 |
|
| 193 |
def test_upstream_gate_matches_filter():
|
| 194 |
+
assert load_script("recover_attribution").CLEAN == KEEP
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
@pytest.mark.parametrize("lic, stored, label", [
|
| 198 |
+
(BY_40, "cc-by", "CC-BY-4.0"),
|
| 199 |
+
(BYSA_40, "cc-by-sa", "CC-BY-SA-4.0"),
|
| 200 |
+
(BY_30_PL, "cc-by", "CC-BY-3.0-PL"),
|
| 201 |
+
(api_license(3, "cc-by", "3.0 Unported", "https://creativecommons.org/licenses/by/3.0/legalcode"), "cc-by", "CC-BY-3.0"),
|
| 202 |
+
(api_license(8, "cc-by-sa", "3.0", "https://creativecommons.org/licenses/by-sa/3.0/pl/legalcode", " PL"), "cc-by-sa", "CC-BY-SA-3.0-PL"),
|
| 203 |
+
(BY_20, "cc-by", "CC-BY-2.0"),
|
| 204 |
+
])
|
| 205 |
+
def test_license_label_reads_kind_version_and_port_from_the_api(lic, stored, label):
|
| 206 |
+
assert license_label(lic, stored) == label
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
@pytest.mark.parametrize("lic, stored", [
|
| 210 |
+
({**BY_40, "creativeCommons": False}, "cc-by"),
|
| 211 |
+
({**BY_40, "urlEn": "https://creativecommons.org/publicdomain/mark/1.0/"}, "cc-by"),
|
| 212 |
+
({**BY_40, "urlEn": "https://creativecommons.org/licenses/by-nc/4.0/legalcode"}, "cc-by"),
|
| 213 |
+
({**BY_40, "urlEn": "https://creativecommons.org/licenses/by-nd/4.0/legalcode"}, "cc-by"),
|
| 214 |
+
({**BY_40, "urlEn": "https://creativecommons.org/licenses/by/1.0/legalcode"}, "cc-by"),
|
| 215 |
+
({**BY_40, "urlEn": "https://creativecommons.org/licenses/by/3.0/de/legalcode"}, "cc-by"),
|
| 216 |
+
({**BY_40, "urlEn": "https://example.org/licenses/by/4.0/legalcode"}, "cc-by"),
|
| 217 |
+
({**BY_40, "urlEn": None}, "cc-by"),
|
| 218 |
+
({**BY_40, "nameEn": "CC BY: Creative Commons Attribution 3.0 PL"}, "cc-by"), # name says 3.0, URL says 4.0
|
| 219 |
+
({**BY_40, "iconId": "cc-by-sa"}, "cc-by"), # icon disagrees with stored label and URL
|
| 220 |
+
(BY_40, "cc-by-sa"), # stored label disagrees with the API
|
| 221 |
+
(BYSA_40, "cc0"),
|
| 222 |
+
])
|
| 223 |
+
def test_license_label_fails_closed(lic, stored):
|
| 224 |
+
with pytest.raises(ValueError):
|
| 225 |
+
license_label(lic, stored)
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def test_relabel_changes_only_license_and_withholds_what_it_cannot_verify():
|
| 229 |
+
table = pa.table({
|
| 230 |
+
"id": ["a", "b", "c", "d", "e", "f"],
|
| 231 |
+
"text": ["ta", "tb", "tc", "td", "te", "tf"],
|
| 232 |
+
"token_count": [1, 2, 3, 4, 5, 6],
|
| 233 |
+
"license": ["cc-by", "cc-by", "cc-by-sa", "cc-by", "cc-by", "cc-by-sa"],
|
| 234 |
+
})
|
| 235 |
+
sidecar = {
|
| 236 |
+
"licenses": {"7": BY_30_PL, "1": BY_40, "2": BYSA_40,
|
| 237 |
+
"9": {**BY_40, "id": 9, "urlEn": "https://creativecommons.org/licenses/by-nc/4.0/legalcode"}},
|
| 238 |
+
"rows": {"a": 7, "b": 1, "c": 2, "d": 9, "f": 1}, # "e" is nowhere; "f" is cc-by-sa locally, BY upstream
|
| 239 |
+
"unresolved": {"e": "http404"},
|
| 240 |
+
}
|
| 241 |
+
sidecar["rows"]["e"] = 1 # unresolved wins over rows
|
| 242 |
+
out, withheld = relabel(table, sidecar)
|
| 243 |
+
assert out.column("id").to_pylist() == ["a", "b", "c"]
|
| 244 |
+
assert out.column("license").to_pylist() == ["CC-BY-3.0-PL", "CC-BY-4.0", "CC-BY-SA-4.0"]
|
| 245 |
+
for name in ("id", "text", "token_count"):
|
| 246 |
+
assert out.column(name).to_pylist() == table.filter(pa.array([True, True, True, False, False, False])).column(name).to_pylist()
|
| 247 |
+
assert out.schema == table.schema
|
| 248 |
+
assert set(withheld) == {"d", "e", "f"}
|
| 249 |
+
assert withheld["e"] == "API: http404"
|
| 250 |
+
assert "not allowlisted" in withheld["d"] and "disagree" in withheld["f"]
|
| 251 |
+
_, withheld = relabel(pa.table({"id": ["z"], "license": ["cc-by"]}), {"licenses": {}, "rows": {}, "unresolved": {}})
|
| 252 |
+
assert withheld == {"z": "not in the API sidecar"}
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
def test_relabel_override_labels_from_the_api_only_and_must_be_reached():
|
| 256 |
+
table = pa.table({"id": ["a", "b"], "license": ["cc-by", "cc-by"]})
|
| 257 |
+
sidecar = {"licenses": {"1": BY_40, "2": BYSA_40}, "rows": {"a": 1, "b": 2}, "unresolved": {}}
|
| 258 |
+
out, withheld = relabel(table, sidecar, {"b": "CC-BY-SA-4.0"}) # stored cc-by, API says BY-SA: the API wins
|
| 259 |
+
assert out.column("license").to_pylist() == ["CC-BY-4.0", "CC-BY-SA-4.0"] and withheld == {}
|
| 260 |
+
_, withheld = relabel(table, sidecar) # without the override the disagreement is withheld
|
| 261 |
+
assert set(withheld) == {"b"}
|
| 262 |
+
with pytest.raises(SystemExit, match="API gives CC-BY-SA-4.0"):
|
| 263 |
+
relabel(table, sidecar, {"b": "CC-BY-4.0"})
|
| 264 |
+
with pytest.raises(SystemExit, match="override ids not reached"):
|
| 265 |
+
relabel(table, sidecar, {"zz": "CC-BY-4.0"}) # absent
|
| 266 |
+
with pytest.raises(SystemExit, match="override ids not reached"):
|
| 267 |
+
relabel(table, {**sidecar, "unresolved": {"b": "http404"}}, {"b": "CC-BY-SA-4.0"}) # withheld by the API
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def test_withhold_listed_drops_exactly_the_listed_ids_and_fails_when_one_is_not_reached():
|
| 271 |
+
table = pa.table({"id": ["a", "b", "c"], "text": ["ta", "tb", "tc"]})
|
| 272 |
+
out, withheld = withhold_listed(table, {"c": "why c", "a": "why a"})
|
| 273 |
+
assert out.to_pydict() == {"id": ["b"], "text": ["tb"]} and withheld == {"c": "why c", "a": "why a"}
|
| 274 |
+
assert withhold_listed(table, {})[0].to_pydict() == table.to_pydict()
|
| 275 |
+
with pytest.raises(SystemExit, match="listed ids not reached: \\['zz'\\]"):
|
| 276 |
+
withhold_listed(table, {"a": "x", "zz": "y"})
|
| 277 |
+
with pytest.raises(SystemExit, match="listed ids not reached"):
|
| 278 |
+
withhold_listed(out, {"a": "x"}) # already gone: a second list may not name a first list's id
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
class FakeResponse:
|
| 282 |
+
def __init__(self, status, body=None, headers=None, text=""):
|
| 283 |
+
self.status_code, self._body, self.headers, self.text = status, body, headers or {}, text
|
| 284 |
+
|
| 285 |
+
def json(self):
|
| 286 |
+
if self._body is None:
|
| 287 |
+
raise ValueError("not json")
|
| 288 |
+
return self._body
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
class FakeSession:
|
| 292 |
+
def __init__(self, *responses):
|
| 293 |
+
self.responses, self.urls = list(responses), []
|
| 294 |
+
|
| 295 |
+
def get(self, url, timeout):
|
| 296 |
+
self.urls.append(url)
|
| 297 |
+
return self.responses.pop(0)
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
class NoClock:
|
| 301 |
+
def wait(self):
|
| 302 |
+
pass
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
RECORD = {"id": 941208, "license": BY_30_PL, "restricted": False, "reprintPublication": True, "translationPublication": False}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def test_fetch_one_reads_the_license_object_and_flags():
|
| 309 |
+
fetch = load_script("recover_license_versions")
|
| 310 |
+
session = FakeSession(FakeResponse(200, RECORD))
|
| 311 |
+
line = fetch.fetch_one(session, NoClock(), "biblioteka_nauki_books_941208", sleep=lambda _: None)
|
| 312 |
+
assert session.urls == ["https://bibliotekanauki.pl/api/books/941208"]
|
| 313 |
+
assert line["status"] == "ok" and line["license"] == BY_30_PL and line["flags"] == ["reprintPublication"]
|
| 314 |
+
wrong = fetch.fetch_one(FakeSession(FakeResponse(200, {**RECORD, "id": 5})), NoClock(), "biblioteka_nauki_books_941208")
|
| 315 |
+
assert wrong["status"] == "id_mismatch"
|
| 316 |
+
gone = fetch.fetch_one(FakeSession(FakeResponse(404)), NoClock(), "biblioteka_nauki_articles_1")
|
| 317 |
+
assert gone["status"] == "http404" and gone["license"] is None
|
| 318 |
+
nolic = fetch.fetch_one(FakeSession(FakeResponse(200, {"id": 1, "license": None})), NoClock(), "biblioteka_nauki_articles_1")
|
| 319 |
+
assert nolic["status"] == "ok" and nolic["license"] is None
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def test_fetch_one_backs_off_on_429_and_5xx_then_gives_up():
|
| 323 |
+
fetch = load_script("recover_license_versions")
|
| 324 |
+
slept = []
|
| 325 |
+
session = FakeSession(FakeResponse(429, headers={"Retry-After": "7"}), FakeResponse(503), FakeResponse(200, RECORD))
|
| 326 |
+
assert fetch.fetch_one(session, NoClock(), "biblioteka_nauki_books_941208", sleep=slept.append)["status"] == "ok"
|
| 327 |
+
assert slept[0] == 7 and 2 <= slept[1] < 3 and len(session.urls) == 3
|
| 328 |
+
never = FakeSession(*[FakeResponse(500) for _ in range(fetch.MAX_RETRY)])
|
| 329 |
+
assert fetch.fetch_one(never, NoClock(), "biblioteka_nauki_books_1", sleep=lambda _: None) is None
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
@pytest.mark.parametrize("response", [
|
| 333 |
+
FakeResponse(403),
|
| 334 |
+
FakeResponse(401),
|
| 335 |
+
FakeResponse(200, None, text="<html>Please verify you are human (CAPTCHA)</html>"),
|
| 336 |
+
FakeResponse(200, {"id": 1}), # JSON without a `license` key
|
| 337 |
+
])
|
| 338 |
+
def test_fetch_one_stops_instead_of_working_around_a_block(response):
|
| 339 |
+
fetch = load_script("recover_license_versions")
|
| 340 |
+
session = FakeSession(response)
|
| 341 |
+
with pytest.raises(fetch.Blocked):
|
| 342 |
+
fetch.fetch_one(session, NoClock(), "biblioteka_nauki_books_1", sleep=lambda _: None)
|
| 343 |
+
assert len(session.urls) == 1 # no retry, no second try
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def test_row_ids_are_parsed_strictly():
|
| 347 |
+
fetch = load_script("recover_license_versions")
|
| 348 |
+
assert fetch.parse_row_id("biblioteka_nauki_chapters_42") == ("chapters", 42)
|
| 349 |
+
for bad in ("biblioteka_nauki_papers_1", "wolne_lektury_books_1", "biblioteka_nauki_books_x", "biblioteka_nauki_books_1/../2"):
|
| 350 |
+
with pytest.raises(ValueError):
|
| 351 |
+
fetch.parse_row_id(bad)
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def test_export_covers_every_row_and_separates_unresolved_and_flagged(tmp_path):
|
| 355 |
+
fetch = load_script("recover_license_versions")
|
| 356 |
+
ids = ["biblioteka_nauki_books_1", "biblioteka_nauki_books_2", "biblioteka_nauki_books_3", "biblioteka_nauki_books_4"]
|
| 357 |
+
parquet = tmp_path / "x.parquet"
|
| 358 |
+
pq.write_table(pa.table({"id": ids}), parquet)
|
| 359 |
+
day = {"fetched": "2026-10-06", "flags": []}
|
| 360 |
+
lines = [
|
| 361 |
+
{"id": ids[0], "status": "ok", "license": BY_40, **day},
|
| 362 |
+
{"id": ids[1], "status": "ok", "license": BY_40, "fetched": "2026-10-06", "flags": ["restricted"]},
|
| 363 |
+
{"id": ids[2], "status": "http404", "license": None, "flags": []},
|
| 364 |
+
{"id": ids[3], "status": "ok", "license": None, **day},
|
| 365 |
+
]
|
| 366 |
+
cache, out = tmp_path / "cache.jsonl", tmp_path / "sidecar.json"
|
| 367 |
+
cache.write_text("\n".join(json.dumps(line) for line in lines[:3]) + "\n", encoding="utf-8")
|
| 368 |
+
args = type("Args", (), {"parquet": parquet, "cache": cache, "out": out})
|
| 369 |
+
with pytest.raises(SystemExit, match="1 rows not fetched"):
|
| 370 |
+
fetch.export(args)
|
| 371 |
+
cache.write_text("\n".join(json.dumps(line) for line in lines) + "\n", encoding="utf-8")
|
| 372 |
+
fetch.export(args)
|
| 373 |
+
result = json.loads(out.read_text(encoding="utf-8"))
|
| 374 |
+
assert result["rows"] == {ids[0]: 1, ids[1]: 1}
|
| 375 |
+
assert result["unresolved"] == {ids[2]: "http404", ids[3]: "no_license"}
|
| 376 |
+
assert result["flagged"] == {ids[1]: ["restricted"]}
|
| 377 |
+
assert result["licenses"] == {"1": BY_40} and result["retrieved"] == "2026-10-06" and result["rows_total"] == 4
|