/
fix_8.py
57 lines (48 loc) · 1.88 KB
/
fix_8.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pywikibot, re, sys, argparse
import blib
from blib import getparam, rmparam, msg, site
import rulib
def process_page(page, index, parsed):
pagetitle = str(page.title())
def pagemsg(txt):
msg("Page %s %s: %s" % (index, pagetitle, txt))
pagemsg("Processing")
text = str(page.text)
parsed = blib.parse(page)
notes = []
for t in parsed.filter_templates():
origt = str(t)
param2 = getparam(t, "2")
if str(t.name) in ["ru-conj"] and re.search(r"^8[ab]", param2):
if [x for x in t.params if str(x.value) == "or"]:
pagemsg("WARNING: Skipping multi-arg conjugation: %s" % str(t))
continue
past_m = getparam(t, "past_m")
if past_m:
rmparam(t, "past_m")
stem = getparam(t, "3")
if stem == past_m:
pagemsg("Stem %s and past_m same" % stem)
notes.append("remove redundant past_m %s" % past_m)
elif (param2.startswith("8b") and not param2.startswith("8b/") and
rulib.make_unstressed_ru(past_m) == stem):
pagemsg("Class 8b/b and stem %s is unstressed version of past_m %s, replacing stem with past_m" % (
stem, past_m))
t.add("3", past_m)
notes.append("moving past_m %s to arg 3" % past_m)
else:
pagemsg("Stem %s and past_m %s are different, putting past_m in param 5" % (
stem, past_m))
t.add("5", past_m)
notes.append("moving past_m %s to arg 5" % past_m)
newt = str(t)
if origt != newt:
pagemsg("Replaced %s with %s" % (origt, newt))
return str(parsed), notes
parser = blib.create_argparser("Fix up class-8 arguments", 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, edit=True,
default_cats=["Russian class 8 verbs"])