Datasets:
wiktionary_examples: drop quoted third-party lines, relabel CC BY-SA 4.0
Browse filesRebuilt from plwiktionary-20261001. Lines citing a source ({{źródło}}, <ref>),
naming one by hand ("(z Internetu)", "(B. Prus: Lalka)") or marked "(…)" are
Art. 29 quotations, not contributors' CC BY-SA text, and are dropped: 32,983
of 78,245 example lines. 1,818 documents (v0.2.5: 8,639).
- id from the page id (preserve_id), author = page URL credit (BY-SA 4.0 §3(a)(2))
- licence CC-BY-SA-4.0 (Terms of Use; pre-2023 3.0 text via 3.0 §4(b))
- {{przykłady}} block end anchored to line start, so inline {{tłum}} no longer cuts it
- citations side-car records the source of every dropped line
- license-evidence.json, datasheet, contract test, findings entry
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- artifacts/source_findings.md +29 -0
- data/wiktionary_examples/wiktionary_examples.license-evidence.json +57 -0
- data/wiktionary_examples/wiktionary_examples.md +58 -13
- data/wiktionary_examples/wiktionary_examples.parquet +2 -2
- data/wiktionary_examples/wiktionary_examples.stats.json +9 -9
- src/fetch_wiktionary_examples.py +117 -37
- src/sources.py +20 -11
- src/test_wiktionary_examples.py +129 -0
- src/test_wiktionary_examples_contract.py +40 -0
artifacts/source_findings.md
CHANGED
|
@@ -1038,3 +1038,32 @@ say so in the datasheet instead of pretending a before/after can be regenerated.
|
|
| 1038 |
|
| 1039 |
**Lesson:** a file name is metadata, not evidence. Two texts did not match the
|
| 1040 |
work their file name gives, and 4 translator credits were wrong.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1038 |
|
| 1039 |
**Lesson:** a file name is metadata, not evidence. Two texts did not match the
|
| 1040 |
work their file name gives, and 4 translator credits were wrong.
|
| 1041 |
+
|
| 1042 |
+
## wiktionary_examples — Polish Wiktionary usage examples (rebuild)
|
| 1043 |
+
|
| 1044 |
+
**Investigated** — 2026-10-05 (October 2026 rights audit, `artifacts/rights_audit_2026-10/reports/wikis_ugc.md`).
|
| 1045 |
+
|
| 1046 |
+
**Verdict** — `added`, rebuilt for v0.2.6. Quotations from third-party works dropped;
|
| 1047 |
+
1,818 documents / 534,521 characters (v0.2.5: 8,639 / 2,889,761). Licence relabelled
|
| 1048 |
+
`CC-BY-SA-3.0` → `CC-BY-SA-4.0`.
|
| 1049 |
+
|
| 1050 |
+
**Enumeration** — official dump `plwiktionary-20261001-pages-articles.xml.bz2` (sha1
|
| 1051 |
+
`a097f6e2…`), parsed by `src/fetch_wiktionary_examples.py`. 116,157 Polish entries;
|
| 1052 |
+
78,245 example lines, of which 32,664 carry `{{źródło}}`/`<ref>` and 319 name a source by
|
| 1053 |
+
hand ("(z Internetu)", "(B. Prus: Lalka)", "(Wikipedia)", Bible references, "(…)"). The
|
| 1054 |
+
audit's sample estimated 23% cited; the full count is 42%.
|
| 1055 |
+
|
| 1056 |
+
**License evidence** — verified: Wikimedia Terms of Use (contributors license their text
|
| 1057 |
+
CC BY-SA 4.0; page sha256 `913bdefc…`) and the pl.wiktionary footer linking BY-SA 4.0,
|
| 1058 |
+
both read 2026-10-05. Inferred: pre-June-2023 text was under 3.0, whose §4(b) allows an
|
| 1059 |
+
adaptation under 4.0. Quoted lines are used on Wiktionary under Art. 29, which does not
|
| 1060 |
+
pass to a corpus. Evidence in `data/wiktionary_examples/wiktionary_examples.license-evidence.json`.
|
| 1061 |
+
|
| 1062 |
+
**Blockers** — none to merge. Open: whether to relax or regroup the 200-character
|
| 1063 |
+
document gate, which removes 29,265 of 31,094 entries; quotations pasted without a
|
| 1064 |
+
source marker cannot be detected; NERGAL pass before release.
|
| 1065 |
+
|
| 1066 |
+
**Lesson** — (1) a template-only citation filter misses about 1% of quotations, which
|
| 1067 |
+
contributors attribute by hand in parentheses; survey the uncited lines before trusting
|
| 1068 |
+
it. (2) An end-of-section regex for `{{przykłady}}` must be anchored to line start, or an
|
| 1069 |
+
inline `{{tłum}}` cuts the section and hides cited lines.
|
data/wiktionary_examples/wiktionary_examples.license-evidence.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"license": "CC-BY-SA-4.0",
|
| 3 |
+
"spdx": "https://spdx.org/licenses/CC-BY-SA-4.0.html",
|
| 4 |
+
"status": "documented-open-cc-by-sa",
|
| 5 |
+
"review_scope": "licence of contributors' text on pl.wiktionary and removal of quoted third-party text; not independent legal advice",
|
| 6 |
+
"checked_at": "2026-10-05",
|
| 7 |
+
"evidence_url": "https://foundation.wikimedia.org/wiki/Policy:Terms_of_Use",
|
| 8 |
+
"sha256": "913bdefc49f13fbb3d12b5402712b10739cede9d6f4a76e7ad49f3304772b434",
|
| 9 |
+
"statement": "When you submit text to which you hold the copyright, you agree to license it under: Creative Commons Attribution-ShareAlike 4.0 International License (\"CC BY-SA 4.0\"), and GNU Free Documentation License (\"GFDL\")",
|
| 10 |
+
"site_footer": {
|
| 11 |
+
"url": "https://pl.wiktionary.org/wiki/dom",
|
| 12 |
+
"sha256": "14a12e875b9ab07f33586f43fb2f9b98eda42110963471917df7d6dd62cedc28",
|
| 13 |
+
"statement": "Tekst udostępniany na licencji Creative Commons: uznanie autorstwa, na tych samych warunkach, z możliwością obowiązywania dodatkowych ograniczeń.",
|
| 14 |
+
"license_link": "https://creativecommons.org/licenses/by-sa/4.0/deed.pl"
|
| 15 |
+
},
|
| 16 |
+
"chain": [
|
| 17 |
+
{
|
| 18 |
+
"hop": "Wiktionary contributors -> Wikimedia Foundation",
|
| 19 |
+
"basis": "Terms of Use: contributors license their text CC BY-SA 4.0 (CC BY-SA 3.0 before June 2023)",
|
| 20 |
+
"mark": "V"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"hop": "Wikimedia dump -> polish-dynaword",
|
| 24 |
+
"basis": "plwiktionary-20261001-pages-articles.xml.bz2, sha1 a097f6e2b005d1235936a19ed8e800e29a6f2fad, matched to the published dump checksum",
|
| 25 |
+
"url": "https://dumps.wikimedia.org/plwiktionary/20261001/",
|
| 26 |
+
"mark": "V"
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"hop": "pre-June-2023 revisions under CC BY-SA 3.0 -> released as 4.0",
|
| 30 |
+
"basis": "CC BY-SA 3.0 §4(b) lets an adaptation be licensed under a later version with the same elements",
|
| 31 |
+
"url": "https://creativecommons.org/licenses/by-sa/3.0/legalcode",
|
| 32 |
+
"mark": "I"
|
| 33 |
+
}
|
| 34 |
+
],
|
| 35 |
+
"attribution": "author = \"Wikisłownik contributors, <page URL>\"; the page history names the contributors (CC BY-SA 4.0 §3(a)(2) allows a URI)",
|
| 36 |
+
"finding": "Contributors' own usage examples are CC BY-SA 4.0. Quotations from third-party works (used on Wiktionary under the Art. 29 quotation right) are not, and are dropped: lines with {{źródło}}/<ref>, lines naming a source by hand, and excerpts marked (…).",
|
| 37 |
+
"release_scope": {
|
| 38 |
+
"pages_scanned": 869406,
|
| 39 |
+
"polish_entries": 116157,
|
| 40 |
+
"entries_with_examples": 31094,
|
| 41 |
+
"lines_dropped_cited": 32664,
|
| 42 |
+
"lines_dropped_hand_attributed": 319,
|
| 43 |
+
"lines_dropped_under_10_chars": 50,
|
| 44 |
+
"lines_kept": 45212,
|
| 45 |
+
"documents_200_chars_or_more": 1829,
|
| 46 |
+
"documents_released": 1818,
|
| 47 |
+
"dropped_duplicates": 11
|
| 48 |
+
},
|
| 49 |
+
"audit_trail": "wiktionary_examples.citations.jsonl, written by the fetcher next to its output, not part of the corpus: per entry, the sources of its dropped lines (199 dropped lines carry a citation marker with no source text)",
|
| 50 |
+
"not_checked": [
|
| 51 |
+
"quotations pasted without any source marker; the filter cannot see them",
|
| 52 |
+
"whether a contributor's example paraphrases a protected text",
|
| 53 |
+
"the 3.0 -> 4.0 relabel of pre-2023 text (inferred from 3.0 §4(b), not reviewed by a lawyer)",
|
| 54 |
+
"GFDL dual licensing; only the CC BY-SA grant is relied on",
|
| 55 |
+
"personal data in example sentences (NERGAL scrub runs before release)"
|
| 56 |
+
]
|
| 57 |
+
}
|
data/wiktionary_examples/wiktionary_examples.md
CHANGED
|
@@ -3,39 +3,84 @@
|
|
| 3 |
Polish Wiktionary usage examples
|
| 4 |
|
| 5 |
## Dataset description
|
| 6 |
-
- **Source (upstream):** https://dumps.wikimedia.org/plwiktionary/
|
| 7 |
- **Domain:** lexicographic
|
| 8 |
- **Language:** Polish (pl)
|
| 9 |
-
- **License:** `CC-BY-SA-
|
| 10 |
-
- **Created (range):** 2004-03-22, 2026-
|
| 11 |
-
- **Added:** 2026-07-19
|
| 12 |
|
| 13 |
## Licensing — traceable basis
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
## Provenance
|
| 17 |
-
Parsed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
## Statistics
|
| 20 |
| documents | characters | tokens (tiktoken proxy) |
|
| 21 |
|---:|---:|---:|
|
| 22 |
-
|
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
## Per-document license metadata
|
| 26 |
| license | documents |
|
| 27 |
|---|---:|
|
| 28 |
-
| `CC-BY-SA-
|
| 29 |
|
| 30 |
-
Author metadata present for **
|
| 31 |
|
| 32 |
## Filters applied (build_dynaword.py)
|
| 33 |
-
|
| 34 |
-
- drop documents < 200 chars: **0**
|
| 35 |
- drop non-Polish (diacritic ratio): **0**
|
| 36 |
-
- exact cross-source dedup (sha1): **
|
| 37 |
- OCR alpha-ratio < 0.70 (OCR sources only): **0**
|
| 38 |
-
- read
|
| 39 |
|
| 40 |
Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
|
| 41 |
Llama-3 count is computed at release.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
Polish Wiktionary usage examples
|
| 4 |
|
| 5 |
## Dataset description
|
| 6 |
+
- **Source (upstream):** https://dumps.wikimedia.org/plwiktionary/20261001/
|
| 7 |
- **Domain:** lexicographic
|
| 8 |
- **Language:** Polish (pl)
|
| 9 |
+
- **License:** `CC-BY-SA-4.0`
|
| 10 |
+
- **Created (range):** 2004-03-22, 2026-10-01
|
| 11 |
+
- **Added:** 2026-07-19; rebuilt 2026-10-05 without quoted third-party text
|
| 12 |
|
| 13 |
## Licensing — traceable basis
|
| 14 |
+
Wiktionary contributors license their text under CC BY-SA 4.0: the Wikimedia
|
| 15 |
+
[Terms of Use](https://foundation.wikimedia.org/wiki/Policy:Terms_of_Use) (read
|
| 16 |
+
2026-10-05) and the pl.wiktionary footer, which links
|
| 17 |
+
`creativecommons.org/licenses/by-sa/4.0/deed.pl`. Text contributed before June 2023
|
| 18 |
+
was under CC BY-SA 3.0, which allows an adaptation under a later version (3.0 §4(b)).
|
| 19 |
+
v0.2.5 labelled the source `CC-BY-SA-3.0`; this release labels it `CC-BY-SA-4.0`.
|
| 20 |
+
|
| 21 |
+
Not every example sentence is contributor text. Many are quotations from books,
|
| 22 |
+
press, the NKJP corpus, the web or Wikipedia, used on Wiktionary under the quotation
|
| 23 |
+
right (Art. 29 of the Polish copyright act). That right does not pass to a corpus,
|
| 24 |
+
and the CC BY-SA grant does not cover them. The fetcher drops them:
|
| 25 |
+
|
| 26 |
+
| line | lines | released |
|
| 27 |
+
|---|---:|---|
|
| 28 |
+
| carries `{{źródło}}` or a `<ref>` | 32,664 | no |
|
| 29 |
+
| names its source by hand, e.g. "(B. Prus: Lalka)", "(z Internetu)", "(Wikipedia)", "(Mt 4:19)", or is an excerpt marked "(…)" / "[…]" | 319 | no |
|
| 30 |
+
| shorter than 10 characters | 50 | no |
|
| 31 |
+
| contributor's own example | 45,212 | yes, if its entry reaches 200 characters |
|
| 32 |
+
|
| 33 |
+
The hand-attribution patterns come from a survey of the dump and also drop a few
|
| 34 |
+
lines that end in a Latin gloss in parentheses. Quotations pasted with no source
|
| 35 |
+
marker cannot be detected and may remain.
|
| 36 |
+
|
| 37 |
+
Evidence: `wiktionary_examples.license-evidence.json`.
|
| 38 |
+
|
| 39 |
+
## Attribution
|
| 40 |
+
Each row's `author` is `Wikisłownik contributors, <page URL>`, e.g.
|
| 41 |
+
`https://pl.wiktionary.org/wiki/czyta%C4%87`. The page history names the
|
| 42 |
+
contributors; CC BY-SA 4.0 §3(a)(2) allows attribution by a URI. The row `id` is
|
| 43 |
+
`wiktionary_examples_<page id>`.
|
| 44 |
|
| 45 |
## Provenance
|
| 46 |
+
Parsed from the official Wikimedia dump `plwiktionary-20261001-pages-articles.xml.bz2`
|
| 47 |
+
(sha1 `a097f6e2b005d1235936a19ed8e800e29a6f2fad`) by `src/fetch_wiktionary_examples.py`;
|
| 48 |
+
not routed through SpeakLeash. One document per Polish-language headword: the lines of
|
| 49 |
+
its `{{przykłady}}` section, in source order. The fetcher also writes
|
| 50 |
+
`wiktionary_examples.citations.jsonl` (not part of the corpus) listing, per entry, the
|
| 51 |
+
sources of the dropped lines.
|
| 52 |
+
|
| 53 |
+
869,406 pages scanned → 116,157 Polish entries → 31,094 with at least one kept example
|
| 54 |
+
→ 1,829 at 200 characters or more → 1,818 after deduplication.
|
| 55 |
|
| 56 |
## Statistics
|
| 57 |
| documents | characters | tokens (tiktoken proxy) |
|
| 58 |
|---:|---:|---:|
|
| 59 |
+
| 1,818 | 534,521 | 207,181 |
|
| 60 |
|
| 61 |
+
v0.2.5 had 8,639 documents (2,889,761 characters). Most of the drop comes from the
|
| 62 |
+
200-character document gate: removing the quotations leaves most entries with one or
|
| 63 |
+
two short examples.
|
| 64 |
|
| 65 |
## Per-document license metadata
|
| 66 |
| license | documents |
|
| 67 |
|---|---:|
|
| 68 |
+
| `CC-BY-SA-4.0` | 1,818 |
|
| 69 |
|
| 70 |
+
Author metadata present for **1,818** documents.
|
| 71 |
|
| 72 |
## Filters applied (build_dynaword.py)
|
| 73 |
+
- drop documents < 200 chars: **0** (the fetcher applies the same gate: 29,265 entries)
|
|
|
|
| 74 |
- drop non-Polish (diacritic ratio): **0**
|
| 75 |
+
- exact cross-source dedup (sha1): **11**
|
| 76 |
- OCR alpha-ratio < 0.70 (OCR sources only): **0**
|
| 77 |
+
- read 1,829 → kept 1,818
|
| 78 |
|
| 79 |
Token counts are a fast tiktoken (cl100k) proxy (~1% off Llama-3); the canonical
|
| 80 |
Llama-3 count is computed at release.
|
| 81 |
+
|
| 82 |
+
## Not checked
|
| 83 |
+
- quotations pasted without any source marker
|
| 84 |
+
- whether an example paraphrases a protected text
|
| 85 |
+
- the 3.0 → 4.0 relabel of pre-2023 text (reading of 3.0 §4(b), not a lawyer's opinion)
|
| 86 |
+
- personal data in example sentences (the NERGAL scrub runs before release)
|
data/wiktionary_examples/wiktionary_examples.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:28a987798fc6f6d06cc64bad59e95236f821d20c88cecda37531cc4d6b3b26e6
|
| 3 |
+
size 306198
|
data/wiktionary_examples/wiktionary_examples.stats.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
{
|
| 2 |
-
"read":
|
| 3 |
-
"kept":
|
| 4 |
"drop_short": 0,
|
| 5 |
"drop_lang": 0,
|
| 6 |
-
"drop_dup":
|
| 7 |
"drop_ocr": 0,
|
| 8 |
-
"chars":
|
| 9 |
-
"tokens":
|
| 10 |
"licenses": {
|
| 11 |
-
"CC-BY-SA-
|
| 12 |
},
|
| 13 |
-
"authors_with_value":
|
| 14 |
-
"secs":
|
| 15 |
-
"license": "CC-BY-SA-
|
| 16 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"read": 1829,
|
| 3 |
+
"kept": 1818,
|
| 4 |
"drop_short": 0,
|
| 5 |
"drop_lang": 0,
|
| 6 |
+
"drop_dup": 11,
|
| 7 |
"drop_ocr": 0,
|
| 8 |
+
"chars": 534521,
|
| 9 |
+
"tokens": 207181,
|
| 10 |
"licenses": {
|
| 11 |
+
"CC-BY-SA-4.0": 1818
|
| 12 |
},
|
| 13 |
+
"authors_with_value": 1818,
|
| 14 |
+
"secs": 0.5,
|
| 15 |
+
"license": "CC-BY-SA-4.0"
|
| 16 |
}
|
src/fetch_wiktionary_examples.py
CHANGED
|
@@ -9,11 +9,13 @@ Unlike most sources in this registry, this one is NOT routed through
|
|
| 9 |
SpeakLeash's redistribution — it is parsed directly from the Wikimedia dump.
|
| 10 |
The `provenance` field in sources.py records this.
|
| 11 |
|
| 12 |
-
One document = one headword; its
|
| 13 |
-
newline-separated, in source order. A
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
Only the standard library is required for parsing; `zstandard` is used for
|
| 19 |
output compression (falls back to plain .jsonl with a warning).
|
|
@@ -36,11 +38,15 @@ import json
|
|
| 36 |
import re
|
| 37 |
import sys
|
| 38 |
from pathlib import Path
|
|
|
|
| 39 |
from xml.etree import ElementTree as ET
|
| 40 |
|
| 41 |
SOURCE_NAME = "wiktionary_examples"
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# Gates mirrored from build_dynaword.py so the preview count matches the build.
|
| 46 |
MIN_CHARS = 200
|
|
@@ -50,16 +56,43 @@ MIN_EXAMPLE_CHARS = 10
|
|
| 50 |
PL_HEADING = re.compile(r"^==\s*(.+?)\s*\(\{\{język polski\}\}\)\s*==\s*$", re.M)
|
| 51 |
NEXT_HEADING = re.compile(r"^==[^=]", re.M)
|
| 52 |
|
| 53 |
-
# Blocks run until the next
|
|
|
|
| 54 |
EXAMPLES_BLOCK = re.compile(
|
| 55 |
-
r"\{\{przykłady\}\}(.*?)(?=\{\{[a-ząćęłńóśźż]+\}\}|\Z)", re.S
|
| 56 |
)
|
| 57 |
# Numbered lines: `: (1.1) <sentence>`
|
| 58 |
NUMBERED_LINE = re.compile(r"^:\s*\(([\d.]+)\)\s*(.+?)\s*$", re.M)
|
| 59 |
SENSE_NUMBER = re.compile(r"\(\d+\.\d+\)")
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
| 62 |
CITATION_TEMPLATES = ("{{źródło", "{{zrodlo")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
def split_templates(text: str) -> tuple[str, list[str]]:
|
|
@@ -94,14 +127,18 @@ def split_templates(text: str) -> tuple[str, list[str]]:
|
|
| 94 |
|
| 95 |
|
| 96 |
def describe_citation(template: str) -> str:
|
| 97 |
-
"""Flatten a `{{źródło|autor=…|tytuł=…}}` template into a readable string
|
|
|
|
|
|
|
| 98 |
fields: dict[str, str] = {}
|
| 99 |
-
for chunk in
|
| 100 |
if "=" in chunk:
|
| 101 |
key, value = chunk.split("=", 1)
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
parts = [fields[k] for k in CITATION_FIELDS if fields.get(k)]
|
| 104 |
-
return " | ".join(parts)
|
| 105 |
|
| 106 |
|
| 107 |
def unlink(text: str) -> str:
|
|
@@ -127,12 +164,14 @@ def clean(text: str) -> str:
|
|
| 127 |
philological convention inside quotations, not markup residue."""
|
| 128 |
text = re.sub(r"<ref[^>]*>.*?</ref>", "", text, flags=re.S)
|
| 129 |
text = re.sub(r"<ref[^>]*/>", "", text)
|
|
|
|
| 130 |
text = re.sub(r"<[^>]+>", "", text)
|
| 131 |
text = unlink(text)
|
| 132 |
text = re.sub(r"'{2,}", "", text)
|
| 133 |
text = html.unescape(html.unescape(text)) # some entities are double-encoded
|
| 134 |
text = text.replace("\u00a0", " ")
|
| 135 |
text = SENSE_NUMBER.sub("", text)
|
|
|
|
| 136 |
text = re.sub(r"\s+", " ", text)
|
| 137 |
return text.strip(" -–—•\t")
|
| 138 |
|
|
@@ -155,8 +194,37 @@ def is_cited(raw: str, templates: list[str]) -> bool:
|
|
| 155 |
return "<ref" in raw.lower() or any(t.startswith(CITATION_TEMPLATES) for t in templates)
|
| 156 |
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
def examples_and_citations(section: str) -> tuple[list[str], list[str], int]:
|
| 159 |
-
"""(
|
|
|
|
|
|
|
|
|
|
| 160 |
match = EXAMPLES_BLOCK.search(section)
|
| 161 |
if not match:
|
| 162 |
return [], [], 0
|
|
@@ -165,20 +233,30 @@ def examples_and_citations(section: str) -> tuple[list[str], list[str], int]:
|
|
| 165 |
without_templates, templates = split_templates(raw)
|
| 166 |
if is_cited(raw, templates):
|
| 167 |
dropped += 1
|
| 168 |
-
|
| 169 |
-
if template.startswith(CITATION_TEMPLATES):
|
| 170 |
-
described = describe_citation(clean(template))
|
| 171 |
-
if described:
|
| 172 |
-
citations.append(described)
|
| 173 |
continue
|
| 174 |
sentence = clean(without_templates)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
if len(sentence) >= MIN_EXAMPLE_CHARS:
|
| 176 |
examples.append(sentence)
|
| 177 |
return examples, sorted(set(citations)), dropped
|
| 178 |
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
def iter_pages(dump_path: Path):
|
| 181 |
-
"""Yield (namespace, wikitext) for every page, streaming the bz2 dump."""
|
| 182 |
with bz2.open(dump_path, "rb") as handle:
|
| 183 |
for _, element in ET.iterparse(handle, events=("end",)):
|
| 184 |
if element.tag.rsplit("}", 1)[-1] != "page":
|
|
@@ -186,9 +264,11 @@ def iter_pages(dump_path: Path):
|
|
| 186 |
values = {}
|
| 187 |
for child in element.iter():
|
| 188 |
tag = child.tag.rsplit("}", 1)[-1]
|
| 189 |
-
|
|
|
|
| 190 |
values[tag] = child.text
|
| 191 |
-
yield (values.get("ns") or "").strip(), values.get("
|
|
|
|
| 192 |
element.clear()
|
| 193 |
|
| 194 |
|
|
@@ -209,11 +289,11 @@ def main() -> None:
|
|
| 209 |
out_dir = Path(args.out).expanduser()
|
| 210 |
out_dir.mkdir(parents=True, exist_ok=True)
|
| 211 |
|
| 212 |
-
pages = entries = with_examples = with_citations =
|
| 213 |
-
documents: list[
|
| 214 |
citation_index: list[dict] = []
|
| 215 |
|
| 216 |
-
for namespace, wikitext in iter_pages(dump_path):
|
| 217 |
pages += 1
|
| 218 |
if pages % 100_000 == 0:
|
| 219 |
print(f" {pages:,} pages scanned, {entries:,} Polish entries",
|
|
@@ -226,33 +306,33 @@ def main() -> None:
|
|
| 226 |
entries += 1
|
| 227 |
headword, body = section
|
| 228 |
examples, citations, dropped = examples_and_citations(body)
|
| 229 |
-
|
| 230 |
if citations:
|
| 231 |
with_citations += 1
|
| 232 |
-
citation_index.append({"
|
|
|
|
| 233 |
if not examples:
|
| 234 |
continue
|
| 235 |
with_examples += 1
|
| 236 |
-
|
| 237 |
-
documents.append(
|
|
|
|
| 238 |
|
| 239 |
-
kept = [
|
| 240 |
-
chars = sum(len(
|
| 241 |
|
| 242 |
print()
|
| 243 |
print(f"pages scanned: {pages:,}")
|
| 244 |
print(f"Polish entries: {entries:,}")
|
| 245 |
print(f"entries with examples: {with_examples:,}")
|
| 246 |
print(f"entries with attribution: {with_citations:,}")
|
| 247 |
-
print(f"
|
| 248 |
-
print(f"
|
| 249 |
print(f"documents >= {args.min_chars} chars: {len(kept):,}")
|
| 250 |
print(f"characters: {chars:,}")
|
| 251 |
|
| 252 |
payload = "\n".join(
|
| 253 |
-
json.dumps(
|
| 254 |
-
ensure_ascii=False)
|
| 255 |
-
for _, text in kept
|
| 256 |
) + "\n"
|
| 257 |
|
| 258 |
plain = out_dir / f"{SOURCE_NAME}.jsonl"
|
|
|
|
| 9 |
SpeakLeash's redistribution — it is parsed directly from the Wikimedia dump.
|
| 10 |
The `provenance` field in sources.py records this.
|
| 11 |
|
| 12 |
+
One document = one headword; its example sentences are concatenated,
|
| 13 |
+
newline-separated, in source order. A quotation from a third-party work (used
|
| 14 |
+
under the Art. 29 quotation right, not licensed CC BY-SA by Wiktionary
|
| 15 |
+
contributors) is dropped: a line carrying a `{{źródło|...}}` template or a
|
| 16 |
+
`<ref>`, a hand-written source such as "(B. Prus: Lalka)" or "(z Internetu)",
|
| 17 |
+
or an omission mark "(…)". Its citation goes to a side-car file for auditing
|
| 18 |
+
(not part of the corpus).
|
| 19 |
|
| 20 |
Only the standard library is required for parsing; `zstandard` is used for
|
| 21 |
output compression (falls back to plain .jsonl with a warning).
|
|
|
|
| 38 |
import re
|
| 39 |
import sys
|
| 40 |
from pathlib import Path
|
| 41 |
+
from urllib.parse import quote
|
| 42 |
from xml.etree import ElementTree as ET
|
| 43 |
|
| 44 |
SOURCE_NAME = "wiktionary_examples"
|
| 45 |
+
# pl.wiktionary's footer links CC BY-SA 4.0 (Wikimedia Terms of Use, June 2023).
|
| 46 |
+
# Older revisions were contributed under 3.0, whose §4(b) allows an adaptation
|
| 47 |
+
# to be licensed under a later version with the same elements.
|
| 48 |
+
LICENSE = "CC-BY-SA-4.0"
|
| 49 |
+
PAGE_URL = "https://pl.wiktionary.org/wiki/"
|
| 50 |
|
| 51 |
# Gates mirrored from build_dynaword.py so the preview count matches the build.
|
| 52 |
MIN_CHARS = 200
|
|
|
|
| 56 |
PL_HEADING = re.compile(r"^==\s*(.+?)\s*\(\{\{język polski\}\}\)\s*==\s*$", re.M)
|
| 57 |
NEXT_HEADING = re.compile(r"^==[^=]", re.M)
|
| 58 |
|
| 59 |
+
# Blocks run until the next section marker, a `{{template}}` opening a line.
|
| 60 |
+
# Inline templates such as `{{tłum}}` or `{{pot}}` inside an example don't end it.
|
| 61 |
EXAMPLES_BLOCK = re.compile(
|
| 62 |
+
r"\{\{przykłady\}\}(.*?)(?=^\{\{[a-ząćęłńóśźż]+\}\}|\Z)", re.S | re.M
|
| 63 |
)
|
| 64 |
# Numbered lines: `: (1.1) <sentence>`
|
| 65 |
NUMBERED_LINE = re.compile(r"^:\s*\(([\d.]+)\)\s*(.+?)\s*$", re.M)
|
| 66 |
SENSE_NUMBER = re.compile(r"\(\d+\.\d+\)")
|
| 67 |
|
| 68 |
+
# Fields of {{źródło}} and of the templates used inside <ref>: {{NKJP}}, {{cytuj}},
|
| 69 |
+
# {{cytuj stronę}}, {{KJP}}, {{Gloger1900}}.
|
| 70 |
+
CITATION_FIELDS = ("autor", "autorzy", "tytuł", "tytul", "tytuł_pub", "rozdział", "rozdzial",
|
| 71 |
+
"hasło", "rok", "data", "isbn", "url")
|
| 72 |
CITATION_TEMPLATES = ("{{źródło", "{{zrodlo")
|
| 73 |
+
# `<ref>source</ref>`, or `<ref name="x" />` reusing a source given elsewhere on the page.
|
| 74 |
+
REF = re.compile(r"<ref\b([^>]*?)(?:/>|>(.*?)</ref\s*>)", re.I | re.S)
|
| 75 |
+
|
| 76 |
+
# Quotations whose source is written by hand instead of with {{źródło}}, matched
|
| 77 |
+
# on the cleaned sentence. Patterns come from a survey of the 20261001 dump.
|
| 78 |
+
_UP = "A-ZĄĆĘŁŃÓŚŹŻ"
|
| 79 |
+
_LOW = "a-ząćęłńóśźż"
|
| 80 |
+
_END = r"[\s.!?…]*$"
|
| 81 |
+
ATTRIBUTION_TAILS = (
|
| 82 |
+
# A capital opening a word or an initial: "(B. Prus: Lalka)", "(Adam Mickiewicz)",
|
| 83 |
+
# "(Kogel-mogel)", "(Mt 4:19)", "(W leśniczówce …)". Acronyms and formulas
|
| 84 |
+
# ("(ZSRR)", "(C/kg)") don't match.
|
| 85 |
+
# ponytail: also drops a few glosses like "(Alligator missisippiensis)";
|
| 86 |
+
# losing a sentence is cheaper than shipping a quotation.
|
| 87 |
+
re.compile(rf"\(\s*[\"„“]?[{_UP}](?:[{_LOW}]|\.|\s)[^()]*\){_END}"),
|
| 88 |
+
# "(z Internetu)", "(z Wikipedii)", "(z Odysei)": "from <source>".
|
| 89 |
+
re.compile(rf"\(\s*z\s+[{_UP}{_LOW}][{_LOW}]*\){_END}", re.I),
|
| 90 |
+
re.compile(rf"\(\s*(?:źródło|wywiad|tytuł|słowa|cytat|za:)[^()]*\){_END}", re.I),
|
| 91 |
+
# Unparenthesised tag after the sentence: "…Gałczyńskiego. Internet".
|
| 92 |
+
re.compile(rf"(?<=[.!?…\]”\"])\s*(?:z\s+)?(?:internet\w*|wikipedi\w*){_END}", re.I),
|
| 93 |
+
)
|
| 94 |
+
# "(…)" / "[...]" mark an omission: the line was cut from someone else's text.
|
| 95 |
+
EXCERPT_MARK = re.compile(r"[(\[]\s*(?:…|\.\.\.)\s*[)\]]")
|
| 96 |
|
| 97 |
|
| 98 |
def split_templates(text: str) -> tuple[str, list[str]]:
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
def describe_citation(template: str) -> str:
|
| 130 |
+
"""Flatten a `{{źródło|autor=…|tytuł=…}}` template into a readable string; the
|
| 131 |
+
template's name when it has none of CITATION_FIELDS (e.g. `{{zWikiprojektu|…}}`)."""
|
| 132 |
+
name, *chunks = template.strip("{}").split("|")
|
| 133 |
fields: dict[str, str] = {}
|
| 134 |
+
for chunk in chunks:
|
| 135 |
if "=" in chunk:
|
| 136 |
key, value = chunk.split("=", 1)
|
| 137 |
+
key = key.strip().lower()
|
| 138 |
+
# clean() would delete a bare URL, which is the whole point of `url`.
|
| 139 |
+
fields[key] = value.strip() if key == "url" else clean(value)
|
| 140 |
parts = [fields[k] for k in CITATION_FIELDS if fields.get(k)]
|
| 141 |
+
return " | ".join(parts) or "{{" + name.strip() + "}}"
|
| 142 |
|
| 143 |
|
| 144 |
def unlink(text: str) -> str:
|
|
|
|
| 164 |
philological convention inside quotations, not markup residue."""
|
| 165 |
text = re.sub(r"<ref[^>]*>.*?</ref>", "", text, flags=re.S)
|
| 166 |
text = re.sub(r"<ref[^>]*/>", "", text)
|
| 167 |
+
text = re.sub(r"<br\s*/?>", " ", text, flags=re.I) # a line break separates words
|
| 168 |
text = re.sub(r"<[^>]+>", "", text)
|
| 169 |
text = unlink(text)
|
| 170 |
text = re.sub(r"'{2,}", "", text)
|
| 171 |
text = html.unescape(html.unescape(text)) # some entities are double-encoded
|
| 172 |
text = text.replace("\u00a0", " ")
|
| 173 |
text = SENSE_NUMBER.sub("", text)
|
| 174 |
+
text = re.sub(r"\(\s*\)", "", text) # left behind by a stripped template
|
| 175 |
text = re.sub(r"\s+", " ", text)
|
| 176 |
return text.strip(" -–—•\t")
|
| 177 |
|
|
|
|
| 194 |
return "<ref" in raw.lower() or any(t.startswith(CITATION_TEMPLATES) for t in templates)
|
| 195 |
|
| 196 |
|
| 197 |
+
def cited_sources(raw: str, templates: list[str]) -> list[str]:
|
| 198 |
+
"""The sources a cited line gives, for the audit side-car."""
|
| 199 |
+
sources = [describe_citation(t) for t in templates if t.startswith(CITATION_TEMPLATES)]
|
| 200 |
+
for ref in REF.finditer(raw):
|
| 201 |
+
attributes, body = ref.groups()
|
| 202 |
+
if body is None:
|
| 203 |
+
sources.append(f"<ref{attributes.rstrip()}/>")
|
| 204 |
+
continue
|
| 205 |
+
text, inner = split_templates(body)
|
| 206 |
+
# {{źródło}} inside a <ref> is already in `templates`.
|
| 207 |
+
sources += [describe_citation(t) for t in inner if not t.startswith(CITATION_TEMPLATES)]
|
| 208 |
+
sources.append(clean(text))
|
| 209 |
+
return [source for source in sources if source]
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def hand_attribution(sentence: str) -> str | None:
|
| 213 |
+
"""The source a quotation names without {{źródło}}, or "(…)" for an excerpt
|
| 214 |
+
that names none; None for a contributor's own example."""
|
| 215 |
+
for pattern in ATTRIBUTION_TAILS:
|
| 216 |
+
match = pattern.search(sentence)
|
| 217 |
+
if match:
|
| 218 |
+
return match.group(0).strip(" .!?…")
|
| 219 |
+
match = EXCERPT_MARK.search(sentence)
|
| 220 |
+
return match.group(0) if match else None
|
| 221 |
+
|
| 222 |
+
|
| 223 |
def examples_and_citations(section: str) -> tuple[list[str], list[str], int]:
|
| 224 |
+
"""(example sentences, citations of the dropped quotations, number of dropped lines).
|
| 225 |
+
|
| 226 |
+
A line is a quotation when it carries {{źródło}}/<ref> or a hand-written
|
| 227 |
+
source (see hand_attribution)."""
|
| 228 |
match = EXAMPLES_BLOCK.search(section)
|
| 229 |
if not match:
|
| 230 |
return [], [], 0
|
|
|
|
| 233 |
without_templates, templates = split_templates(raw)
|
| 234 |
if is_cited(raw, templates):
|
| 235 |
dropped += 1
|
| 236 |
+
citations.extend(cited_sources(raw, templates) or ["(no source text)"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
continue
|
| 238 |
sentence = clean(without_templates)
|
| 239 |
+
attribution = hand_attribution(sentence)
|
| 240 |
+
if attribution:
|
| 241 |
+
dropped += 1
|
| 242 |
+
citations.append(attribution)
|
| 243 |
+
continue
|
| 244 |
if len(sentence) >= MIN_EXAMPLE_CHARS:
|
| 245 |
examples.append(sentence)
|
| 246 |
return examples, sorted(set(citations)), dropped
|
| 247 |
|
| 248 |
|
| 249 |
+
def page_url(title: str) -> str:
|
| 250 |
+
return PAGE_URL + quote(title.replace(" ", "_"), safe="/:()',!")
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def credit(title: str) -> str:
|
| 254 |
+
"""BY-SA 4.0 §3(a)(2) allows attribution by a URI; the page history lists the authors."""
|
| 255 |
+
return f"Wikisłownik contributors, {page_url(title)}"
|
| 256 |
+
|
| 257 |
+
|
| 258 |
def iter_pages(dump_path: Path):
|
| 259 |
+
"""Yield (namespace, page id, title, wikitext) for every page, streaming the bz2 dump."""
|
| 260 |
with bz2.open(dump_path, "rb") as handle:
|
| 261 |
for _, element in ET.iterparse(handle, events=("end",)):
|
| 262 |
if element.tag.rsplit("}", 1)[-1] != "page":
|
|
|
|
| 264 |
values = {}
|
| 265 |
for child in element.iter():
|
| 266 |
tag = child.tag.rsplit("}", 1)[-1]
|
| 267 |
+
# The page's own <id> precedes its revision's <id>.
|
| 268 |
+
if tag in ("ns", "id", "title", "text") and tag not in values:
|
| 269 |
values[tag] = child.text
|
| 270 |
+
yield ((values.get("ns") or "").strip(), (values.get("id") or "").strip(),
|
| 271 |
+
values.get("title") or "", values.get("text") or "")
|
| 272 |
element.clear()
|
| 273 |
|
| 274 |
|
|
|
|
| 289 |
out_dir = Path(args.out).expanduser()
|
| 290 |
out_dir.mkdir(parents=True, exist_ok=True)
|
| 291 |
|
| 292 |
+
pages = entries = with_examples = with_citations = quoted_lines = example_lines = 0
|
| 293 |
+
documents: list[dict] = []
|
| 294 |
citation_index: list[dict] = []
|
| 295 |
|
| 296 |
+
for namespace, page_id, title, wikitext in iter_pages(dump_path):
|
| 297 |
pages += 1
|
| 298 |
if pages % 100_000 == 0:
|
| 299 |
print(f" {pages:,} pages scanned, {entries:,} Polish entries",
|
|
|
|
| 306 |
entries += 1
|
| 307 |
headword, body = section
|
| 308 |
examples, citations, dropped = examples_and_citations(body)
|
| 309 |
+
quoted_lines += dropped
|
| 310 |
if citations:
|
| 311 |
with_citations += 1
|
| 312 |
+
citation_index.append({"id": f"{SOURCE_NAME}_{page_id}", "headword": headword,
|
| 313 |
+
"citations": citations})
|
| 314 |
if not examples:
|
| 315 |
continue
|
| 316 |
with_examples += 1
|
| 317 |
+
example_lines += len(examples)
|
| 318 |
+
documents.append({"id": f"{SOURCE_NAME}_{page_id}", "text": "\n".join(examples),
|
| 319 |
+
"license": LICENSE, "author": credit(title)})
|
| 320 |
|
| 321 |
+
kept = [d for d in documents if len(d["text"]) >= args.min_chars]
|
| 322 |
+
chars = sum(len(d["text"]) for d in kept)
|
| 323 |
|
| 324 |
print()
|
| 325 |
print(f"pages scanned: {pages:,}")
|
| 326 |
print(f"Polish entries: {entries:,}")
|
| 327 |
print(f"entries with examples: {with_examples:,}")
|
| 328 |
print(f"entries with attribution: {with_citations:,}")
|
| 329 |
+
print(f"quoted lines dropped: {quoted_lines:,}")
|
| 330 |
+
print(f"example lines kept: {example_lines:,}")
|
| 331 |
print(f"documents >= {args.min_chars} chars: {len(kept):,}")
|
| 332 |
print(f"characters: {chars:,}")
|
| 333 |
|
| 334 |
payload = "\n".join(
|
| 335 |
+
json.dumps(document, ensure_ascii=False) for document in kept
|
|
|
|
|
|
|
| 336 |
) + "\n"
|
| 337 |
|
| 338 |
plain = out_dir / f"{SOURCE_NAME}.jsonl"
|
src/sources.py
CHANGED
|
@@ -158,20 +158,29 @@ SOURCES = {
|
|
| 158 |
"added": "2026-07-19",
|
| 159 |
"release": "0.2.5",
|
| 160 |
"file_key": "wiktionary_examples",
|
|
|
|
| 161 |
"pretty": "Polish Wiktionary usage examples",
|
| 162 |
"provenance": "Parsed directly from the official Wikimedia dump "
|
| 163 |
-
"
|
| 164 |
-
"
|
| 165 |
-
"
|
| 166 |
-
|
| 167 |
-
"
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
"domain": "lexicographic",
|
| 174 |
-
"created": "2004-03-22, 2026-
|
| 175 |
"is_ocr": False,
|
| 176 |
},
|
| 177 |
"eurlex": {
|
|
|
|
| 158 |
"added": "2026-07-19",
|
| 159 |
"release": "0.2.5",
|
| 160 |
"file_key": "wiktionary_examples",
|
| 161 |
+
"preserve_id": True,
|
| 162 |
"pretty": "Polish Wiktionary usage examples",
|
| 163 |
"provenance": "Parsed directly from the official Wikimedia dump "
|
| 164 |
+
"plwiktionary-20261001-pages-articles.xml.bz2 by "
|
| 165 |
+
"src/fetch_wiktionary_examples.py; not routed through SpeakLeash. "
|
| 166 |
+
"Usage-example sections of Polish-language entries, one document "
|
| 167 |
+
"per headword, id from the page id.",
|
| 168 |
+
"legal_note": "Quotations from third-party works are dropped: lines citing a source "
|
| 169 |
+
"with {{źródło}} or <ref>, lines naming one by hand (\"(B. Prus: "
|
| 170 |
+
"Lalka)\", \"(z Internetu)\") and excerpts marked \"(…)\". They are "
|
| 171 |
+
"used on Wiktionary under the quotation right (Art. 29) and are not "
|
| 172 |
+
"the contributors' CC BY-SA text. Unattributed quotations a contributor "
|
| 173 |
+
"pasted without any marker cannot be detected.",
|
| 174 |
+
"license": "CC-BY-SA-4.0",
|
| 175 |
+
"license_spdx": "CC-BY-SA-4.0",
|
| 176 |
+
"traceable": "Contributors license their text under CC BY-SA 4.0 (Wikimedia Terms "
|
| 177 |
+
"of Use, June 2023; pl.wiktionary footer). Revisions before that were "
|
| 178 |
+
"contributed under CC BY-SA 3.0, which allows an adaptation under a "
|
| 179 |
+
"later version (3.0 §4(b)). Each row's author field links its page, "
|
| 180 |
+
"whose history names the contributors (4.0 §3(a)(2)).",
|
| 181 |
+
"upstream": "https://dumps.wikimedia.org/plwiktionary/20261001/",
|
| 182 |
"domain": "lexicographic",
|
| 183 |
+
"created": "2004-03-22, 2026-10-01",
|
| 184 |
"is_ocr": False,
|
| 185 |
},
|
| 186 |
"eurlex": {
|
src/test_wiktionary_examples.py
CHANGED
|
@@ -21,7 +21,136 @@ def test_cited_lines_are_dropped_and_recorded():
|
|
| 21 |
assert dropped == 3
|
| 22 |
assert "Bolesław Prus | Lalka | 1890" in citations
|
| 23 |
assert any(c.startswith("Jan Nowak") for c in citations)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
def test_section_without_examples():
|
| 27 |
assert examples_and_citations("{{znaczenia}}\n: (1.1) dom\n") == ([], [], 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
assert dropped == 3
|
| 22 |
assert "Bolesław Prus | Lalka | 1890" in citations
|
| 23 |
assert any(c.startswith("Jan Nowak") for c in citations)
|
| 24 |
+
assert "Narodowy Korpus Języka Polskiego" in citations
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_every_ref_shape_leaves_a_record():
|
| 28 |
+
section = """{{przykłady}}
|
| 29 |
+
: (1.1) Pies szczeka.<ref name="nkjp" />
|
| 30 |
+
: (1.2) Kot śpi.<ref name=prus>{{źródło|autor=Bolesław Prus|tytuł=Lalka}}</ref>
|
| 31 |
+
: (1.3) Ptak śpiewa.<REF>[[NKJP]], 2001</REF>
|
| 32 |
+
: (1.4) Ryba pływa.<ref></ref>
|
| 33 |
+
: (1.5) Koń biegnie.<ref>{{NKJP|autorzy=Andrzej Sapkowski|tytuł_pub=Chrzest ognia|data=1996|hash=3eeeb574}}</ref>
|
| 34 |
+
: (1.6) Mysz piszczy.<ref>{{cytuj stronę | autor = Jan Kowal | url = https://example.pl/a }}</ref>
|
| 35 |
+
: (1.7) Wół ryczy.<ref>{{zWikiprojektu|Wikipedia|Wół}}</ref>
|
| 36 |
+
"""
|
| 37 |
+
examples, citations, dropped = examples_and_citations(section)
|
| 38 |
+
assert (examples, dropped) == ([], 7)
|
| 39 |
+
assert citations == sorted({'<ref name="nkjp"/>', "Bolesław Prus | Lalka", "NKJP, 2001",
|
| 40 |
+
"(no source text)", "Andrzej Sapkowski | Chrzest ognia | 1996",
|
| 41 |
+
"Jan Kowal | https://example.pl/a", "{{zWikiprojektu}}"})
|
| 42 |
|
| 43 |
|
| 44 |
def test_section_without_examples():
|
| 45 |
assert examples_and_citations("{{znaczenia}}\n: (1.1) dom\n") == ([], [], 0)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
import pytest
|
| 49 |
+
|
| 50 |
+
from fetch_wiktionary_examples import clean, hand_attribution
|
| 51 |
+
|
| 52 |
+
# Shapes taken from the plwiktionary 20261001 dump (sentences shortened).
|
| 53 |
+
QUOTED = [
|
| 54 |
+
("Podłoże trasy stanowiła błotnista glajda. (z Internetu)", "(z Internetu)"),
|
| 55 |
+
("Graficy trochę bardziej poszaleli. (Z internetu)", "(Z internetu)"),
|
| 56 |
+
("Za pokojem orędował Piotr Włostowic (Wikipedia)", "(Wikipedia)"),
|
| 57 |
+
("Obraz przedstawia cztery dziewczęta. (z Wikipedii)", "(z Wikipedii)"),
|
| 58 |
+
("Zbiornik wody rosły mury budynków. (B. Prus: Emancypantki)", "(B. Prus: Emancypantki)"),
|
| 59 |
+
("Żyła lat pięć z mężem. (J. I. Kraszewski: Ulana)", "(J. I. Kraszewski: Ulana)"),
|
| 60 |
+
("Czesz się, Jerzy, jak należy! (J. Brzechwa: Grzebień i szczotka)", "(J. Brzechwa: Grzebień i szczotka)"),
|
| 61 |
+
("Wrona gdzieniegdzie kracze. (Adam Mickiewicz)", "(Adam Mickiewicz)"),
|
| 62 |
+
("Rozmiary piwnic miały być wielkie. (K. Grzybowski)", "(K. Grzybowski)"),
|
| 63 |
+
("Ma pani wszystkich w domu? (Kogel-mogel)", "(Kogel-mogel)"),
|
| 64 |
+
("To leśniczówka Pranie. (W leśniczówce Konstanty Ildefons Gałczyński)",
|
| 65 |
+
"(W leśniczówce Konstanty Ildefons Gałczyński)"),
|
| 66 |
+
("Idź pan w chuj z takim żartem! (Kaliber 44: \"Litery\")", "(Kaliber 44: \"Litery\")"),
|
| 67 |
+
("Pójdźcie za Mną, a uczynię was rybakami ludzi (Mt 4:19)", "(Mt 4:19)"),
|
| 68 |
+
("Zła się nie ulęknę, bo Ty jesteś ze mną. (Ps 23, 4)", "(Ps 23, 4)"),
|
| 69 |
+
("Do pogrążenia narodu w ciemnocie (Tadeusz Boy-Żeleński: \"Dziewice\").", "(Tadeusz Boy-Żeleński: \"Dziewice\")"),
|
| 70 |
+
("Zobaczyli wywiad dla „Gazety Polskiej”. (Onet.pl)", "(Onet.pl)"),
|
| 71 |
+
("Wiersz o Odyseuszu. (z Odysei)", "(z Odysei)"),
|
| 72 |
+
("Ale nas zbaw ode złego (słowa modlitwy Ojcze Nasz)", "(słowa modlitwy Ojcze Nasz)"),
|
| 73 |
+
("Kiedy przyszła, powiedziała to. (źródło)", "(źródło)"),
|
| 74 |
+
("Uliczka Krakowa z wiersza Gałczyńskiego. Internet", "Internet"),
|
| 75 |
+
("Na płycie znalazły się utwory Lindy […] Wikipedia", "Wikipedia"),
|
| 76 |
+
("(…) potem pójdziemy 5 kilometrów na południe (…)", "(…)"),
|
| 77 |
+
("Na taką dolegliwość lekarze rozkładają ręce […] i tyle.", "[…]"),
|
| 78 |
+
("Rząd przyznał priorytet technologii. [...] i dalej", "[...]"),
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
# Contributor glosses and in-sentence words that must survive.
|
| 82 |
+
KEPT = [
|
| 83 |
+
"Kombinat ma dwie linie ciągłego odlewania stali (COS).",
|
| 84 |
+
"Rozpad ZSRR nastąpił w 1991 roku (ZSRR).",
|
| 85 |
+
"Jednostką jest kulomb na kilogram (C/kg).",
|
| 86 |
+
"Prawdopodobieństwo wynosi dziesięć procent (0,1).",
|
| 87 |
+
"Spokojniej proszę (od spokojnie).",
|
| 88 |
+
"Muszę jeszcze ugotować obiad (= Muszę jeszcze ugotować obiad.)",
|
| 89 |
+
"Każdy owoc pasuje (z wyjątkiem mleka kokosowego).",
|
| 90 |
+
"Stosuje się do tego regułę (z alternacją ch:sz).",
|
| 91 |
+
"Wszystkie te informacje pochodzą z Internetu.",
|
| 92 |
+
"Polska Wikipedia powstała 26 września 2001 roku.",
|
| 93 |
+
"Memy internetowe wykorzystuje się w reklamie.",
|
| 94 |
+
"Jaja jako bogate źródło substancji odżywczych są podstawą wielu potraw.",
|
| 95 |
+
"Mikołaj Kopernik był wybitnym astronomem (twierdzenie Ptolemeusza)",
|
| 96 |
+
"Ile to kosztuje? Cztery złocisze.",
|
| 97 |
+
"Bank miał siedzibę przy alei 1 Maja (ob. al. Piłsudskiego).",
|
| 98 |
+
"Hans Klawincker (fl. 1586-1635 w Norymberdze)",
|
| 99 |
+
"Mój przyjaciel mieszka w Bielsku-Białej (nie: Bielsko-Białej).",
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
@pytest.mark.parametrize("sentence,source", QUOTED)
|
| 104 |
+
def test_hand_written_source_marks_a_quotation(sentence, source):
|
| 105 |
+
assert hand_attribution(sentence) == source
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@pytest.mark.parametrize("sentence", KEPT)
|
| 109 |
+
def test_glosses_are_not_attributions(sentence):
|
| 110 |
+
assert hand_attribution(sentence) is None
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_hand_attributed_lines_are_dropped_and_recorded():
|
| 114 |
+
section = """{{przykłady}}
|
| 115 |
+
: (1.1) Kupiliśmy '''dom''' pod miastem.
|
| 116 |
+
: (1.1) Dom stał na wzgórzu. ([[Bolesław Prus|B. Prus]]: ''Lalka'')
|
| 117 |
+
: (1.2) Nasz dom ma ogród (…)
|
| 118 |
+
{{składnia}}
|
| 119 |
+
"""
|
| 120 |
+
examples, citations, dropped = examples_and_citations(section)
|
| 121 |
+
assert examples == ["Kupiliśmy dom pod miastem."]
|
| 122 |
+
assert dropped == 2
|
| 123 |
+
assert citations == ["(B. Prus: Lalka)", "(…)"]
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def test_inline_template_does_not_end_the_examples_block():
|
| 127 |
+
section = """{{przykłady}}
|
| 128 |
+
: (1.1) ''Dziesięć małych Murzyniątek.'' (A. Christie: ''Dziesięciu Murzynków'', {{tłum}} Włodzimierz Lewik)
|
| 129 |
+
: (1.2) Kupiliśmy '''dom''' pod miastem.
|
| 130 |
+
{{składnia}}
|
| 131 |
+
: (1.1) To nie jest przykład, tylko składnia.
|
| 132 |
+
"""
|
| 133 |
+
examples, citations, dropped = examples_and_citations(section)
|
| 134 |
+
assert examples == ["Kupiliśmy dom pod miastem."]
|
| 135 |
+
assert dropped == 1
|
| 136 |
+
assert citations == ["(A. Christie: Dziesięciu Murzynków, Włodzimierz Lewik)"]
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def test_clean_separates_br_and_drops_empty_parens():
|
| 140 |
+
assert clean("na wzgórzu<br />to leśniczówka") == "na wzgórzu to leśniczówka"
|
| 141 |
+
assert clean("() Holdek ciepnył bala z autu.") == "Holdek ciepnył bala z autu."
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def test_page_id_title_and_credit(tmp_path):
|
| 145 |
+
import bz2
|
| 146 |
+
|
| 147 |
+
from fetch_wiktionary_examples import credit, iter_pages
|
| 148 |
+
|
| 149 |
+
dump = tmp_path / "dump.xml.bz2"
|
| 150 |
+
dump.write_bytes(bz2.compress("""<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.11/">
|
| 151 |
+
<page><title>wielki piec</title><ns>0</ns><id>42</id>
|
| 152 |
+
<revision><id>9001</id><text>== wielki piec ({{język polski}}) ==</text></revision></page>
|
| 153 |
+
</mediawiki>""".encode("utf-8")))
|
| 154 |
+
assert list(iter_pages(dump)) == [("0", "42", "wielki piec", "== wielki piec ({{język polski}}) ==")]
|
| 155 |
+
assert credit("wielki piec") == "Wikisłownik contributors, https://pl.wiktionary.org/wiki/wielki_piec"
|
| 156 |
+
assert credit("żółw") == "Wikisłownik contributors, https://pl.wiktionary.org/wiki/%C5%BC%C3%B3%C5%82w"
|
src/test_wiktionary_examples_contract.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contract checks for the released wiktionary_examples data (src/fetch_wiktionary_examples.py)."""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import pyarrow.parquet as pq
|
| 8 |
+
|
| 9 |
+
from fetch_wiktionary_examples import LICENSE, PAGE_URL, hand_attribution
|
| 10 |
+
from sources import SOURCES
|
| 11 |
+
|
| 12 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 13 |
+
DATA = ROOT / "data" / "wiktionary_examples"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_schema_counts_license_and_attribution():
|
| 17 |
+
stats = json.loads((DATA / "wiktionary_examples.stats.json").read_text(encoding="utf-8"))
|
| 18 |
+
evidence = json.loads((DATA / "wiktionary_examples.license-evidence.json").read_text(encoding="utf-8"))
|
| 19 |
+
table = pq.read_table(DATA / "wiktionary_examples.parquet")
|
| 20 |
+
rows = table.select(["id", "source", "license", "author"]).to_pylist()
|
| 21 |
+
entry = SOURCES["wiktionary_examples"]
|
| 22 |
+
assert table.column_names == ["id", "text", "source", "added", "created", "token_count", "license", "author"]
|
| 23 |
+
assert table.num_rows == stats["kept"] == evidence["release_scope"]["documents_released"]
|
| 24 |
+
assert stats["read"] == evidence["release_scope"]["documents_200_chars_or_more"]
|
| 25 |
+
assert stats["drop_dup"] == evidence["release_scope"]["dropped_duplicates"]
|
| 26 |
+
assert len({r["id"] for r in rows}) == table.num_rows
|
| 27 |
+
assert all(re.fullmatch(r"wiktionary_examples_\d+", r["id"]) for r in rows)
|
| 28 |
+
assert {r["source"] for r in rows} == {"wiktionary_examples"}
|
| 29 |
+
assert {r["license"] for r in rows} == {LICENSE} == {entry["license"]} == {entry["license_spdx"]} == {evidence["license"]}
|
| 30 |
+
assert stats["licenses"] == {LICENSE: table.num_rows}
|
| 31 |
+
assert entry["preserve_id"] is True
|
| 32 |
+
assert all(r["author"].startswith(f"Wikisłownik contributors, {PAGE_URL}") for r in rows)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def test_no_quotation_reached_the_release():
|
| 36 |
+
for text in pq.read_table(DATA / "wiktionary_examples.parquet", columns=["text"]).column("text").to_pylist():
|
| 37 |
+
assert len(text) >= 200
|
| 38 |
+
assert "<ref" not in text.lower() and "{{" not in text
|
| 39 |
+
for line in text.split("\n"):
|
| 40 |
+
assert hand_attribution(line) is None, line
|