【发布时间】:2017-12-26 22:39:38
【问题描述】:
我正在尝试提取一个句子并提取 Person(PER) 和 Place(GPE) 之间的关系。
句子:“John 来自俄亥俄州,Michael 来自佛罗里达州,Rebecca 来自田纳西州的纳什维尔。”
对于最后一个人,她有一个城市和一个州,可以作为她的位置。到目前为止,我已经尝试使用 nltk 来执行此操作,但只能提取她的城市而不是她的州。
我尝试过的:
import re
from nltk import ne_chunk, pos_tag, word_tokenize
from nltk.sem.relextract import extract_rels, rtuple
sentence = "John is from Ohio, Michael is from Florida and Rebecca is from Nashville which is in Tennessee."
chunked = ne_chunk(pos_tag(word_tokenize(sentence)))
ISFROM = re.compile(r'.*\bfrom\b.*')
rels = extract_rels('PER', 'GPE', chunked, corpus = 'ace', pattern = ISFROM)
for rel in rels:
print(rtuple(rel))
我的输出是:
[PER: 'John/NNP'] 'is/VBZ from/IN' [GPE: 'Ohio/NNP']
[PER: 'Michael/NNP'] 'is/VBZ from/IN' [GPE: 'Florida/NNP']
[PER: 'Rebecca/NNP'] 'is/VBZ from/IN' [GPE: 'Nashville/NNP']
问题是丽贝卡。我怎样才能提取出纳什维尔和田纳西州都是她所在位置的一部分?或者甚至只是田纳西州?
【问题讨论】:
标签: nlp nltk named-entity-recognition information-extraction spacy