| | 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' |
| |
|
| | word_database = load_word_database(database_filename) |
| | check_generated_conversation_for_words(csv_filename, word_database) |
| |
|
| | if __name__ == "__main__": |
| | main() |
| |
|
| |
|
| |
|