wangzhibo
2023-08-30 38198e716dea44c698b31c5abaf74dac32173edb
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
 
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
import sys
 
 
'''
在第一个文件的基础上,添加后续的全部不重复的2字词语。 再加一个限定条件,即新加的2个字全部都属于一级字表。
 
'''
 
_list_unique = set()
_list_temp = set()
 
base_txt_file = sys.argv[1]
new_added_txt_file =sys.argv[2]
base_txt_file_with_added = sys.argv[3]
 
level1_words_file =  'universal_char_list_1_3500.txt'
 
level1_words = ''
with open(level1_words_file, 'r', encoding='utf-8-sig') as f:
    level1_words = f.read().splitlines()
 
with open(base_txt_file, 'r', encoding='utf-8-sig') as f:
        for word in f.read().splitlines():
            _list_unique.add(word[0])
            _list_unique.add(word[1])
            _list_unique.add(word[2])
            _list_unique.add(word[3])
 
def if_all_level_one(word):
    for char in word:
        try:
            _index = level1_words[0].index(char) 
        except:
            return False
    return True
 
 
print(len(_list_unique))
with open(base_txt_file_with_added, 'w', encoding='utf-8') as final_f:
    with open(new_added_txt_file, 'r', encoding='utf-8-sig') as f:
        for word in f.read().splitlines():
            #print(word)
            if len(word) == 2:
                
                _list_temp = _list_unique.copy()
                _list_temp.add(word[0])
                _list_temp.add(word[1])
 
                if len(_list_temp) - len(_list_unique) == 2:
                    if if_all_level_one(word):
                        _list_unique.add(word[0])
                        _list_unique.add(word[1])
                        final_f.write(word)
                        final_f.write('\n')
            else:
                print(word)
                print(len(word))