Skip to content

Commit 530309f

Browse files
committed
new script in progress
1 parent 630e56f commit 530309f

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import re
4+
from peyutil import read_as_json
5+
6+
no_app_pat = re.compile(r"^amende?ment [#](\d+) not applied:")
7+
homonym_pat = re.compile(r"^amende?ment [#](\d+) not applied: ([A-Za-z][-A-Za-z0-9 ]+[A-Za-z0-9]) is a homonym of (\d+)")
8+
9+
def check_if_del_works(amend_num, name, ott_id, edott, amendments_repo):
10+
exp_amend_idx = amend_num - 1
11+
rel_amends = []
12+
for amend_idx, amend in enumerate(edott):
13+
if amend.get("action", "") != "add":
14+
continue
15+
taxon = amend.get("taxon", {})
16+
tn = taxon.get("name", "")
17+
if tn.strip() == name:
18+
rel_amends.append((amend_idx, amend))
19+
if len(rel_amends) < 2:
20+
return (False, "solo")
21+
if rel_amends[0][0] == exp_amend_idx:
22+
return False, "first"
23+
found = False
24+
for ra in rel_amends[1:]:
25+
if ra[0] == exp_amend_idx:
26+
found = True
27+
break
28+
if not found:
29+
return False, "notfound"
30+
return True, ""
31+
32+
def main(edott_fp,
33+
logfile,
34+
amendments_repo):
35+
to_del = []
36+
edott = read_as_json(edott_fp)
37+
with open(logfile, "r") as logf:
38+
for line in logf:
39+
m = no_app_pat.match(line)
40+
if m:
41+
hm = homonym_pat.match(line)
42+
if hm:
43+
amend_num = int(hm.group(1))
44+
name = hm.group(2)
45+
ott_id = int(hm.group(3))
46+
print(amend_num, name, ott_id)
47+
rc = check_if_del_works(amend_num, name, ott_id, edott, amendments_repo)
48+
if rc[0]:
49+
to_del.append(amend_num)
50+
else:
51+
prob = rc[1]
52+
if prob == "solo":
53+
print("Atypical homonym. Solo in amendments {amend_num}:", edott[amend_num -1])
54+
elif prob == "notfound":
55+
print("PROBLEM {amend_num} does not match:", edott[amend_num -1])
56+
else:
57+
assert(prob == "first")
58+
print("Atypical homonym. First in amendments {amend_num} is bad:", edott[amend_num -1])
59+
else:
60+
print(m.group(1), "not a homonym")
61+
62+
if __name__ == "__main__":
63+
try:
64+
_args = list(sys.argv[1:4])
65+
assert(len(_args) == 3)
66+
except:
67+
sys.exit("Expecting 3 arguments: the edott JSON, the logfile from the failed run, and the directory that holds the amendments-1 repo.")
68+
main(edott_fp=_args[0],
69+
logfile=_args[1],
70+
amendments_repo=_args[2])

0 commit comments

Comments
 (0)