Datasets:
Release v0.3.1 Europeana preview shard
#4
by kacperwikiel - opened
- CHANGELOG.md +12 -0
- README.md +7 -0
- previews/v0.3.1/europeana.parquet +3 -0
- previews/v0.3.1/europeana.stats.json +17 -0
- src/fetch_europeana.py +274 -0
- src/rights.py +5 -1
- src/sources.py +32 -31
- src/test_europeana_contract.py +31 -0
CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
| 1 |
# Changelog
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
## v0.3.0-preview (in progress)
|
| 4 |
|
| 5 |
- Validated the source-policy gate on live local SpeakLeash shards: 12 reviewed
|
|
|
|
| 1 |
# Changelog
|
| 2 |
|
| 3 |
+
## v0.3.1-preview (2026-07-10)
|
| 4 |
+
|
| 5 |
+
- Added a separate 810-document Europeana direct-ingestion preview parquet at
|
| 6 |
+
`previews/v0.3.1/europeana.parquet`. It was built from 1,000 live API records
|
| 7 |
+
using per-record rights/creator metadata in 59.4 seconds; 808 retained records are Public
|
| 8 |
+
Domain Mark and two are CC-BY-SA-4.0.
|
| 9 |
+
- The direct source gate dropped 181 non-Polish and nine OCR-garble records.
|
| 10 |
+
`dsbench` found unique IDs, no empty text, no duplicate text and no eval-set
|
| 11 |
+
overlap. Potential-phone matches remain warnings for manual review.
|
| 12 |
+
- This preview does not change v0.2.1 stable totals or promote Europeana to a
|
| 13 |
+
stable source. It is the measured contract for the full rights-preserving run.
|
| 14 |
+
|
| 15 |
## v0.3.0-preview (in progress)
|
| 16 |
|
| 17 |
- Validated the source-policy gate on live local SpeakLeash shards: 12 reviewed
|
README.md
CHANGED
|
@@ -28,6 +28,12 @@ family (Enevoldsen et al., [arXiv:2508.02271](https://arxiv.org/abs/2508.02271))
|
|
| 28 |
> remix workflow. This is candidate-only metadata and audit work: it does not
|
| 29 |
> replace the v0.2.1 stable parquets.
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
## Versions
|
| 32 |
|
| 33 |
| version | status | documents | tokens | notes |
|
|
@@ -35,6 +41,7 @@ family (Enevoldsen et al., [arXiv:2508.02271](https://arxiv.org/abs/2508.02271))
|
|
| 35 |
| `v0.2.1` | stable release | 2,491,773 | 6.28B | 12-source stable corpus with `license` and `author` metadata columns; adds `1000_novels`. |
|
| 36 |
| `v0.2.0` | previous stable | 2,490,773 | 6.22B | Provenance-first corpus from 11 open/official sources. |
|
| 37 |
| `v0.3.0-preview` | validation release, candidate-only | candidate-only | TBD | Live source gates validated; Biblioteka Nauki, Europeana, and HPLT/Common Corpus expansion remain subject to per-source QA, dedup, and legal review. |
|
|
|
|
| 38 |
|
| 39 |
## What this dataset contributes
|
| 40 |
The raw texts come from existing open corpora (redistributed via SpeakLeash and,
|
|
|
|
| 28 |
> remix workflow. This is candidate-only metadata and audit work: it does not
|
| 29 |
> replace the v0.2.1 stable parquets.
|
| 30 |
|
| 31 |
+
> **v0.3.1-preview** · first reproducible Europeana direct-ingestion shard:
|
| 32 |
+
> 1,000 API records → 810 quality-gated parquet documents, each preserving
|
| 33 |
+
> per-record rights and creator metadata. Stored separately under
|
| 34 |
+
> `previews/v0.3.1/europeana.parquet`; the paged Search API run took 59.4 s and
|
| 35 |
+
> does not alter v0.2.1 stable totals.
|
| 36 |
+
|
| 37 |
## Versions
|
| 38 |
|
| 39 |
| version | status | documents | tokens | notes |
|
|
|
|
| 41 |
| `v0.2.1` | stable release | 2,491,773 | 6.28B | 12-source stable corpus with `license` and `author` metadata columns; adds `1000_novels`. |
|
| 42 |
| `v0.2.0` | previous stable | 2,490,773 | 6.22B | Provenance-first corpus from 11 open/official sources. |
|
| 43 |
| `v0.3.0-preview` | validation release, candidate-only | candidate-only | TBD | Live source gates validated; Biblioteka Nauki, Europeana, and HPLT/Common Corpus expansion remain subject to per-source QA, dedup, and legal review. |
|
| 44 |
+
| `v0.3.1-preview` | reproducible Europeana shard | 810 | 140,042 | 1,000 direct API records sampled; 810 passed short/language/OCR gates, with per-record rights and author metadata. |
|
| 45 |
|
| 46 |
## What this dataset contributes
|
| 47 |
The raw texts come from existing open corpora (redistributed via SpeakLeash and,
|
previews/v0.3.1/europeana.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ceb638262859c675ca41f520c6fa60d8aa57bf62c6ab0e3dcb390136b8b2a321
|
| 3 |
+
size 146437
|
previews/v0.3.1/europeana.stats.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"read": 1000,
|
| 3 |
+
"kept": 810,
|
| 4 |
+
"drop_short": 0,
|
| 5 |
+
"drop_lang": 181,
|
| 6 |
+
"drop_dup": 0,
|
| 7 |
+
"drop_ocr": 9,
|
| 8 |
+
"chars": 433736,
|
| 9 |
+
"tokens": 140042,
|
| 10 |
+
"licenses": {
|
| 11 |
+
"public-domain (PDM-1.0)": 808,
|
| 12 |
+
"CC-BY-SA-4.0": 2
|
| 13 |
+
},
|
| 14 |
+
"authors_with_value": 809,
|
| 15 |
+
"secs": 0.4,
|
| 16 |
+
"license": "per-record public-domain/open rights statement"
|
| 17 |
+
}
|
src/fetch_europeana.py
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Direct Europeana rebuild with per-record rights metadata.
|
| 3 |
+
|
| 4 |
+
This intentionally does not consume the SpeakLeash Europeana aggregate. It uses
|
| 5 |
+
Europeana Search/Record APIs, preserves per-record rights/creator metadata, and
|
| 6 |
+
only emits records whose rights statement is open enough for DynaWord stable.
|
| 7 |
+
|
| 8 |
+
Usage:
|
| 9 |
+
EUROPEANA_API_KEY=... python3 src/fetch_europeana.py \
|
| 10 |
+
--query 'language:pl' --max-records 1000 --out data/upstream
|
| 11 |
+
|
| 12 |
+
For a connectivity smoke test, Europeana's public demo key can be used:
|
| 13 |
+
python3 src/fetch_europeana.py --api-key apidemo --query '*:*' --max-records 10 --out /tmp/dw
|
| 14 |
+
"""
|
| 15 |
+
from __future__ import annotations
|
| 16 |
+
|
| 17 |
+
import argparse
|
| 18 |
+
import json
|
| 19 |
+
import os
|
| 20 |
+
import re
|
| 21 |
+
import subprocess
|
| 22 |
+
import time
|
| 23 |
+
from collections import Counter
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
from urllib.parse import quote
|
| 26 |
+
|
| 27 |
+
import requests
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
from bs4 import BeautifulSoup
|
| 31 |
+
except Exception: # pragma: no cover - optional in some envs
|
| 32 |
+
BeautifulSoup = None
|
| 33 |
+
|
| 34 |
+
from rights import rights_ok, spdx
|
| 35 |
+
|
| 36 |
+
SEARCH_URL = "https://api.europeana.eu/record/v2/search.json"
|
| 37 |
+
RECORD_URL = "https://api.europeana.eu/record/v2/{record_id}.json"
|
| 38 |
+
UA = "polish-dynaword/0.3 (+direct-upstream-rights-rebuild)"
|
| 39 |
+
KEY = "europeana"
|
| 40 |
+
MIN_CHARS = 200
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def compact_text(value) -> str:
|
| 44 |
+
if value is None:
|
| 45 |
+
return ""
|
| 46 |
+
if isinstance(value, list):
|
| 47 |
+
return "; ".join(str(v).strip() for v in value if str(v).strip())
|
| 48 |
+
if isinstance(value, dict):
|
| 49 |
+
parts = []
|
| 50 |
+
for v in value.values():
|
| 51 |
+
if isinstance(v, list):
|
| 52 |
+
parts.extend(str(x).strip() for x in v if str(x).strip())
|
| 53 |
+
elif v:
|
| 54 |
+
parts.append(str(v).strip())
|
| 55 |
+
return "; ".join(parts)
|
| 56 |
+
return str(value).strip()
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def strip_html(text: str) -> str:
|
| 60 |
+
if not text:
|
| 61 |
+
return ""
|
| 62 |
+
if BeautifulSoup is not None:
|
| 63 |
+
text = BeautifulSoup(text, "html.parser").get_text("\n")
|
| 64 |
+
text = re.sub(r"\s+\n", "\n", text)
|
| 65 |
+
text = re.sub(r"\n{3,}", "\n\n", text)
|
| 66 |
+
text = re.sub(r"[ \t]{2,}", " ", text)
|
| 67 |
+
return text.strip()
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def get_json(session: requests.Session, url: str, params: dict, tries: int = 5) -> dict:
|
| 71 |
+
for attempt in range(tries):
|
| 72 |
+
resp = session.get(url, params=params, timeout=60)
|
| 73 |
+
if resp.status_code in (429, 500, 502, 503, 504):
|
| 74 |
+
time.sleep(2 + attempt * 3)
|
| 75 |
+
continue
|
| 76 |
+
resp.raise_for_status()
|
| 77 |
+
return resp.json()
|
| 78 |
+
resp.raise_for_status()
|
| 79 |
+
return {}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def record_text(record: dict, item: dict) -> str:
|
| 83 |
+
obj = record.get("object", {}) if isinstance(record.get("object"), dict) else {}
|
| 84 |
+
proxies = obj.get("proxies") or []
|
| 85 |
+
candidates = []
|
| 86 |
+
for proxy in proxies:
|
| 87 |
+
for key in ("dcDescription", "dcTitle", "dctermsAlternative", "dctermsTableOfContents"):
|
| 88 |
+
candidates.append(compact_text(proxy.get(key)))
|
| 89 |
+
for key in ("title", "dcTitle", "description", "dcDescription"):
|
| 90 |
+
candidates.append(compact_text(item.get(key)))
|
| 91 |
+
text = "\n\n".join(part for part in candidates if part)
|
| 92 |
+
return strip_html(text)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def creator(record: dict, item: dict) -> str:
|
| 96 |
+
obj = record.get("object", {}) if isinstance(record.get("object"), dict) else {}
|
| 97 |
+
vals = []
|
| 98 |
+
for proxy in obj.get("proxies") or []:
|
| 99 |
+
for key in ("dcCreator", "dcContributor"):
|
| 100 |
+
val = compact_text(proxy.get(key))
|
| 101 |
+
if val:
|
| 102 |
+
vals.append(val)
|
| 103 |
+
for key in ("dcCreator", "edmAgentLabel"):
|
| 104 |
+
val = compact_text(item.get(key))
|
| 105 |
+
if val:
|
| 106 |
+
vals.append(val)
|
| 107 |
+
return "; ".join(dict.fromkeys(vals))
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def created(record: dict, item: dict) -> str:
|
| 111 |
+
obj = record.get("object", {}) if isinstance(record.get("object"), dict) else {}
|
| 112 |
+
for proxy in obj.get("proxies") or []:
|
| 113 |
+
for key in ("year", "dctermsCreated", "dcDate", "dctermsIssued"):
|
| 114 |
+
val = compact_text(proxy.get(key))
|
| 115 |
+
if val:
|
| 116 |
+
return val
|
| 117 |
+
return compact_text(item.get("year") or item.get("timestamp_created_epoch"))
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def rights_uri(record: dict, item: dict) -> str:
|
| 121 |
+
obj = record.get("object", {}) if isinstance(record.get("object"), dict) else {}
|
| 122 |
+
aggs = obj.get("aggregations") or []
|
| 123 |
+
for agg in aggs:
|
| 124 |
+
val = compact_text(agg.get("edmRights"))
|
| 125 |
+
if val:
|
| 126 |
+
return val
|
| 127 |
+
return compact_text(item.get("rights"))
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def normalize_europeana_row(record: dict, item: dict) -> dict | None:
|
| 131 |
+
"""Normalize one API item only when its per-record rights are reusable."""
|
| 132 |
+
item_id = item.get("id")
|
| 133 |
+
if not item_id:
|
| 134 |
+
return None
|
| 135 |
+
rights = rights_uri(record, item)
|
| 136 |
+
if not rights_ok(rights):
|
| 137 |
+
return None
|
| 138 |
+
return {
|
| 139 |
+
"id": item_id.strip("/").replace("/", "_"),
|
| 140 |
+
"text": record_text(record, item),
|
| 141 |
+
"source_url": f"https://www.europeana.eu/item{item_id}",
|
| 142 |
+
"title": compact_text(item.get("title")),
|
| 143 |
+
"license": spdx(rights),
|
| 144 |
+
"rights_url": rights,
|
| 145 |
+
"author": creator(record, item),
|
| 146 |
+
"created": created(record, item),
|
| 147 |
+
"provider": compact_text(item.get("dataProvider") or item.get("provider")),
|
| 148 |
+
"raw_metadata": {"europeana_id": item_id, "rights": rights},
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def compress_jsonl(path: Path) -> Path:
|
| 153 |
+
out = path.with_suffix(path.suffix + ".zst")
|
| 154 |
+
subprocess.run(["zstd", "-19", "-f", "--rm", str(path), "-o", str(out)], check=True)
|
| 155 |
+
return out
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def main() -> None:
|
| 159 |
+
ap = argparse.ArgumentParser()
|
| 160 |
+
ap.add_argument("--api-key", default=os.environ.get("EUROPEANA_API_KEY", ""))
|
| 161 |
+
ap.add_argument("--query", default="*:*")
|
| 162 |
+
ap.add_argument("--qf", action="append", default=["LANGUAGE:pl"])
|
| 163 |
+
ap.add_argument("--out", default="data/upstream")
|
| 164 |
+
ap.add_argument("--rows", type=int, default=100)
|
| 165 |
+
ap.add_argument("--max-records", type=int, default=1000)
|
| 166 |
+
ap.add_argument("--delay", type=float, default=0.05)
|
| 167 |
+
ap.add_argument("--include-short", action="store_true")
|
| 168 |
+
ap.add_argument("--record-api", action="store_true",
|
| 169 |
+
help="fetch every Record API document too; slower, use only for metadata comparison")
|
| 170 |
+
args = ap.parse_args()
|
| 171 |
+
if not args.api_key:
|
| 172 |
+
raise SystemExit("Set EUROPEANA_API_KEY or pass --api-key. Use --api-key apidemo only for smoke tests.")
|
| 173 |
+
|
| 174 |
+
out_root = Path(args.out).expanduser()
|
| 175 |
+
raw_dir = out_root / KEY / "raw"
|
| 176 |
+
raw_dir.mkdir(parents=True, exist_ok=True)
|
| 177 |
+
audit_dir = Path("artifacts")
|
| 178 |
+
audit_dir.mkdir(exist_ok=True)
|
| 179 |
+
jsonl = raw_dir / f"{KEY}.jsonl"
|
| 180 |
+
|
| 181 |
+
session = requests.Session()
|
| 182 |
+
session.headers.update({"User-Agent": UA})
|
| 183 |
+
stats = Counter()
|
| 184 |
+
rights_stats = Counter()
|
| 185 |
+
examples = {"included": [], "dropped": []}
|
| 186 |
+
cursor = "*"
|
| 187 |
+
written = 0
|
| 188 |
+
|
| 189 |
+
with jsonl.open("w", encoding="utf-8") as fo:
|
| 190 |
+
while written < args.max_records:
|
| 191 |
+
params = {
|
| 192 |
+
"wskey": args.api_key,
|
| 193 |
+
"query": args.query,
|
| 194 |
+
"qf": args.qf,
|
| 195 |
+
"rows": min(args.rows, args.max_records - written),
|
| 196 |
+
"cursor": cursor,
|
| 197 |
+
"profile": "rich",
|
| 198 |
+
}
|
| 199 |
+
page = get_json(session, SEARCH_URL, params)
|
| 200 |
+
items = page.get("items") or []
|
| 201 |
+
if not items:
|
| 202 |
+
break
|
| 203 |
+
cursor = page.get("nextCursor") or cursor
|
| 204 |
+
for item in items:
|
| 205 |
+
stats["seen"] += 1
|
| 206 |
+
item_id = item.get("id")
|
| 207 |
+
if not item_id:
|
| 208 |
+
stats["drop_no_id"] += 1
|
| 209 |
+
continue
|
| 210 |
+
# Search ``profile=rich`` already contains rights, creator and
|
| 211 |
+
# descriptions. Avoiding a second API request per item turns
|
| 212 |
+
# a 1,000-record run from thousands of HTTP calls into a dozen
|
| 213 |
+
# paged calls while retaining per-record provenance. The
|
| 214 |
+
# Record API remains available for comparison/debugging.
|
| 215 |
+
rec = get_json(
|
| 216 |
+
session,
|
| 217 |
+
RECORD_URL.format(record_id=quote(item_id.strip("/"), safe="/")),
|
| 218 |
+
{"wskey": args.api_key},
|
| 219 |
+
) if args.record_api else item
|
| 220 |
+
rights = rights_uri(rec, item)
|
| 221 |
+
rights_stats[rights or ""] += 1
|
| 222 |
+
row = normalize_europeana_row(rec, item)
|
| 223 |
+
if row is None:
|
| 224 |
+
stats["drop_rights"] += 1
|
| 225 |
+
if len(examples["dropped"]) < 20:
|
| 226 |
+
examples["dropped"].append({"id": item_id, "rights": rights, "reason": "rights_not_open"})
|
| 227 |
+
continue
|
| 228 |
+
text = row["text"]
|
| 229 |
+
if len(text) < MIN_CHARS and not args.include_short:
|
| 230 |
+
stats["drop_short"] += 1
|
| 231 |
+
continue
|
| 232 |
+
fo.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 233 |
+
stats["included"] += 1
|
| 234 |
+
written += 1
|
| 235 |
+
if len(examples["included"]) < 20:
|
| 236 |
+
examples["included"].append({k: row.get(k) for k in ("id", "title", "license", "rights_url", "author", "created")})
|
| 237 |
+
if written >= args.max_records:
|
| 238 |
+
break
|
| 239 |
+
time.sleep(args.delay)
|
| 240 |
+
if not page.get("nextCursor") or cursor == "*":
|
| 241 |
+
break
|
| 242 |
+
|
| 243 |
+
zst_path = compress_jsonl(jsonl)
|
| 244 |
+
audit = {
|
| 245 |
+
"source": KEY,
|
| 246 |
+
"query": args.query,
|
| 247 |
+
"qf": args.qf,
|
| 248 |
+
"max_records": args.max_records,
|
| 249 |
+
"stats": dict(stats),
|
| 250 |
+
"rights_distribution": dict(rights_stats.most_common()),
|
| 251 |
+
"examples": examples,
|
| 252 |
+
"output": str(zst_path),
|
| 253 |
+
"policy": "include only PDM/CC0/CC-BY/CC-BY-SA via per-record edm:rights",
|
| 254 |
+
}
|
| 255 |
+
audit_json = audit_dir / "europeana_direct_rebuild_audit.json"
|
| 256 |
+
audit_json.write_text(json.dumps(audit, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 257 |
+
md = audit_dir / "europeana_direct_rebuild_audit.md"
|
| 258 |
+
md.write_text(
|
| 259 |
+
"# Europeana direct rebuild audit\n\n"
|
| 260 |
+
f"- Query: `{args.query}`\n"
|
| 261 |
+
f"- Output: `{zst_path}`\n"
|
| 262 |
+
f"- Seen: {stats['seen']}\n"
|
| 263 |
+
f"- Included: {stats['included']}\n"
|
| 264 |
+
f"- Dropped rights: {stats['drop_rights']}\n"
|
| 265 |
+
f"- Dropped short: {stats['drop_short']}\n\n"
|
| 266 |
+
"Rights distribution is stored in `europeana_direct_rebuild_audit.json`.\n",
|
| 267 |
+
encoding="utf-8",
|
| 268 |
+
)
|
| 269 |
+
print(json.dumps(audit["stats"], ensure_ascii=False, indent=2))
|
| 270 |
+
print(f"wrote {zst_path}")
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
if __name__ == "__main__":
|
| 274 |
+
main()
|
src/rights.py
CHANGED
|
@@ -23,7 +23,10 @@ def rights_ok(uri: str) -> bool:
|
|
| 23 |
def spdx(uri: str) -> str:
|
| 24 |
u = (uri or "").lower()
|
| 25 |
if "publicdomain/zero" in u: return "CC0-1.0"
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
if "/by-sa/" in u: return "CC-BY-SA-4.0"
|
| 28 |
if "/by/" in u: return "CC-BY-4.0"
|
| 29 |
return "UNKNOWN"
|
|
@@ -40,4 +43,5 @@ if __name__ == "__main__": # self-check
|
|
| 40 |
assert not rights_ok("")
|
| 41 |
assert spdx("http://creativecommons.org/licenses/by-sa/4.0/") == "CC-BY-SA-4.0"
|
| 42 |
assert spdx("http://creativecommons.org/publicdomain/zero/1.0/") == "CC0-1.0"
|
|
|
|
| 43 |
print("ok")
|
|
|
|
| 23 |
def spdx(uri: str) -> str:
|
| 24 |
u = (uri or "").lower()
|
| 25 |
if "publicdomain/zero" in u: return "CC0-1.0"
|
| 26 |
+
# PDM has no SPDX identifier. Use the explicit public-domain label that
|
| 27 |
+
# the source gate recognizes, while retaining the original rights URL in
|
| 28 |
+
# the record for legal traceability.
|
| 29 |
+
if "publicdomain/mark" in u: return "public-domain (PDM-1.0)"
|
| 30 |
if "/by-sa/" in u: return "CC-BY-SA-4.0"
|
| 31 |
if "/by/" in u: return "CC-BY-4.0"
|
| 32 |
return "UNKNOWN"
|
|
|
|
| 43 |
assert not rights_ok("")
|
| 44 |
assert spdx("http://creativecommons.org/licenses/by-sa/4.0/") == "CC-BY-SA-4.0"
|
| 45 |
assert spdx("http://creativecommons.org/publicdomain/zero/1.0/") == "CC0-1.0"
|
| 46 |
+
assert spdx("http://creativecommons.org/publicdomain/mark/1.0/") == "public-domain (PDM-1.0)"
|
| 47 |
print("ok")
|
src/sources.py
CHANGED
|
@@ -65,6 +65,23 @@ SOURCES = {
|
|
| 65 |
"created": "1991-01-01, 2019-12-31",
|
| 66 |
"is_ocr": False,
|
| 67 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
"wolne_lektury": {
|
| 69 |
"speakleash_key": "wolne_lektury_corpus",
|
| 70 |
"pretty": "Wolne Lektury (school readings)",
|
|
@@ -169,25 +186,6 @@ SOURCES = {
|
|
| 169 |
"created": "1918-01-01, 2025-12-31",
|
| 170 |
"is_ocr": False,
|
| 171 |
},
|
| 172 |
-
"1000_novels": {
|
| 173 |
-
"file_key": "1000_novels_corpus_CLARIN-PL",
|
| 174 |
-
"pretty": "1000 Novels Corpus (CLARIN-PL)",
|
| 175 |
-
"license": "CC-BY-4.0",
|
| 176 |
-
"license_spdx": "CC-BY-4.0",
|
| 177 |
-
"traceable": "The 1000 Novels Corpus is released under Creative Commons "
|
| 178 |
-
"Attribution 4.0 International by CLARIN-PL / Wrocław "
|
| 179 |
-
"University of Technology, with attribution to the corpus "
|
| 180 |
-
"authors and maintainers.",
|
| 181 |
-
"upstream": "https://clarin-pl.eu/dspace/handle/11321/312",
|
| 182 |
-
"provenance": "Pulled from SpeakLeash's public redistribution "
|
| 183 |
-
"(`speakleash-ds-pub`, key `1000_novels_corpus_CLARIN-PL`) "
|
| 184 |
-
"of the upstream CLARIN-PL source. SpeakLeash credited as "
|
| 185 |
-
"intermediate aggregator; upstream license/attribution "
|
| 186 |
-
"preserved.",
|
| 187 |
-
"domain": "literature",
|
| 188 |
-
"created": "unknown",
|
| 189 |
-
"is_ocr": False,
|
| 190 |
-
},
|
| 191 |
"biblioteka_nauki": {
|
| 192 |
"file_key": "biblioteka_nauki_pl_corpus",
|
| 193 |
"pretty": "Biblioteka Nauki",
|
|
@@ -198,17 +196,18 @@ SOURCES = {
|
|
| 198 |
"per-document `license` and `author` fields from the upstream "
|
| 199 |
"metadata collected by the source-specific rebuild script.",
|
| 200 |
"upstream": "https://bibliotekanauki.pl/",
|
| 201 |
-
"provenance": "Fetched directly from Biblioteka Nauki via
|
| 202 |
-
"
|
| 203 |
-
"
|
| 204 |
-
"
|
| 205 |
-
"schema.",
|
| 206 |
"domain": "academic",
|
| 207 |
"created": "unknown",
|
| 208 |
"is_ocr": False,
|
| 209 |
},
|
| 210 |
"europeana": {
|
| 211 |
-
|
|
|
|
|
|
|
| 212 |
"pretty": "Europeana Polish records",
|
| 213 |
"license": "per-record public-domain/open rights statement",
|
| 214 |
"license_spdx": "MIXED",
|
|
@@ -217,11 +216,10 @@ SOURCES = {
|
|
| 217 |
"status is jurisdiction-sensitive; downstream users must "
|
| 218 |
"check their local legal requirements.",
|
| 219 |
"upstream": "https://www.europeana.eu/",
|
| 220 |
-
"provenance": "Fetched directly from Europeana via
|
| 221 |
-
"
|
| 222 |
-
"
|
| 223 |
-
"
|
| 224 |
-
"evidence for release.",
|
| 225 |
"domain": "cultural heritage",
|
| 226 |
"created": "unknown",
|
| 227 |
"is_ocr": True,
|
|
@@ -233,7 +231,7 @@ SOURCES = {
|
|
| 233 |
},
|
| 234 |
}
|
| 235 |
|
| 236 |
-
ADDED = "2026-
|
| 237 |
EXCLUDED = {
|
| 238 |
"open_subtitles_corpus": "Derivative of copyrighted film/TV dialogue; "
|
| 239 |
"OpenSubtitles uploads largely unlicensed. Same copyright lesson as "
|
|
@@ -242,6 +240,9 @@ EXCLUDED = {
|
|
| 242 |
"per-record rights (PD / CC-BY-NC / rights-reserved). The raw "
|
| 243 |
"SpeakLeash redistribution is excluded; only a direct rebuild preserving "
|
| 244 |
"per-record rights metadata may be included.",
|
|
|
|
|
|
|
|
|
|
| 245 |
"project_gutenberg_pl_corpus": "Only 31 PL books (4.3MB) — PG is ~99% English; "
|
| 246 |
"Polish PD literature already covered by wolne_lektury + wikisource (so "
|
| 247 |
"near-redundant after dedup). Dropped to avoid the PD-in-EU per-work check "
|
|
|
|
| 65 |
"created": "1991-01-01, 2019-12-31",
|
| 66 |
"is_ocr": False,
|
| 67 |
},
|
| 68 |
+
"parlamint_pl": {
|
| 69 |
+
"file_key": "parlamint_pl",
|
| 70 |
+
"pretty": "ParlaMint-PL (parliamentary debates, 2015-2022)",
|
| 71 |
+
"license": "CC-BY-4.0",
|
| 72 |
+
"license_spdx": "CC-BY-4.0",
|
| 73 |
+
"traceable": "ParlaMint 3.0 corpora released under CC-BY 4.0 (CLARIN.SI "
|
| 74 |
+
"handle 11356/1486); parliamentary proceedings are also "
|
| 75 |
+
"official documents (PL art. 4 pr. aut.).",
|
| 76 |
+
"upstream": "http://hdl.handle.net/11356/1486",
|
| 77 |
+
"provenance": "Fetched directly from the CLARIN.SI plain-text edition "
|
| 78 |
+
"(ParlaMint-PL.tgz) by src/fetch_parlamint.py; one session "
|
| 79 |
+
"transcript per document, utterance IDs stripped. Modern "
|
| 80 |
+
"spoken register, complements the older PPC (1991-2019).",
|
| 81 |
+
"domain": "political/spoken",
|
| 82 |
+
"created": "2015-01-01, 2022-12-31",
|
| 83 |
+
"is_ocr": False,
|
| 84 |
+
},
|
| 85 |
"wolne_lektury": {
|
| 86 |
"speakleash_key": "wolne_lektury_corpus",
|
| 87 |
"pretty": "Wolne Lektury (school readings)",
|
|
|
|
| 186 |
"created": "1918-01-01, 2025-12-31",
|
| 187 |
"is_ocr": False,
|
| 188 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
"biblioteka_nauki": {
|
| 190 |
"file_key": "biblioteka_nauki_pl_corpus",
|
| 191 |
"pretty": "Biblioteka Nauki",
|
|
|
|
| 196 |
"per-document `license` and `author` fields from the upstream "
|
| 197 |
"metadata collected by the source-specific rebuild script.",
|
| 198 |
"upstream": "https://bibliotekanauki.pl/",
|
| 199 |
+
"provenance": "Fetched directly from Biblioteka Nauki via the contributor "
|
| 200 |
+
"rebuild script, not from the SpeakLeash redistribution. "
|
| 201 |
+
"License and author metadata are checked document by document "
|
| 202 |
+
"before normalization into the DynaWord schema.",
|
|
|
|
| 203 |
"domain": "academic",
|
| 204 |
"created": "unknown",
|
| 205 |
"is_ocr": False,
|
| 206 |
},
|
| 207 |
"europeana": {
|
| 208 |
+
# Direct rebuild output from fetch_europeana.py, never the raw
|
| 209 |
+
# SpeakLeash Europeana aggregate.
|
| 210 |
+
"file_key": "europeana",
|
| 211 |
"pretty": "Europeana Polish records",
|
| 212 |
"license": "per-record public-domain/open rights statement",
|
| 213 |
"license_spdx": "MIXED",
|
|
|
|
| 216 |
"status is jurisdiction-sensitive; downstream users must "
|
| 217 |
"check their local legal requirements.",
|
| 218 |
"upstream": "https://www.europeana.eu/",
|
| 219 |
+
"provenance": "Fetched directly from Europeana via the contributor rebuild "
|
| 220 |
+
"script, preserving per-record rights and creator metadata. "
|
| 221 |
+
"The raw SpeakLeash aggregate remains insufficient because "
|
| 222 |
+
"it does not carry enough rights evidence for release.",
|
|
|
|
| 223 |
"domain": "cultural heritage",
|
| 224 |
"created": "unknown",
|
| 225 |
"is_ocr": True,
|
|
|
|
| 231 |
},
|
| 232 |
}
|
| 233 |
|
| 234 |
+
ADDED = "2026-06-15"
|
| 235 |
EXCLUDED = {
|
| 236 |
"open_subtitles_corpus": "Derivative of copyrighted film/TV dialogue; "
|
| 237 |
"OpenSubtitles uploads largely unlicensed. Same copyright lesson as "
|
|
|
|
| 240 |
"per-record rights (PD / CC-BY-NC / rights-reserved). The raw "
|
| 241 |
"SpeakLeash redistribution is excluded; only a direct rebuild preserving "
|
| 242 |
"per-record rights metadata may be included.",
|
| 243 |
+
"1000_novels_corpus_CLARIN-PL": "CC-BY-4.0 label, but 'novels' likely include "
|
| 244 |
+
"in-copyright contemporary works; verify titles/years on CLARIN handle "
|
| 245 |
+
"11321/312 before inclusion.",
|
| 246 |
"project_gutenberg_pl_corpus": "Only 31 PL books (4.3MB) — PG is ~99% English; "
|
| 247 |
"Polish PD literature already covered by wolne_lektury + wikisource (so "
|
| 248 |
"near-redundant after dedup). Dropped to avoid the PD-in-EU per-work check "
|
src/test_europeana_contract.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""TDD contract for the direct Europeana ingestion path."""
|
| 2 |
+
import sys
|
| 3 |
+
import unittest
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 7 |
+
|
| 8 |
+
from fetch_europeana import normalize_europeana_row
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class EuropeanaContractTest(unittest.TestCase):
|
| 12 |
+
def test_open_record_keeps_rights_and_canonical_schema(self):
|
| 13 |
+
item = {
|
| 14 |
+
"id": "/123/item-1", "rights": ["https://creativecommons.org/licenses/by/4.0/"],
|
| 15 |
+
"dcDescription": ["Polski opis wystarczająco długi do testu." * 10],
|
| 16 |
+
"dcCreator": ["Autor Testowy"], "year": ["1912"], "title": ["Tytuł"],
|
| 17 |
+
}
|
| 18 |
+
row = normalize_europeana_row(item, item)
|
| 19 |
+
self.assertEqual(set(row), {"id", "text", "source_url", "title", "license", "rights_url", "author", "created", "provider", "raw_metadata"})
|
| 20 |
+
self.assertEqual(row["license"], "CC-BY-4.0")
|
| 21 |
+
self.assertEqual(row["author"], "Autor Testowy")
|
| 22 |
+
self.assertEqual(row["created"], "1912")
|
| 23 |
+
self.assertTrue(row["rights_url"].startswith("https://creativecommons.org/licenses/by/"))
|
| 24 |
+
|
| 25 |
+
def test_restricted_rights_are_not_normalized(self):
|
| 26 |
+
item = {"id": "/x", "rights": ["https://creativecommons.org/licenses/by-nc/4.0/"]}
|
| 27 |
+
self.assertIsNone(normalize_europeana_row(item, item))
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
unittest.main()
|