-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_latin_participles.py
84 lines (74 loc) · 2.41 KB
/
convert_latin_participles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pywikibot, re, sys, argparse
import blib
from blib import getparam, rmparam, tname, msg, site
import lalib
def process_page(page, index, parsed):
pagetitle = str(page.title())
def pagemsg(txt):
msg("Page %s %s: %s" % (index, pagetitle, txt))
notes = []
pagemsg("Processing")
for t in parsed.filter_templates():
origt = str(t)
tn = tname(t)
allow_2 = False
lemma = None
if tn in ["la-future participle", "la-perfect participle", "la-gerundive"]:
base = getparam(t, "1")
if tn == "la-gerundive":
param2 = getparam(t, "2")
if param2:
if lalib.remove_macrons(base) == lalib.remove_macrons(param2):
allow_2 = True
base = param2
else:
pagemsg("WARNING: Unrecognized param 2: %s" % origt)
continue
if not base:
pagemsg("WARNING: Empty param 1: %s" % origt)
continue
lemma = base + "us"
elif tn == "la-present participle":
base = getparam(t, "1")
ending = getparam(t, "2")
if not base:
pagemsg("WARNING: Empty param 1: %s" % origt)
continue
if not ending:
pagemsg("WARNING: Empty param 2: %s" % origt)
continue
if ending == "ans":
lemma = base + "āns"
elif ending == "ens":
lemma = base + "ēns"
elif ending == "iens":
lemma = "%siēns/%seunt" % (base, base)
else:
pagemsg("WARNING: Unrecognized param 2: %s" % origt)
continue
allow_2 = True
if lemma:
bad_param = False
for param in t.params:
pname = str(param.name)
if pname.strip() == "1" or allow_2 and pname.strip() == "2":
continue
pagemsg("WARNING: Unrecognized param %s=%s: %s" % (
pname, param.value, origt))
bad_param = True
if bad_param:
continue
rmparam(t, "2")
t.add("1", lemma)
blib.set_template_name(t, "la-part")
pagemsg("Replaced %s with %s" % (origt, str(t)))
notes.append("convert {{%s}} to {{la-part}}" % tn)
return str(parsed), notes
parser = blib.create_argparser("Convert Latin participle headwords to use {{la-part}}",
include_pagefile=True)
args = parser.parse_args()
start, end = blib.parse_start_end(args.start, args.end)
blib.do_pagefile_cats_refs(args, start, end, process_page,
default_cats=["Latin participles"], edit=True)