-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreplace.py
46 lines (36 loc) · 1.15 KB
/
replace.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
import csv
from shutil import copyfile
import re
metadata = csv.reader(open('metadata.csv', newline=''), delimiter=',', quotechar='|')
data = []
for row in metadata:
data.append(row[0])
data = data[1:]
for id in data:
filename = "corpus/"+id+".txt"
file = open(filename, encoding='utf-8', errors='replace')
try :
fileContent = file.read()
file.close()
fileContent = fileContent.replace("~", "")
fileContent = fileContent.replace("�", "'")
fileContent = fileContent.replace("—", "-")
fileContent = fileContent.replace("-------", "-")
fileContent = fileContent.replace("------", "-")
fileContent = fileContent.replace("-----", "-")
fileContent = fileContent.replace("----", "-")
fileContent = fileContent.replace("---", "-")
fileContent = fileContent.replace("--", "-")
file = open("corpus2/"+id+".txt", "w", encoding="utf-8")
file.write(fileContent)
file.close()
except UnicodeDecodeError:
print(id)
file.close()
copyfile(filename, "corpus2/"+id+".txt")
for id in data:
filename = "corpus2/"+id+".txt"
file = open(filename, encoding='utf-8', errors='replace')
fileContent = file.read()
if "--" in fileContent:
print(id)