-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathNER.py
48 lines (34 loc) · 980 Bytes
/
NER.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
29
30
31
32
33
34
35
36
from tokenizer import wordTokenizer
from preprocessing import ban_processing
bp=ban_processing()
tokenizer=wordTokenizer()
exData={}
pos_dict={}
class UncustomizeNER:
def __init__(self):
for word in open('bn_nlp/dataset/exdata.txt', 'r'):
word=word.replace('\n','')
tokens=tokenizer.basic_tokenizer(word)
if len(tokens)>=2:
val=tokens[-1]
ind=len(word)-len(val)
tmp=word[0:ind-1]
exData[tmp] = val
def NER(self,text):
i=0
tokens=tokenizer.basic_tokenizer(text)
l=len(tokens)
ans={}
while i<l:
j=min(i+10,l-1);
while j>i:
st=' '.join(tokens[i:j])
print(st)
if exData.get(st):
ans[st]=exData[st]
break
j-=1
if j==i:
j+=1
i=j
return ans