Bug493-GongKeCheng
parent
a5c792b782
commit
654fd52c44
|
@ -37,14 +37,6 @@ def file2str(fname):#文件转字符
|
||||||
f.close() #关闭
|
f.close() #关闭
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def str2chararray(str): # 字符串转字符数组
|
|
||||||
chararray = []
|
|
||||||
for i in range(len(str)):
|
|
||||||
chararray.append(str[i])
|
|
||||||
return chararray
|
|
||||||
|
|
||||||
|
|
||||||
def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。
|
def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。
|
||||||
|
|
||||||
# carr = str2chararray(s) # 字符串转字符数组
|
# carr = str2chararray(s) # 字符串转字符数组
|
||||||
|
@ -52,22 +44,9 @@ def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用
|
||||||
special_characters = '&_~=+[]%^@.,?!:;#()"“”—‘’|/\\<>{}' # 把里面的字符都去掉
|
special_characters = '&_~=+[]%^@.,?!:;#()"“”—‘’|/\\<>{}' # 把里面的字符都去掉
|
||||||
special_words = ('$lt', '$gt', '$') # 特殊词汇
|
special_words = ('$lt', '$gt', '$') # 特殊词汇
|
||||||
|
|
||||||
special_characters = '\_©~<=>+-/[]*&$%^@.,?!:;#()"“”—‘’{}|' # 把里面的字符都去掉
|
|
||||||
|
|
||||||
for c in special_characters:
|
for c in special_characters:
|
||||||
s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况
|
s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况
|
||||||
carr = str2chararray(s) # 字符串转字符数组
|
|
||||||
for i, value in enumerate(carr):
|
|
||||||
if value == '&': # 遍历替换
|
|
||||||
carr[i] = '\''
|
|
||||||
print('sss' + s)
|
|
||||||
for j in range(1,5):
|
|
||||||
if carr[i+j] in [' ','3','9']:
|
|
||||||
carr[i + j]=''
|
|
||||||
s = ''.join(carr) # 字符数组转字符串
|
|
||||||
print('sss'+s)
|
|
||||||
for w in special_words: # 替换字符串中的剩余特殊字符
|
|
||||||
s = s.replace(w, ' ')
|
|
||||||
s = s.replace('--', ' ')
|
s = s.replace('--', ' ')
|
||||||
s = s.strip() # 去除前后的空格
|
s = s.strip() # 去除前后的空格
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue