File size: 1,310 Bytes
f4fdbd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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")