ppuzio Claude Opus 5.5 commited on
Commit
049bad4
·
1 Parent(s): 64b093f

wiktionary_examples: drop cited example lines (WIP)

Browse files

A usage example carrying {{źródło|…}}, {{zrodlo|…}} or <ref> is a quotation
from a third-party work, used on Wiktionary under the Art. 29 quotation right,
not contributor text licensed CC BY-SA. The fetcher now drops those lines and
records their citations in the audit side-car.

On the 2026-10-01 dump: 32,280 cited lines dropped, 45,547 uncited kept;
1,915 documents (558,105 chars) pass the 200-char gate.

Not yet done: filter for untemplated attributions such as "(z Internetu)" or
"(Autor: Tytuł)", rebuild of data/wiktionary_examples/, datasheet and registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

src/fetch_wiktionary_examples.py CHANGED
@@ -9,10 +9,11 @@ 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; all its example sentences are concatenated,
13
- newline-separated, in source order. Citation attribution found in
14
- `{{źródło|...}}` templates is stripped from the text and written to a
15
- side-car file for auditing (not part of the corpus).
 
16
 
17
  Only the standard library is required for parsing; `zstandard` is used for
18
  output compression (falls back to plain .jsonl with a warning).
@@ -58,6 +59,7 @@ NUMBERED_LINE = re.compile(r"^:\s*\(([\d.]+)\)\s*(.+?)\s*$", re.M)
58
  SENSE_NUMBER = re.compile(r"\(\d+\.\d+\)")
59
 
60
  CITATION_FIELDS = ("autor", "tytuł", "tytul", "rozdział", "rozdzial", "rok", "isbn")
 
61
 
62
 
63
  def split_templates(text: str) -> tuple[str, list[str]]:
@@ -147,22 +149,32 @@ def polish_section(wikitext: str) -> tuple[str, str] | None:
147
  return headword, rest
148
 
149
 
150
- def examples_and_citations(section: str) -> tuple[list[str], list[str]]:
 
 
 
 
 
 
 
151
  match = EXAMPLES_BLOCK.search(section)
152
  if not match:
153
- return [], []
154
- examples, citations = [], []
155
  for _, raw in NUMBERED_LINE.findall(match.group(1)):
156
  without_templates, templates = split_templates(raw)
157
- for template in templates:
158
- if template.startswith(("{{źródło", "{{zrodlo")):
159
- described = describe_citation(clean(template))
160
- if described:
161
- citations.append(described)
 
 
 
162
  sentence = clean(without_templates)
163
  if len(sentence) >= MIN_EXAMPLE_CHARS:
164
  examples.append(sentence)
165
- return examples, sorted(set(citations))
166
 
167
 
168
  def iter_pages(dump_path: Path):
@@ -197,7 +209,7 @@ def main() -> None:
197
  out_dir = Path(args.out).expanduser()
198
  out_dir.mkdir(parents=True, exist_ok=True)
199
 
200
- pages = entries = with_examples = with_citations = 0
201
  documents: list[tuple[str, str]] = []
202
  citation_index: list[dict] = []
203
 
@@ -213,13 +225,15 @@ def main() -> None:
213
  continue
214
  entries += 1
215
  headword, body = section
216
- examples, citations = examples_and_citations(body)
217
- if not examples:
218
- continue
219
- with_examples += 1
220
  if citations:
221
  with_citations += 1
222
  citation_index.append({"headword": headword, "citations": citations})
 
 
 
 
223
  documents.append((headword, "\n".join(examples)))
224
 
225
  kept = [(h, t) for h, t in documents if len(t) >= args.min_chars]
@@ -230,6 +244,8 @@ def main() -> None:
230
  print(f"Polish entries: {entries:,}")
231
  print(f"entries with examples: {with_examples:,}")
232
  print(f"entries with attribution: {with_citations:,}")
 
 
233
  print(f"documents >= {args.min_chars} chars: {len(kept):,}")
234
  print(f"characters: {chars:,}")
235
 
 
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 uncited example sentences are concatenated,
13
+ newline-separated, in source order. A line carrying a `{{źródło|...}}` template
14
+ or a `<ref>` is a quotation from a third-party work (used under the Art. 29
15
+ quotation right, not licensed CC BY-SA by Wiktionary contributors), so it is
16
+ dropped; its citation goes to a side-car file for auditing (not part of the corpus).
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).
 
59
  SENSE_NUMBER = re.compile(r"\(\d+\.\d+\)")
60
 
61
  CITATION_FIELDS = ("autor", "tytuł", "tytul", "rozdział", "rozdzial", "rok", "isbn")
62
+ CITATION_TEMPLATES = ("{{źródło", "{{zrodlo")
63
 
64
 
65
  def split_templates(text: str) -> tuple[str, list[str]]:
 
149
  return headword, rest
150
 
151
 
152
+ def is_cited(raw: str, templates: list[str]) -> bool:
153
+ """A line with a source attached is a quotation from a third-party work (Art. 29
154
+ quotation right), not a contributor's own CC BY-SA text."""
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
+ """(uncited example sentences, citations of the dropped lines, number of dropped lines)."""
160
  match = EXAMPLES_BLOCK.search(section)
161
  if not match:
162
+ return [], [], 0
163
+ examples, citations, dropped = [], [], 0
164
  for _, raw in NUMBERED_LINE.findall(match.group(1)):
165
  without_templates, templates = split_templates(raw)
166
+ if is_cited(raw, templates):
167
+ dropped += 1
168
+ for template in templates:
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):
 
209
  out_dir = Path(args.out).expanduser()
210
  out_dir.mkdir(parents=True, exist_ok=True)
211
 
212
+ pages = entries = with_examples = with_citations = cited_lines = uncited_lines = 0
213
  documents: list[tuple[str, str]] = []
214
  citation_index: list[dict] = []
215
 
 
225
  continue
226
  entries += 1
227
  headword, body = section
228
+ examples, citations, dropped = examples_and_citations(body)
229
+ cited_lines += dropped
 
 
230
  if citations:
231
  with_citations += 1
232
  citation_index.append({"headword": headword, "citations": citations})
233
+ if not examples:
234
+ continue
235
+ with_examples += 1
236
+ uncited_lines += len(examples)
237
  documents.append((headword, "\n".join(examples)))
238
 
239
  kept = [(h, t) for h, t in documents if len(t) >= args.min_chars]
 
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"cited lines dropped: {cited_lines:,}")
248
+ print(f"uncited lines kept: {uncited_lines:,}")
249
  print(f"documents >= {args.min_chars} chars: {len(kept):,}")
250
  print(f"characters: {chars:,}")
251
 
src/test_wiktionary_examples.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Cited usage examples are third-party quotations and must not reach the corpus."""
2
+
3
+ from fetch_wiktionary_examples import examples_and_citations
4
+
5
+ SECTION = """{{znaczenia}}
6
+ ''rzeczownik''
7
+ : (1.1) [[dom]]
8
+ {{przykłady}}
9
+ : (1.1) Kupiliśmy '''dom''' pod miastem.
10
+ : (1.1) ''Dom stał na wzgórzu.'' {{źródło|autor=Bolesław Prus|tytuł=Lalka|rok=1890}}
11
+ : (1.2) Wróciłem do domu późno.<ref>Narodowy Korpus Języka Polskiego</ref>
12
+ : (1.2) Nasz '''dom''' ma ogród. {{zrodlo|autor=Jan Nowak|tytuł={{kursywa|Ogrody}}}}
13
+ : (1.3) To [[mieszkanie|mieszkanie]] jest jasne i ciche.
14
+ {{składnia}}
15
+ """
16
+
17
+
18
+ def test_cited_lines_are_dropped_and_recorded():
19
+ examples, citations, dropped = examples_and_citations(SECTION)
20
+ assert examples == ["Kupiliśmy dom pod miastem.", "To mieszkanie jest jasne i ciche."]
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)