eurlex: drop the 92 IASB-notice documents (243,060 -> 242,968 docs, v0.2.6)

#82
by ppuzio - opened
artifacts/source_findings.md CHANGED
@@ -1928,16 +1928,19 @@ clause does not change a label here. Evidence in `data/wikinews/wikinews.license
1928
  documents; copyright pastes in news text (the audit's 100-document press-copying sample was
1929
  not run); the markup residue above.
1930
 
1931
- ## eurlex — relabelled to the EU reuse policy, third-party material reported (2026-10-06)
1932
 
1933
  **Investigated** — 2026-10-06 (October 2026 rights audit, polish-dynaword-v2 #57; lawyer
1934
  question #56 B5; `rights_audit_2026-10/reports/citations.md`).
1935
 
1936
- **Verdict** — kept and relabelled, nothing dropped: 243,060 documents, 5,976,949,249
1937
- characters, 2,378,055,718 tokens before and after. `CC-BY-4.0` becomes
 
1938
  `LicenseRef-EU-Reuse-Policy` in the per-row `license` column, the registry and the card,
1939
- by `src/clean_eurlex.py` (tested in `src/test_eurlex_contract.py`; all other columns are
1940
- identical). The Polish Copyright Act Art. 4 basis is removed from the card.
 
 
1941
 
1942
  **License evidence** — verified, read 2026-10-06: the EUR-Lex legal notice
1943
  (<https://eur-lex.europa.eu/content/legal-notice/legal-notice.html>, sha256 `7994b96f…`)
@@ -1952,13 +1955,14 @@ the Decision covers Commission documents, so acts of other institutions (Council
1952
  Parliament, ECB, EESC, CJEU) rest on the notice's general sentence. Evidence in
1953
  `data/eurlex/eurlex.license-evidence.json`.
1954
 
1955
- **Third-party check** — report only (`python3 src/clean_eurlex.py --scan`):
1956
  - 92 documents (74.1M characters, 1.24%) contain the IASB notice: reproduction allowed in
1957
  the EEA, all rights reserved outside it. They are 64 OJ acts adopting or amending
1958
  IAS/IFRS and 28 consolidated versions (20 of Regulation 1126/2008). The notice is the
1959
  "special conditions of use" the legal notice names for the International Accounting
1960
  Standards. All 92 matched lines and all 64 titles hand-checked. Two more documents have
1961
  a standard title line without the notice (67,283 characters) and were not counted.
 
1962
  - 97 documents contain a (c) sign; 33 are third-party credits or short data citations
1963
  (photographs, maps, OECD, IHS Markit, McKinsey, Springer), 25 EU credits, 7 binary
1964
  garbage, 32 glyph noise or list markers. Labelled by reading the first occurrence in
@@ -1971,9 +1975,9 @@ Parliament, ECB, EESC, CJEU) rest on the notice's general sentence. Evidence in
1971
  - No large-scale reproduction of non-EU copyrighted works was found. Recall for third-party
1972
  text the patterns do not target is unknown.
1973
 
1974
- **Blockers** — none to merge. Open decision for the maintainer: keep the 92 IASB-notice
1975
- documents (the notice reserves rights outside the EEA, and the Hub is not EEA-limited) or
1976
- drop them. Ids are in `data/eurlex/eurlex.third-party-scan.json`.
1977
 
1978
  **Not established** — SpeakLeash's terms for `eurlex_corpus`; whether the ECB, EESC,
1979
  Council, Parliament and the Court of Justice publish reuse terms of their own; the
 
1928
  documents; copyright pastes in news text (the audit's 100-document press-copying sample was
1929
  not run); the markup residue above.
1930
 
1931
+ ## eurlex — relabelled to the EU reuse policy, 92 IASB documents dropped (2026-10-06)
1932
 
1933
  **Investigated** — 2026-10-06 (October 2026 rights audit, polish-dynaword-v2 #57; lawyer
1934
  question #56 B5; `rights_audit_2026-10/reports/citations.md`).
1935
 
1936
+ **Verdict** — kept and relabelled, the 92 IASB-notice documents dropped (maintainer
1937
+ decision 2026-10-06): 243,060 -> 242,968 documents, 5,976,949,249 -> 5,902,889,135
1938
+ characters, 2,378,055,718 -> 2,350,709,056 tokens. `CC-BY-4.0` becomes
1939
  `LicenseRef-EU-Reuse-Policy` in the per-row `license` column, the registry and the card,
1940
+ by `src/clean_eurlex.py` (tested in `src/test_eurlex_contract.py`; every kept row is
1941
+ otherwise identical to v0.2.5). The drop is pinned to the 92 hand-checked ids and fails
1942
+ closed if the IASB rule and the list disagree. The Polish Copyright Act Art. 4 basis is
1943
+ removed from the card.
1944
 
1945
  **License evidence** — verified, read 2026-10-06: the EUR-Lex legal notice
1946
  (<https://eur-lex.europa.eu/content/legal-notice/legal-notice.html>, sha256 `7994b96f…`)
 
1955
  Parliament, ECB, EESC, CJEU) rest on the notice's general sentence. Evidence in
1956
  `data/eurlex/eurlex.license-evidence.json`.
1957
 
1958
+ **Third-party check** — `python3 src/clean_eurlex.py --scan` on the v0.2.5 input:
1959
  - 92 documents (74.1M characters, 1.24%) contain the IASB notice: reproduction allowed in
1960
  the EEA, all rights reserved outside it. They are 64 OJ acts adopting or amending
1961
  IAS/IFRS and 28 consolidated versions (20 of Regulation 1126/2008). The notice is the
1962
  "special conditions of use" the legal notice names for the International Accounting
1963
  Standards. All 92 matched lines and all 64 titles hand-checked. Two more documents have
1964
  a standard title line without the notice (67,283 characters) and were not counted.
1965
+ Dropped. None of the 92 is in the (c)-sign or header counts below, so those are unchanged.
1966
  - 97 documents contain a (c) sign; 33 are third-party credits or short data citations
1967
  (photographs, maps, OECD, IHS Markit, McKinsey, Springer), 25 EU credits, 7 binary
1968
  garbage, 32 glyph noise or list markers. Labelled by reading the first occurrence in
 
1975
  - No large-scale reproduction of non-EU copyrighted works was found. Recall for third-party
1976
  text the patterns do not target is unknown.
1977
 
1978
+ **Blockers** — none to merge. The notice reserves rights outside the EEA and the Hub is not
1979
+ EEA-limited, so the 92 documents were dropped; the (c)-sign and header documents are kept.
1980
+ Ids are in `data/eurlex/eurlex.third-party-scan.json`.
1981
 
1982
  **Not established** — SpeakLeash's terms for `eurlex_corpus`; whether the ECB, EESC,
1983
  Council, Parliament and the Court of Justice publish reuse terms of their own; the
data/eurlex/eurlex.license-evidence.json CHANGED
@@ -51,11 +51,14 @@
51
  "parquet": {
52
  "v0_2_5_sha256": "5f151d57c20103f5488fd7f1b6c108311b648e4c7ed1ff02ef7a376be5c92f04",
53
  "v0_2_5_bytes": 1691883292,
54
- "after_relabel_sha256": "44cc0dfb0c73c1462635cebc23ed7c1f46e6c509e57e118477a8cfc7cc74c84c",
55
- "rows": 243060,
56
- "chars": 5976949249,
57
- "tokens": 2378055718,
58
- "change": "per-row license column CC-BY-4.0 -> LicenseRef-EU-Reuse-Policy (src/clean_eurlex.py); all other columns identical, no row dropped"
 
 
 
59
  },
60
  "document_kinds_heuristic": {
61
  "method": "first 200 characters of each document",
@@ -73,13 +76,14 @@
73
  "note": "17,229 consolidated texts (29.0% of characters) are within the notice's CC BY 4.0 grant as well; the single corpus label does not claim CC BY 4.0 for the rest"
74
  },
75
  "third_party_check": {
76
- "report_only": true,
77
- "dropped": 0,
78
- "scan": "data/eurlex/eurlex.third-party-scan.json (src/clean_eurlex.py --scan)",
79
  "iasb_notice": {
80
  "documents": 92,
81
  "characters": 74060114,
82
  "share_of_characters": 0.01239,
 
83
  "what": "Documents carrying the IASB notice (reproduction allowed within the EEA, all rights reserved outside it): 64 OJ acts adopting or amending IAS/IFRS and 28 consolidated versions (20 of Regulation 1126/2008, 6 of 1725/2003, 1 of 475/2012, 1 of 1361/2014). The notice sits in the reproduced standards; the rest of each document is EU text.",
84
  "hand_check": "All 92 matched lines read: each is the IASB notice (11 distinct line forms, including whitespace and quote-mark variants). All 64 non-consolidated titles concern IAS/IFRS or accounting.",
85
  "cross_check": "2 further documents have a standard-title line without the notice (eurlex_1848316, eurlex_2024404; 67,283 characters): not counted.",
@@ -143,7 +147,8 @@
143
  "un_ece_regulation": 253,
144
  "note": "Not third-party under the notice by themselves: they are texts of EU bodies or Commission notices. They matter only if those bodies' reuse terms differ (not checked). The audit's rough shares (ECB ~4%, state aid ~2.5%) do not reproduce with these patterns."
145
  },
146
- "not_found": "No large-scale reproduction of non-EU copyrighted works was found by these patterns. Recall for third-party text they do not target is unknown (Inferred)."
 
147
  },
148
  "not_checked": [
149
  "SpeakLeash's terms for eurlex_corpus",
 
51
  "parquet": {
52
  "v0_2_5_sha256": "5f151d57c20103f5488fd7f1b6c108311b648e4c7ed1ff02ef7a376be5c92f04",
53
  "v0_2_5_bytes": 1691883292,
54
+ "v0_2_5_rows": 243060,
55
+ "v0_2_5_chars": 5976949249,
56
+ "v0_2_5_tokens": 2378055718,
57
+ "after_sha256": "17e4112c40d2f961f01e6c4c0b31157c77d5ba89b4c86935d19a82fe0496a2ef",
58
+ "rows": 242968,
59
+ "chars": 5902889135,
60
+ "tokens": 2350709056,
61
+ "change": "per-row license column CC-BY-4.0 -> LicenseRef-EU-Reuse-Policy and the 92 IASB-notice documents dropped (src/clean_eurlex.py); every kept row is otherwise identical to v0.2.5"
62
  },
63
  "document_kinds_heuristic": {
64
  "method": "first 200 characters of each document",
 
76
  "note": "17,229 consolidated texts (29.0% of characters) are within the notice's CC BY 4.0 grant as well; the single corpus label does not claim CC BY 4.0 for the rest"
77
  },
78
  "third_party_check": {
79
+ "report_only": false,
80
+ "dropped": 92,
81
+ "scan": "data/eurlex/eurlex.third-party-scan.json (src/clean_eurlex.py --scan, on the v0.2.5 input; its iasb_notice_ids is the pinned drop list)",
82
  "iasb_notice": {
83
  "documents": 92,
84
  "characters": 74060114,
85
  "share_of_characters": 0.01239,
86
+ "tokens": 27346662,
87
  "what": "Documents carrying the IASB notice (reproduction allowed within the EEA, all rights reserved outside it): 64 OJ acts adopting or amending IAS/IFRS and 28 consolidated versions (20 of Regulation 1126/2008, 6 of 1725/2003, 1 of 475/2012, 1 of 1361/2014). The notice sits in the reproduced standards; the rest of each document is EU text.",
88
  "hand_check": "All 92 matched lines read: each is the IASB notice (11 distinct line forms, including whitespace and quote-mark variants). All 64 non-consolidated titles concern IAS/IFRS or accounting.",
89
  "cross_check": "2 further documents have a standard-title line without the notice (eurlex_1848316, eurlex_2024404; 67,283 characters): not counted.",
 
147
  "un_ece_regulation": 253,
148
  "note": "Not third-party under the notice by themselves: they are texts of EU bodies or Commission notices. They matter only if those bodies' reuse terms differ (not checked). The audit's rough shares (ECB ~4%, state aid ~2.5%) do not reproduce with these patterns."
149
  },
150
+ "not_found": "No large-scale reproduction of non-EU copyrighted works was found by these patterns. Recall for third-party text they do not target is unknown (Inferred).",
151
+ "decision": "2026-10-06, maintainer: drop the 92 IASB-notice documents (Hub PR 71). The (c)-sign and author-header documents are reported only and kept."
152
  },
153
  "not_checked": [
154
  "SpeakLeash's terms for eurlex_corpus",
data/eurlex/eurlex.md CHANGED
@@ -19,18 +19,18 @@ Pulled from SpeakLeash's public redistribution (`speakleash-ds-pub`, key `eurlex
19
  ## Statistics
20
  | documents | characters | tokens (tiktoken proxy) |
21
  |---:|---:|---:|
22
- | 243,060 | 5,976,949,249 | 2,378,055,718 |
23
 
24
 
25
  ## Per-document license metadata
26
  | license | documents |
27
  |---|---:|
28
- | `LicenseRef-EU-Reuse-Policy` | 243,060 |
29
 
30
  Author metadata present for **0** documents. Empty values mean the upstream record did not expose a machine-readable author field.
31
 
32
  ## Legal scope note
33
- Third-party material is not covered. The notice and Decision 2011/833/EU Art. 2(2)(a)-(b) exclude documents covered by industrial property rights or third-party intellectual property rights, and the notice says the International Accounting Standards may carry special conditions of use. 92 documents (74.1M characters, 1.24%) contain the IASB notice allowing reproduction within the EEA and reserving all rights outside it: 64 Official Journal acts adopting or amending IAS/IFRS and 28 consolidated versions (Regulations 1126/2008, 1725/2003, 475/2012, 1361/2014). 97 documents contain a (c) sign; 33 of them are third-party credits or short data citations (photographs, maps, OECD, IHS Markit, McKinsey, Springer), the rest EU credits or extraction noise. Nothing was removed. Ids and counts are in `eurlex.third-party-scan.json` and `eurlex.license-evidence.json`; recall for third-party text the patterns do not target is unknown. Decision 2011/833/EU itself covers documents held by the Commission or the Publications Office; acts of other institutions (Council, Parliament, ECB, EESC, CJEU) rest on the notice's general sentence alone, and whether those bodies publish their own reuse terms was not checked.
34
 
35
  Statistics were recomputed directly from the released parquet file.
36
 
@@ -40,7 +40,7 @@ Minimal, per Dynaword guidelines (heavy filtering left to downstream use):
40
  - drop non-Polish (diacritic ratio): **0**
41
  - exact cross-source dedup (sha1): **0**
42
  - OCR alpha-ratio < 0.70 (OCR sources only): **0**
43
- - read 243,060 → kept 243,060
44
 
45
  Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
46
  Llama-3 count is computed at release.
 
19
  ## Statistics
20
  | documents | characters | tokens (tiktoken proxy) |
21
  |---:|---:|---:|
22
+ | 242,968 | 5,902,889,135 | 2,350,709,056 |
23
 
24
 
25
  ## Per-document license metadata
26
  | license | documents |
27
  |---|---:|
28
+ | `LicenseRef-EU-Reuse-Policy` | 242,968 |
29
 
30
  Author metadata present for **0** documents. Empty values mean the upstream record did not expose a machine-readable author field.
31
 
32
  ## Legal scope note
33
+ Third-party material is not covered. The notice and Decision 2011/833/EU Art. 2(2)(a)-(b) exclude documents covered by industrial property rights or third-party intellectual property rights, and the notice says the International Accounting Standards may carry special conditions of use. 92 documents (74.1M characters, 1.24% of v0.2.5) carried the IASB notice allowing reproduction within the EEA and reserving all rights outside it: 64 Official Journal acts adopting or amending IAS/IFRS and 28 consolidated versions (Regulations 1126/2008, 1725/2003, 475/2012, 1361/2014). They were removed in v0.2.6 (243,060 -> 242,968 documents). 97 documents contain a (c) sign; 33 of them are third-party credits or short data citations (photographs, maps, OECD, IHS Markit, McKinsey, Springer), the rest EU credits or extraction noise; they were kept. Ids and counts are in `eurlex.third-party-scan.json` and `eurlex.license-evidence.json`; recall for third-party text the patterns do not target is unknown. Decision 2011/833/EU itself covers documents held by the Commission or the Publications Office; acts of other institutions (Council, Parliament, ECB, EESC, CJEU) rest on the notice's general sentence alone, and whether those bodies publish their own reuse terms was not checked.
34
 
35
  Statistics were recomputed directly from the released parquet file.
36
 
 
40
  - drop non-Polish (diacritic ratio): **0**
41
  - exact cross-source dedup (sha1): **0**
42
  - OCR alpha-ratio < 0.70 (OCR sources only): **0**
43
+ - read 243,060 → kept 242,968
44
 
45
  Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
46
  Llama-3 count is computed at release.
data/eurlex/eurlex.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:44cc0dfb0c73c1462635cebc23ed7c1f46e6c509e57e118477a8cfc7cc74c84c
3
- size 1691885842
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:17e4112c40d2f961f01e6c4c0b31157c77d5ba89b4c86935d19a82fe0496a2ef
3
+ size 1671120091
data/eurlex/eurlex.stats.json CHANGED
@@ -1,16 +1,17 @@
1
  {
2
  "read": 243060,
3
- "kept": 243060,
4
  "drop_short": 0,
5
  "drop_lang": 0,
6
  "drop_dup": 0,
7
  "drop_ocr": 0,
8
- "chars": 5976949249,
9
- "tokens": 2378055718,
10
  "licenses": {
11
- "LicenseRef-EU-Reuse-Policy": 243060
12
  },
13
  "authors_with_value": 0,
14
  "license": "LicenseRef-EU-Reuse-Policy",
15
- "stats_recomputed_from_parquet": true
 
16
  }
 
1
  {
2
  "read": 243060,
3
+ "kept": 242968,
4
  "drop_short": 0,
5
  "drop_lang": 0,
6
  "drop_dup": 0,
7
  "drop_ocr": 0,
8
+ "chars": 5902889135,
9
+ "tokens": 2350709056,
10
  "licenses": {
11
+ "LicenseRef-EU-Reuse-Policy": 242968
12
  },
13
  "authors_with_value": 0,
14
  "license": "LicenseRef-EU-Reuse-Policy",
15
+ "stats_recomputed_from_parquet": true,
16
+ "drop_iasb_notice": 92
17
  }
src/clean_eurlex.py CHANGED
@@ -1,16 +1,20 @@
1
  #!/usr/bin/env python3
2
  """eurlex rights-audit actions (slayerlabs/polish-dynaword-v2#57).
3
 
4
- relabel (default): the v0.2.5 release labelled every row `CC-BY-4.0`. The EUR-Lex legal
5
  notice licenses under CC BY 4.0 only "the editorial content of this website, the summaries
6
  of EU legislation and the consolidated texts"; the legal documents themselves are reusable
7
  under the Commission's reuse policy (Decision 2011/833/EU). Rewrites the per-row `license`
8
- column to `LicenseRef-EU-Reuse-Policy` and recomputes `eurlex.stats.json` with
9
- `normalize_schema.normalize_one`. No row is dropped or edited. Raises, and leaves the
10
- parquet as it was, if any row carries a licence other than the old or the new label.
 
 
 
11
 
12
  --scan: report-only count of documents the notice's third-party / special-conditions
13
- exclusions may reach. Writes `data/eurlex/eurlex.third-party-scan.json`. Nothing is dropped.
 
14
  The regexes are heuristics: counts are lower bounds on what they target, and recall for
15
  third-party text they do not target is unknown.
16
 
@@ -58,28 +62,57 @@ HEADER_RULES = {
58
  }
59
 
60
 
61
- def relabel(path: Path = PARQUET, old: str = OLD_LICENSE, new: str = NEW_LICENSE) -> dict:
62
- """Rewrite `license` of every row to `new`, then recompute stats. Returns the stats."""
 
 
 
 
 
 
 
 
 
 
 
 
63
  tmp = path.with_suffix(".parquet.tmp")
64
  pf = pq.ParquetFile(path)
65
  schema = pf.schema_arrow
66
  index = schema.get_field_index("license")
67
  writer = pq.ParquetWriter(tmp, schema, compression="zstd")
 
68
  try:
69
  for batch in pf.iter_batches(batch_size=BATCH):
70
  tbl = pa.Table.from_batches([batch])
71
  found = set(pc.unique(tbl["license"]).to_pylist())
72
  if not found <= {old, new}:
73
  raise ValueError(f"{path.name}: unexpected licence(s) {sorted(map(str, found - {old, new}))}")
 
 
 
 
 
 
 
 
 
74
  tbl = tbl.set_column(index, schema.field(index), pa.array([new] * tbl.num_rows, type=pa.string()))
75
  writer.write_table(tbl)
 
 
 
76
  writer.close()
77
  tmp.replace(path)
78
  except BaseException:
79
  writer.close()
80
  tmp.unlink(missing_ok=True)
81
  raise
82
- return normalize_one(path)
 
 
 
 
83
 
84
 
85
  def scan(path: Path = PARQUET) -> dict:
@@ -113,11 +146,15 @@ def main() -> None:
113
  args = ap.parse_args()
114
  if args.scan:
115
  result = scan(args.parquet)
 
 
 
116
  SCAN_JSON.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
117
  print(json.dumps({k: v for k, v in result.items() if k != "iasb_notice_ids"}, ensure_ascii=False, indent=2))
118
  else:
119
- stats = relabel(args.parquet)
120
- print(f"{SOURCE}: {stats['kept']:,} docs | {stats['tokens']:,} tokens | licences {stats['licenses']}")
 
121
 
122
 
123
  if __name__ == "__main__":
 
1
  #!/usr/bin/env python3
2
  """eurlex rights-audit actions (slayerlabs/polish-dynaword-v2#57).
3
 
4
+ clean (default): the v0.2.5 release labelled every row `CC-BY-4.0`. The EUR-Lex legal
5
  notice licenses under CC BY 4.0 only "the editorial content of this website, the summaries
6
  of EU legislation and the consolidated texts"; the legal documents themselves are reusable
7
  under the Commission's reuse policy (Decision 2011/833/EU). Rewrites the per-row `license`
8
+ column to `LicenseRef-EU-Reuse-Policy`, drops the 92 hand-checked documents carrying the
9
+ IASB notice (all rights reserved outside the EEA; maintainer decision 2026-10-06), and
10
+ recomputes `eurlex.stats.json` with `normalize_schema.normalize_one`. No kept row is edited
11
+ except its `license`. Raises, and leaves the parquet as it was, if any row carries a licence
12
+ other than the old or the new label, if a row carries the IASB notice but is not in the
13
+ pinned list, or if a pinned id is missing from the input or lacks the notice.
14
 
15
  --scan: report-only count of documents the notice's third-party / special-conditions
16
+ exclusions may reach, read from the v0.2.5 input. Writes `data/eurlex/eurlex.third-party-scan.json`,
17
+ whose `iasb_notice_ids` is the pinned drop list; it refuses to change a pinned list.
18
  The regexes are heuristics: counts are lower bounds on what they target, and recall for
19
  third-party text they do not target is unknown.
20
 
 
62
  }
63
 
64
 
65
+ def pinned_iasb_ids(path: Path = SCAN_JSON) -> frozenset[str]:
66
+ """The hand-checked IASB-notice ids recorded by --scan on the v0.2.5 input."""
67
+ return frozenset(json.loads(path.read_text())["iasb_notice_ids"])
68
+
69
+
70
+ def clean(path: Path = PARQUET, withhold: frozenset[str] | None = None,
71
+ old: str = OLD_LICENSE, new: str = NEW_LICENSE) -> dict:
72
+ """Rewrite `license` of every row to `new`, drop the `withhold` rows, then recompute stats.
73
+
74
+ `withhold` defaults to `pinned_iasb_ids()`. Each row must carry the IASB notice exactly when
75
+ its id is in `withhold`, and every `withhold` id must be in the input. Returns the stats.
76
+ """
77
+ withhold = pinned_iasb_ids() if withhold is None else withhold
78
+ iasb = WHOLE_TEXT_RULES["iasb_notice"]
79
  tmp = path.with_suffix(".parquet.tmp")
80
  pf = pq.ParquetFile(path)
81
  schema = pf.schema_arrow
82
  index = schema.get_field_index("license")
83
  writer = pq.ParquetWriter(tmp, schema, compression="zstd")
84
+ dropped: set[str] = set()
85
  try:
86
  for batch in pf.iter_batches(batch_size=BATCH):
87
  tbl = pa.Table.from_batches([batch])
88
  found = set(pc.unique(tbl["license"]).to_pylist())
89
  if not found <= {old, new}:
90
  raise ValueError(f"{path.name}: unexpected licence(s) {sorted(map(str, found - {old, new}))}")
91
+ keep = []
92
+ for doc_id, text in zip(tbl["id"].to_pylist(), tbl["text"].to_pylist()):
93
+ notice, listed = iasb.search(text) is not None, doc_id in withhold
94
+ if notice != listed:
95
+ raise ValueError(f"{path.name}: {doc_id} has IASB notice={notice} but pinned={listed}")
96
+ if listed:
97
+ dropped.add(doc_id)
98
+ keep.append(not listed)
99
+ tbl = tbl.filter(pa.array(keep))
100
  tbl = tbl.set_column(index, schema.field(index), pa.array([new] * tbl.num_rows, type=pa.string()))
101
  writer.write_table(tbl)
102
+ if missing := withhold - dropped:
103
+ raise ValueError(f"{path.name}: {len(missing)} pinned id(s) not in the input, e.g. {sorted(missing)[:3]}; "
104
+ "restore the v0.2.5 input first")
105
  writer.close()
106
  tmp.replace(path)
107
  except BaseException:
108
  writer.close()
109
  tmp.unlink(missing_ok=True)
110
  raise
111
+ stats = normalize_one(path)
112
+ stats["read"] += len(dropped)
113
+ stats["drop_iasb_notice"] = len(dropped)
114
+ path.with_name(f"{SOURCE}.stats.json").write_text(json.dumps(stats, ensure_ascii=False, indent=2) + "\n")
115
+ return stats
116
 
117
 
118
  def scan(path: Path = PARQUET) -> dict:
 
146
  args = ap.parse_args()
147
  if args.scan:
148
  result = scan(args.parquet)
149
+ if SCAN_JSON.exists() and (pinned := pinned_iasb_ids(SCAN_JSON)) and pinned != set(result["iasb_notice_ids"]):
150
+ raise SystemExit(f"{SCAN_JSON.name} pins {len(pinned)} IASB ids, this input has "
151
+ f"{len(result['iasb_notice_ids'])}: --scan reads the v0.2.5 input (see the docstring)")
152
  SCAN_JSON.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
153
  print(json.dumps({k: v for k, v in result.items() if k != "iasb_notice_ids"}, ensure_ascii=False, indent=2))
154
  else:
155
+ stats = clean(args.parquet)
156
+ print(f"{SOURCE}: {stats['read']:,} -> {stats['kept']:,} docs (IASB dropped {stats['drop_iasb_notice']}) | "
157
+ f"{stats['tokens']:,} tokens | licences {stats['licenses']}")
158
 
159
 
160
  if __name__ == "__main__":
src/sources.py CHANGED
@@ -232,13 +232,14 @@ SOURCES = {
232
  "Art. 2(2)(a)-(b) exclude documents covered by industrial property rights "
233
  "or third-party intellectual property rights, and the notice says the "
234
  "International Accounting Standards may carry special conditions of use. "
235
- "92 documents (74.1M characters, 1.24%) contain the IASB notice allowing "
236
- "reproduction within the EEA and reserving all rights outside it: 64 "
237
- "Official Journal acts adopting or amending IAS/IFRS and 28 consolidated "
238
- "versions (Regulations 1126/2008, 1725/2003, 475/2012, 1361/2014). 97 "
239
- "documents contain a (c) sign; 33 of them are third-party credits or short "
240
- "data citations (photographs, maps, OECD, IHS Markit, McKinsey, Springer), "
241
- "the rest EU credits or extraction noise. Nothing was removed. Ids and "
 
242
  "counts are in `eurlex.third-party-scan.json` and "
243
  "`eurlex.license-evidence.json`; recall for third-party text the patterns "
244
  "do not target is unknown. Decision 2011/833/EU itself covers documents "
 
232
  "Art. 2(2)(a)-(b) exclude documents covered by industrial property rights "
233
  "or third-party intellectual property rights, and the notice says the "
234
  "International Accounting Standards may carry special conditions of use. "
235
+ "92 documents (74.1M characters, 1.24% of v0.2.5) carried the IASB notice "
236
+ "allowing reproduction within the EEA and reserving all rights outside it: "
237
+ "64 Official Journal acts adopting or amending IAS/IFRS and 28 consolidated "
238
+ "versions (Regulations 1126/2008, 1725/2003, 475/2012, 1361/2014). They "
239
+ "were removed in v0.2.6 (243,060 -> 242,968 documents). 97 documents "
240
+ "contain a (c) sign; 33 of them are third-party credits or short data "
241
+ "citations (photographs, maps, OECD, IHS Markit, McKinsey, Springer), the "
242
+ "rest EU credits or extraction noise; they were kept. Ids and "
243
  "counts are in `eurlex.third-party-scan.json` and "
244
  "`eurlex.license-evidence.json`; recall for third-party text the patterns "
245
  "do not target is unknown. Decision 2011/833/EU itself covers documents "
src/test_eurlex_contract.py CHANGED
@@ -1,4 +1,4 @@
1
- """Contract tests for the eurlex licence relabel (slayerlabs/polish-dynaword-v2#57)."""
2
  from __future__ import annotations
3
 
4
  import hashlib
@@ -19,7 +19,8 @@ from clean_eurlex import (
19
  NEW_LICENSE,
20
  OLD_LICENSE,
21
  WHOLE_TEXT_RULES,
22
- relabel,
 
23
  scan,
24
  )
25
  from normalize_schema import SCHEMA, string_len_sum
@@ -42,42 +43,66 @@ def row(i: int, text: str = "Rozporządzenie. " * 20, license: str = OLD_LICENSE
42
 
43
 
44
  # normalize_one reads the registry entry by directory name, so the fixture lives in <tmp>/eurlex/.
 
 
 
 
45
  @pytest.fixture
46
  def parquet(tmp_path):
47
- return write_parquet(tmp_path / "eurlex" / "eurlex.parquet", [row(0), row(1), row(2, license=NEW_LICENSE)])
 
 
 
 
 
 
 
 
 
 
48
 
49
 
50
- def test_relabel_changes_only_the_license_column(parquet):
51
  before = pq.read_table(parquet)
52
- stats = relabel(parquet)
53
  after = pq.read_table(parquet)
 
54
 
55
  assert after.schema == before.schema
 
56
  assert after["license"].to_pylist() == [NEW_LICENSE] * 3
57
  for name in before.schema.names:
58
  if name != "license":
59
- assert after[name].equals(before[name]), name
60
- assert stats["kept"] == 3
61
  assert stats["licenses"] == {NEW_LICENSE: 3}
62
  assert stats["license"] == NEW_LICENSE == CFG["license"]
63
- assert stats["chars"] == string_len_sum(before["text"])
64
- assert stats["tokens"] == sum(before["token_count"].to_pylist())
65
  assert json.loads(parquet.with_name("eurlex.stats.json").read_text()) == stats
66
  assert not parquet.with_suffix(".parquet.tmp").exists()
67
 
68
 
69
- def test_relabel_is_idempotent(parquet):
70
- first = relabel(parquet)
71
- assert relabel(parquet) == first
 
 
 
72
 
73
 
74
- def test_relabel_refuses_an_unexpected_license_and_leaves_the_file_alone(tmp_path):
 
 
 
 
 
 
 
 
 
75
  path = write_parquet(tmp_path / "eurlex" / "eurlex.parquet", [row(0), row(1, license="CC-BY-SA-4.0")])
76
- digest = hashlib.sha256(path.read_bytes()).hexdigest()
77
- with pytest.raises(ValueError, match="CC-BY-SA-4.0"):
78
- relabel(path)
79
- assert hashlib.sha256(path.read_bytes()).hexdigest() == digest
80
- assert not path.with_suffix(".parquet.tmp").exists()
81
 
82
 
83
  # The three wordings of the IASB notice in the corpus (Polish text of the OJ), and text that must not match.
@@ -133,6 +158,22 @@ def test_scan_counts_documents_per_rule(tmp_path):
133
  assert rules["iasb_notice"]["chars"] == len(pq.read_table(path)["text"][0].as_py())
134
 
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  def test_registry_label_and_basis():
137
  assert CFG["license"] == CFG["license_spdx"] == NEW_LICENSE
138
  assert CFG["release"] == "0.2.0"
@@ -164,14 +205,17 @@ def test_release_artifact_matches_label_stats_and_evidence():
164
  assert sources == {"eurlex"}
165
  assert (rows, chars, tokens) == (stats["kept"], stats["chars"], stats["tokens"])
166
  assert stats["licenses"] == {CFG["license"]: rows} and stats["license"] == CFG["license"]
167
- # the relabel drops nothing: same totals as v0.2.5
168
- assert (rows, chars, tokens) == (243060, 5976949249, 2378055718)
 
 
 
169
 
170
  digest = hashlib.sha256()
171
  with open(path, "rb") as handle:
172
  for block in iter(lambda: handle.read(1 << 24), b""):
173
  digest.update(block)
174
- assert digest.hexdigest() == evidence["parquet"]["after_relabel_sha256"]
175
 
176
 
177
  def test_evidence_and_scan_agree():
@@ -180,15 +224,21 @@ def test_evidence_and_scan_agree():
180
  check = evidence["third_party_check"]
181
 
182
  assert evidence["label"] == CFG["license"] and evidence["previous_label"] == OLD_LICENSE
183
- assert check["dropped"] == 0
184
  assert check["iasb_notice"]["documents"] == result["rules"]["iasb_notice"]["docs"] == len(result["iasb_notice_ids"])
 
185
  assert check["iasb_notice"]["characters"] == result["rules"]["iasb_notice"]["chars"]
186
  assert check["copyright_sign"]["documents"] == result["rules"]["copyright_sign"]["docs"]
187
  third_party = check["copyright_sign"]["hand_labelled_third_party_credit_or_citation"]
188
  assert len(third_party) == len(set(third_party)) == check["copyright_sign"]["hand_labelled_third_party_count"]
189
  for name in ("ecb_act", "eesc", "state_aid_sa", "un_ece_regulation"):
190
  assert check["author_header_categories"][name] == result["rules"][name]["docs"]
191
- assert (result["rows"], result["chars"]) == (evidence["parquet"]["rows"], evidence["parquet"]["chars"])
 
 
 
 
 
192
 
193
  urls = [doc["url"] for doc in evidence["reuse_basis"]["documents"]]
194
  assert urls == ["https://eur-lex.europa.eu/content/legal-notice/legal-notice.html",
 
1
+ """Contract tests for the eurlex licence relabel and IASB drop (slayerlabs/polish-dynaword-v2#57)."""
2
  from __future__ import annotations
3
 
4
  import hashlib
 
19
  NEW_LICENSE,
20
  OLD_LICENSE,
21
  WHOLE_TEXT_RULES,
22
+ clean,
23
+ pinned_iasb_ids,
24
  scan,
25
  )
26
  from normalize_schema import SCHEMA, string_len_sum
 
43
 
44
 
45
  # normalize_one reads the registry entry by directory name, so the fixture lives in <tmp>/eurlex/.
46
+ # eurlex_3 carries the IASB notice and is the one pinned id.
47
+ PINNED = frozenset({"eurlex_3"})
48
+
49
+
50
  @pytest.fixture
51
  def parquet(tmp_path):
52
+ return write_parquet(tmp_path / "eurlex" / "eurlex.parquet", [
53
+ row(0), row(1), row(2, license=NEW_LICENSE), row(3, text=f"Standard\n{IASB_NOTICES[0]}\n" + "a" * 200),
54
+ ])
55
+
56
+
57
+ def assert_refused(path: Path, match: str, withhold: frozenset[str]) -> None:
58
+ digest = hashlib.sha256(path.read_bytes()).hexdigest()
59
+ with pytest.raises(ValueError, match=match):
60
+ clean(path, withhold)
61
+ assert hashlib.sha256(path.read_bytes()).hexdigest() == digest
62
+ assert not path.with_suffix(".parquet.tmp").exists()
63
 
64
 
65
+ def test_clean_relabels_and_drops_only_the_pinned_rows(parquet):
66
  before = pq.read_table(parquet)
67
+ stats = clean(parquet, PINNED)
68
  after = pq.read_table(parquet)
69
+ kept = before.slice(0, 3)
70
 
71
  assert after.schema == before.schema
72
+ assert after["id"].to_pylist() == ["eurlex_0", "eurlex_1", "eurlex_2"]
73
  assert after["license"].to_pylist() == [NEW_LICENSE] * 3
74
  for name in before.schema.names:
75
  if name != "license":
76
+ assert after[name].equals(kept[name]), name
77
+ assert (stats["read"], stats["kept"], stats["drop_iasb_notice"]) == (4, 3, 1)
78
  assert stats["licenses"] == {NEW_LICENSE: 3}
79
  assert stats["license"] == NEW_LICENSE == CFG["license"]
80
+ assert stats["chars"] == string_len_sum(kept["text"])
81
+ assert stats["tokens"] == sum(kept["token_count"].to_pylist())
82
  assert json.loads(parquet.with_name("eurlex.stats.json").read_text()) == stats
83
  assert not parquet.with_suffix(".parquet.tmp").exists()
84
 
85
 
86
+ def test_clean_refuses_an_unpinned_iasb_row(parquet):
87
+ assert_refused(parquet, "eurlex_3 has IASB notice=True but pinned=False", frozenset())
88
+
89
+
90
+ def test_clean_refuses_a_pinned_row_without_the_notice(parquet):
91
+ assert_refused(parquet, "eurlex_0 has IASB notice=False but pinned=True", PINNED | {"eurlex_0"})
92
 
93
 
94
+ def test_clean_refuses_a_pinned_id_missing_from_the_input(parquet):
95
+ assert_refused(parquet, "1 pinned id.*eurlex_9", PINNED | {"eurlex_9"})
96
+
97
+
98
+ def test_clean_refuses_to_rerun_on_its_own_output(parquet):
99
+ clean(parquet, PINNED)
100
+ assert_refused(parquet, "restore the v0.2.5 input", PINNED)
101
+
102
+
103
+ def test_clean_refuses_an_unexpected_license(tmp_path):
104
  path = write_parquet(tmp_path / "eurlex" / "eurlex.parquet", [row(0), row(1, license="CC-BY-SA-4.0")])
105
+ assert_refused(path, "CC-BY-SA-4.0", frozenset())
 
 
 
 
106
 
107
 
108
  # The three wordings of the IASB notice in the corpus (Polish text of the OJ), and text that must not match.
 
158
  assert rules["iasb_notice"]["chars"] == len(pq.read_table(path)["text"][0].as_py())
159
 
160
 
161
+
162
+ @pytest.mark.parametrize("pinned, refused", [(["eurlex_3"], False), (["eurlex_7"], True), ([], False)])
163
+ def test_scan_never_changes_a_pinned_id_list(parquet, tmp_path, monkeypatch, pinned, refused):
164
+ import clean_eurlex
165
+ pin = tmp_path / "eurlex.third-party-scan.json"
166
+ pin.write_text(json.dumps({"iasb_notice_ids": pinned}))
167
+ monkeypatch.setattr(clean_eurlex, "SCAN_JSON", pin)
168
+ monkeypatch.setattr(sys, "argv", ["clean_eurlex.py", "--scan", "--parquet", str(parquet)])
169
+ if refused:
170
+ with pytest.raises(SystemExit, match="pins 1 IASB ids, this input has 1"):
171
+ clean_eurlex.main()
172
+ assert json.loads(pin.read_text()) == {"iasb_notice_ids": pinned}
173
+ else:
174
+ clean_eurlex.main()
175
+ assert json.loads(pin.read_text())["iasb_notice_ids"] == ["eurlex_3"]
176
+
177
  def test_registry_label_and_basis():
178
  assert CFG["license"] == CFG["license_spdx"] == NEW_LICENSE
179
  assert CFG["release"] == "0.2.0"
 
205
  assert sources == {"eurlex"}
206
  assert (rows, chars, tokens) == (stats["kept"], stats["chars"], stats["tokens"])
207
  assert stats["licenses"] == {CFG["license"]: rows} and stats["license"] == CFG["license"]
208
+ # v0.2.5 (243,060 docs, 5,976,949,249 chars, 2,378,055,718 tokens) minus the 92 IASB documents
209
+ assert (rows, chars, tokens) == (242968, 5902889135, 2350709056)
210
+ assert (stats["read"], stats["drop_iasb_notice"]) == (243060, 92)
211
+ ids = set(pq.read_table(path, columns=["id"])["id"].to_pylist())
212
+ assert len(ids) == rows and not ids & pinned_iasb_ids()
213
 
214
  digest = hashlib.sha256()
215
  with open(path, "rb") as handle:
216
  for block in iter(lambda: handle.read(1 << 24), b""):
217
  digest.update(block)
218
+ assert digest.hexdigest() == evidence["parquet"]["after_sha256"]
219
 
220
 
221
  def test_evidence_and_scan_agree():
 
224
  check = evidence["third_party_check"]
225
 
226
  assert evidence["label"] == CFG["license"] and evidence["previous_label"] == OLD_LICENSE
227
+ assert check["dropped"] == check["iasb_notice"]["documents"] == 92
228
  assert check["iasb_notice"]["documents"] == result["rules"]["iasb_notice"]["docs"] == len(result["iasb_notice_ids"])
229
+ assert len(set(result["iasb_notice_ids"])) == 92
230
  assert check["iasb_notice"]["characters"] == result["rules"]["iasb_notice"]["chars"]
231
  assert check["copyright_sign"]["documents"] == result["rules"]["copyright_sign"]["docs"]
232
  third_party = check["copyright_sign"]["hand_labelled_third_party_credit_or_citation"]
233
  assert len(third_party) == len(set(third_party)) == check["copyright_sign"]["hand_labelled_third_party_count"]
234
  for name in ("ecb_act", "eesc", "state_aid_sa", "un_ece_regulation"):
235
  assert check["author_header_categories"][name] == result["rules"][name]["docs"]
236
+ # the scan reads the v0.2.5 input; the release is that input minus the IASB documents
237
+ parquet = evidence["parquet"]
238
+ assert (result["rows"], result["chars"]) == (parquet["v0_2_5_rows"], parquet["v0_2_5_chars"])
239
+ assert parquet["rows"] == parquet["v0_2_5_rows"] - check["dropped"]
240
+ assert parquet["chars"] == parquet["v0_2_5_chars"] - check["iasb_notice"]["characters"]
241
+ assert parquet["tokens"] == parquet["v0_2_5_tokens"] - check["iasb_notice"]["tokens"]
242
 
243
  urls = [doc["url"] for doc in evidence["reuse_basis"]["documents"]]
244
  assert urls == ["https://eur-lex.europa.eu/content/legal-notice/legal-notice.html",