3
我试图拿出一个句子,并提取Person(PER)和Place(GPE)之间的关系。个人与城市/州之间的关系提取
句子:“约翰来自俄亥俄州,迈克尔来自佛罗里达州,丽贝卡来自田纳西州的纳什维尔。”
对于最后一个人,她有一个城市和一个国家,可以被提取作为她的地方。到目前为止,我尝试过使用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']
问题是丽贝卡。我怎样才能提取纳什维尔和田纳西都属于她的位置?甚至只有田纳西州呢?