import csv greeting_file = 'D:/greeting-introduction/greeting.text' introduction_file = 'D:/greeting-introduction/introduction.txt' def clean_quotes(text): # Remove all types of quotes while preserving the text return text.replace('"""', '').replace('"', '').replace("'''", '').replace("'", '').strip() # Read and clean greeting text with open(greeting_file, 'r', encoding='utf-8') as f: greeting_text = set(clean_quotes(line) for line in f if clean_quotes(line)) # Read and clean introduction text with open(introduction_file, 'r', encoding='utf-8') as f: introduction_text = set(clean_quotes(line) for line in f if clean_quotes(line)) # Create data list with cleaned text data = [] # Add greeting text with label 1 for line in greeting_text: if line: # Only add non-empty lines data.append([line, 1]) # Add introduction text with label 0 for line in introduction_text: if line: # Only add non-empty lines data.append([line, 0]) # Write to CSV file 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")