-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge_list_of_lists.py
executable file
·52 lines (44 loc) · 1.3 KB
/
merge_list_of_lists.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
#!/usr/bin/env python3
import json
import sys
from itertools import combinations
from file.similars_file import SimilarsFile
from file.not_similar_file import NotSimilar
def main():
with open(sys.argv[1]) as f:
data = json.load(f)
similar = SimilarsFile('kanji.tgz_similars.ut8')
not_similar = NotSimilar()
queue = []
skipped = 0
for group in data:
for c1, c2 in combinations(group, 2):
if c1 not in similar.get_similar(c2) and c1 not in not_similar.get(c2):
queue.append((c1, c2))
else:
skipped += 1
auto = False
if len(sys.argv) > 2 and sys.argv[2] == 'auto':
auto = True
for pair in queue:
print(''.join(pair))
print(len(queue))
print('skipped: {}'.format(skipped))
for c1, c2 in queue:
if c1 in similar.get_similar(c2):
continue
if auto:
similar.set_similar(c1, c2)
else:
i = input('Do {} and {} look similar? (Y/n/a(bort))'.format(c1, c2))
if i == 'n':
not_similar.add(c1, c2)
continue
if i == 'a':
break
else:
similar.set_similar(c1, c2)
similar.write()
not_similar.write()
if __name__ == '__main__':
main()