|
|
import json |
|
|
import csv |
|
|
|
|
|
|
|
|
jsonl_file_path = '/mnt/afs/xueyingyi/meme/generate/user_input_descriptions_simple.jsonl' |
|
|
csv_file_path = '/mnt/afs/xueyingyi/meme/generate/E_text.csv' |
|
|
output_csv_path = '/mnt/afs/xueyingyi/meme/generate/text_pipeline_label.csv' |
|
|
|
|
|
|
|
|
text_dict = {} |
|
|
with open(csv_file_path, 'r', encoding='ISO-8859-1') as csv_file: |
|
|
csv_reader = csv.DictReader(csv_file) |
|
|
for row in csv_reader: |
|
|
file_name = row['file_name'] |
|
|
text = row['text'] |
|
|
text_dict[file_name] = text |
|
|
|
|
|
|
|
|
with open(jsonl_file_path, 'r') as jsonl_file, open(output_csv_path, 'w', newline='', encoding='utf-8') as output_csv: |
|
|
csv_writer = csv.writer(output_csv) |
|
|
|
|
|
|
|
|
csv_writer.writerow([ |
|
|
'file_name', 'Emotion Category', 'Emotion Intensity', 'Text Content Keywords', 'text' |
|
|
]) |
|
|
|
|
|
|
|
|
for line in jsonl_file: |
|
|
try: |
|
|
data = json.loads(line.strip()) |
|
|
except json.JSONDecodeError as e: |
|
|
print(f"JSON解析错误: {e},跳过此行: {line}") |
|
|
continue |
|
|
|
|
|
file_name = data['file_name'] |
|
|
user_input = data['user_input'] |
|
|
|
|
|
|
|
|
emotion_category = user_input['Emotion Category'] |
|
|
emotion_intensity = user_input['Emotion Intensity'] |
|
|
text_content_keywords = ', '.join(user_input['Text Content Keywords']) |
|
|
text = text_dict.get(file_name, '') |
|
|
|
|
|
|
|
|
csv_writer.writerow([ |
|
|
file_name, emotion_category, emotion_intensity, text_content_keywords, text |
|
|
]) |
|
|
|
|
|
print(f"CSV文件已生成: {output_csv_path}") |