I have 2 different lists which contains names and location. Need to identify position of both name and location in text.
Input
Name:['Mughal'] Location: ['Panipat','Agra']
text=['The battle of Panipat laid the foundation of the Mughal dynasty in Agra.']
Output:
Start position:15;end position:21;Word:Panipat;type:Location; Start position:50;end position:55;Word:Mughal;type:Name
code:
for t in (text):
for n in name_:
while index_ < len(t):
index_ = t.find(n,index_)
if index_ == -1:
break
else:
kwmatch.append((index_, index_+len(n),"Name"))
index_ += len(rect)
index_ = 0
a = (text,{'entities':kwmatch})
doctuple.append(a)
kwmatch = []
a = None