我将使用python中的stanfordner来对齐两个不同的句子,它们包含相同的NER类别('PERSON','LOCATION','ORGANIZATION')。你知道吗
sentence1 = John is reading a booklet in London Library
sentence2 = Michael reads a brochure in England Library
我想要的结果是:
result= [[[u'John', u'Person'],[u'Michael',u'PERSON']] , [[u'London',u'LOCATION],['u'England',u'LOCATION']]]
我试过我的密码
def alignNER(self, sent1, sent2):
java.path = 'C:/program files'/java/jre/bin/java.exe'
os.environ ['JAVAHOME'] = java.path
st = StanfordNERTagger('usr/english.all.3class.distsim.crf.ser','usr/stanford-ner.jar')
result = []
for i in xrange(len(sent1)):
if sent1[i]:
word = sent1[i]
temp = st.tag(word.split())
for token, tag in temp:
if tag in ['PERSON','LOCATION','ORGANIZATION']:
result.append([temp,i])
return result
for j in xrange(len(sent2)):
if sent2[j]:
word = sent2[j]
temp = st.tag(word.split())
for token, tag in temp:
if tag in ['PERSON','LOCATION','ORGANIZATION']:
result.append([temp,j])
return result
当我叫它
checkNER = alignNER(sent1, sent2)
print checkNER
结果只显示了带有检测类别位置索引的句子1:
[[[u'John', u'Person'],0],[[u'London',u'LOCATION],6]]
有人能帮忙吗?谢谢
目前没有回答
相关问题 更多 >
编程相关推荐