|
|
import csv
|
|
|
|
|
|
greeting_file = 'D:/greeting-introduction/greeting.text'
|
|
|
introduction_file = 'D:/greeting-introduction/introduction.txt'
|
|
|
|
|
|
def clean_quotes(text):
|
|
|
|
|
|
return text.replace('"""', '').replace('"', '').replace("'''", '').replace("'", '').strip()
|
|
|
|
|
|
|
|
|
with open(greeting_file, 'r', encoding='utf-8') as f:
|
|
|
greeting_text = set(clean_quotes(line) for line in f if clean_quotes(line))
|
|
|
|
|
|
|
|
|
with open(introduction_file, 'r', encoding='utf-8') as f:
|
|
|
introduction_text = set(clean_quotes(line) for line in f if clean_quotes(line))
|
|
|
|
|
|
|
|
|
data = []
|
|
|
|
|
|
|
|
|
for line in greeting_text:
|
|
|
if line:
|
|
|
data.append([line, 1])
|
|
|
|
|
|
|
|
|
for line in introduction_text:
|
|
|
if line:
|
|
|
data.append([line, 0])
|
|
|
|
|
|
|
|
|
csv_file = 'preprocess.csv'
|
|
|
with open(csv_file, 'w', newline='', encoding='utf-8') as f:
|
|
|
writer = csv.writer(f)
|
|
|
writer.writerow(['Text', 'Label'])
|
|
|
writer.writerows(data)
|
|
|
|
|
|
print(f"Data has been written to {csv_file} with duplicates removed and quotes cleaned")
|
|
|
|