khulnasoft
commited on
Commit
•
1beb6dd
1
Parent(s):
10ec365
Create toBenchIEformat.py
Browse files
evaluation_data/benchIE/toBenchIEformat.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sent2id = dict()
|
2 |
+
with open('sample300_en.txt', 'r') as f:
|
3 |
+
i = 1
|
4 |
+
for line in f.readlines():
|
5 |
+
sent2id[line.replace('\n', '')] = i
|
6 |
+
i += 1
|
7 |
+
|
8 |
+
with open('output_extractions.txt', 'r') as fin, open('compactIE_1.2_new.txt', 'w') as fout:
|
9 |
+
for line in fin.readlines():
|
10 |
+
sentence, extraction, score = line.split('\t')
|
11 |
+
sentId = sent2id[sentence]
|
12 |
+
try:
|
13 |
+
arg1 = extraction[extraction.index('<arg1>') + 6:extraction.index('</arg1>')]
|
14 |
+
arg1 = arg1.strip()
|
15 |
+
except:
|
16 |
+
print("subject error!", extraction)
|
17 |
+
arg1 = ""
|
18 |
+
try:
|
19 |
+
rel = extraction[extraction.index('<rel>') + 5:extraction.index('</rel>')]
|
20 |
+
rel = rel.strip()
|
21 |
+
except:
|
22 |
+
print("predicate error!", extraction)
|
23 |
+
rel = ""
|
24 |
+
try:
|
25 |
+
arg2 = extraction[extraction.index('<arg2>') + 6:extraction.index('</arg2>')]
|
26 |
+
arg2 = arg2.strip()
|
27 |
+
if arg2 == "":
|
28 |
+
continue
|
29 |
+
except:
|
30 |
+
print("object error!", extraction)
|
31 |
+
arg2 = ""
|
32 |
+
print("{}\t{}\t{}\t{}".format(sentId, arg1, rel, arg2), file=fout)
|