-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_annt.py
28 lines (26 loc) · 1.03 KB
/
read_annt.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
# -*- coding: utf-8 -*-
"""
Created on Wed May 24 13:14:44 2017
@author: lenovo laptop
"""
import re
def read_annt(filepath):
print(filepath)
dest = re.sub("\.txt" , "", filepath)
with open(filepath, "r", encoding="utf8") as fs, open(dest+".reference.txt", 'a', encoding="utf8") as fd:
count = 0
for line in fs:
if count % 3 == 0:
line.strip("\n")
annt_sent = line.split('|')
sid = annt_sent[7].strip()
sid = sid[sid.find("[")+1:sid.find("]")] # extract ref id
sid = sid.replace("\'", "") # remove "'"
annt_sent = annt_sent[8].strip()
annt_sent = " ".join(re.findall(">(.*?)<", annt_sent))
discourse = annt_sent[9].strip()
discourse = discourse.replace(" ".join(re.findall("(.*?:)", discourse)), "")
fd.write(annt_sent+"\t"+discourse+"\n")
count += 1
fs.close()
fd.close()