File size: 920 Bytes
db30823
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import json
import pandas as pd
import os

os.makedirs("dataset/topic_ner", exist_ok=True)
for s in ["test.jsonl", "train.jsonl", "validation.jsonl"]:
    with open(f"dataset/topic/{s}") as f:
        topic = pd.DataFrame([json.loads(i) for i in f.read().split("\n") if len(i) > 0])
    with open(f"dataset/ner/{s}") as f:
        ner = pd.DataFrame([json.loads(i) for i in f.read().split("\n") if len(i) > 0])
    topic.index = topic.pop("id")
    ner.index = ner.pop("id")
    df_merge = pd.merge(topic, ner, left_index=True, right_index=True)
    df_merge['text'] = df_merge.pop("text_x")
    df_merge['date'] = df_merge.pop("date_x")
    df_merge.pop("text_y")
    df_merge.pop("date_y")
    df_merge['condition'] = df_merge.pop("condition_x") + " \n" + df_merge.pop("condition_y")
    with open(f"dataset/topic_ner/{s}", "w") as f:
        f.write("\n".join([json.dumps(i) for i in df_merge.T.to_dict().values()]))