File size: 1,192 Bytes
ca165c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import csv

def load_word_database(database_filename):
    with open(database_filename, mode='r', encoding='utf-8') as database_file:
        return set(word.strip().lower() for word in database_file)

def check_generated_conversation_for_words(csv_filename, word_database):
    with open(csv_filename, mode='r', newline='', encoding='utf-8') as csv_file:
        csv_reader = csv.DictReader(csv_file)
        for row in csv_reader:
            generated_conversation = row.get('Generated Conversation', '').lower()
            for word in generated_conversation.split():
                if word in word_database:
                    save_word_to_csv(word)

def save_word_to_csv(word):
    output_csv_filename = "text.csv"
    with open(output_csv_filename, mode='w', newline='', encoding='utf-8') as output_csv_file:
        csv_writer = csv.writer(output_csv_file)
        csv_writer.writerow([word])

def main():
    database_filename = 'word_database.txt'
    csv_filename = 'info.csv'  # Replace with your CSV file

    word_database = load_word_database(database_filename)
    check_generated_conversation_for_words(csv_filename, word_database)

if __name__ == "__main__":
    main()