wangzhibo
2023-07-25 2ccac51ebb1d41c4dd6d2e07f6eb34f75a03210c
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
 
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
import sys
from numpy import *
 
 
'''
 
从 pdf 转成的excel文件; 再保存成txt文件之后的一行多字,处理成单行的清单。
 
txt文件中,可能会有OCR识别错误的汉字,出现英文字母,如fft等,这种要对比原始pdf文件,手工改成正确的文字。
 
 
step1:去除序号和文字为空的行;
step2:把括号去掉,即删除含括号在内的内容
step3:去重: 因为有多音字,因此 会出现同一个两条记录的情况,如 了(le)  了 (liao) ---暂时未做
 
'''
src_file = sys.argv[1]
dst_file = sys.argv[2]
 
dst_file_4 = sys.argv[3]
 
dst_file_2 = sys.argv[4]
 
 
array_all_words = []
 
 
last_count = 0
with open(src_file, 'r', encoding='utf-8-sig') as f:
     for word in f.read().splitlines():
        chars = word.split(';')
        for item in chars :
            char_index = item.split(',')
            #print(char_index[0])
            #print(char_index[1])
            char_a = char_index[1]
            try:
                if char_a.index('(') > -1 :
                    char_a = char_a[0:char_a.index('(')]
            except:
                print()
            try:
                if char_a.index('(') > -1 :
                    char_a = char_a[0:char_a.index('(')]
            except:
                print()
            
            if int(last_count - int(char_index[0]))  >200:
                print(last_count)
                print(item)
            
            array_all_words.append([int(char_index[0]),char_a])
            last_count = int(char_index[0])
 
 
words_sorted = sorted(array_all_words, key =lambda array_all_words:array_all_words[0])
#words_argsorted = sorted(array_all_words, key =lambda array_all_words:array_all_words[0],reverse=True)
#print(words_sorted)
 
tmp_index = 1
 
with open(dst_file, 'w', encoding='utf-8') as final_f:
    for item in words_sorted:
        final_f.write(str(tmp_index)+';'+item[1])
        final_f.write('\n')
        tmp_index = tmp_index +1
 
with open(dst_file_4, 'w', encoding='utf-8') as final_f:
    for item in words_sorted:
        if len(item[1]) == 4:
            final_f.write(item[1])
            final_f.write('\n')
 
with open(dst_file_2, 'w', encoding='utf-8') as final_f:
    for item in words_sorted:
        if len(item[1]) ==2:
            final_f.write(item[1])
            final_f.write('\n')