-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriplet.py
28 lines (26 loc) · 1.03 KB
/
Triplet.py
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
import json
def extract_triplet(language,text, mode = "main"):
return_triplet = []
if mode == "test":
if language=="en":
path = "Dataset/en/Text2DT_triple_test.json"
else:
path = "Res/test_627.json" # 中文使用的
with open(path, 'r',encoding="utf-8") as f:
triplets = json.load(f)
# 根据text在triplets中找到对应的字典,读取其中的“triples”
for triplet in triplets:
if triplet['text'] == text:
return_triplet = triplet['triples']
if mode == "dev":
if language=="en":
path = "Dataset/en/Text2DT_triple_dev.json"
else:
path = "Res/dev_64_new.json"
with open(path, 'r',encoding="utf-8") as f:
triplets = json.load(f)
# 根据text在triplets中找到对应的字典,读取其中的“triples”
for triplet in triplets:
if triplet['text'] == text:
return_triplet = triplet['triples']
return return_triplet