【发布时间】:2017-03-13 11:05:48
【问题描述】:
我正在使用 NLTK 来提取 PERSON 和 ORGANIZATION 之间的关系。
另外,我想提取 ORGANIZATION 和 LOCATION 之间的关系。 NLTK 版本是 3.2.1。
我使用了词性标记和命名实体识别 (NER)。还为 NER 结果绘制解析树。
但是我无法从那句话中提取出提到的关系。
代码如下:
import nltk, re
from nltk import word_tokenize
sentence = "Mark works at JPMC in London every day"
pos_tags = nltk.pos_tag(word_tokenize(sentence)) # POS tagging of the sentence
ne = nltk.ne_chunk(pos_tags) # Named Entity Recognition
ne.draw() # Draw the Parse Tree
IN = re.compile(r'.*\bin\b(?!\b.+ing)')
for rel1 in nltk.sem.extract_rels('PER', 'ORG', pos_tags, pattern = IN):
print(nltk.sem.rtuple(rel1))
for rel2 in nltk.sem.extract_rels('ORG', 'LOC', pos_tags, pattern = IN):
print(nltk.sem.rtuple(rel2))
如何提取'Person - Organization'关系和'Organization - Location'关系?
【问题讨论】: