|
#!/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')
|