-
Notifications
You must be signed in to change notification settings - Fork 0
/
making_entity_list.py
25 lines (22 loc) · 1.54 KB
/
making_entity_list.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
# -*- coding: utf-8 -*-
import codecs
from lxml import etree
import sys
names={'types':"http:///gr/ilsp/types.ecore",'xmi':"http://www.omg.org/XMI"}
n={'cas':"http:///uima/cas.ecore",'xmi':"http://www.omg.org/XMI"}
entities=codecs.open('makedonia_list.txt','w',encoding='utf-8',errors='ignore')
for i in range(1696):
print(i)
file_pos= sys.argv[1]+'/archive/split'+str(i)+'_makedonia.txt' # dataset with part of speech tags
file_ner= sys.argv[2]+'/archive/split'+str(i)+'_makedonia.txt.tagged' # dataset with named entities
article_pos=etree.parse(file_pos)
article_ner=etree.parse(file_ner)
with codecs.open(file_pos,'r',encoding='utf-8',errors='ignore') as file_pos:
with codecs.open(file_ner,'r',encoding='utf-8',errors='ignore') as file_ner:
sofas=article_pos.xpath("cas:Sofa/@sofaString",namespaces=n)[0] #news text
begin_tokens=article_ner.xpath("//Annotation[@Type='LOCATION' or @Type='ORGANIZATION' or @Type='FACILITY'or @Type='PERSON']/@StartNode",namespaces=names)
end_tokens=article_ner.xpath("//Annotation[@Type='LOCATION' or @Type='ORGANIZATION' or @Type='FACILITY'or @Type='PERSON']/@EndNode",namespaces=names)
entity_tokens=article_ner.xpath("//Annotation[@Type='LOCATION' or @Type='ORGANIZATION' or @Type='FACILITY'or @Type='PERSON']/@Type",namespaces=names)
for index in range(len(begin_tokens)):
entities.write(sofas[int(begin_tokens[index]):int(end_tokens[index])]+' '+entity_tokens[index])
entities.write('\n')