相关疑难解决方法(0)

使用NLTK提取关系

这是我的问题后续行动.我正在使用nltk解析人员,组织及其关系.通过这个例子,我能够创建大量的人员和组织; 但是,我在nltk.sem.extract_rel命令中收到错误:

AttributeError: 'Tree' object has no attribute 'text'
Run Code Online (Sandbox Code Playgroud)

这是完整的代码:

import nltk
import re
#billgatesbio from http://www.reuters.com/finance/stocks/officerProfile?symbol=MSFT.O&officerId=28066
with open('billgatesbio.txt', 'r') as f:
    sample = f.read()

sentences = nltk.sent_tokenize(sample)
tokenized_sentences = [nltk.word_tokenize(sentence) for sentence in sentences]
tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences]
chunked_sentences = nltk.batch_ne_chunk(tagged_sentences)

# tried plain ne_chunk instead of batch_ne_chunk as given in the book
#chunked_sentences = [nltk.ne_chunk(sentence) for sentence in tagged_sentences]

# pattern to find <person> served as <title> in <org> …
Run Code Online (Sandbox Code Playgroud)

python nlp nltk

9
推荐指数
2
解决办法
8733
查看次数

标签 统计

nlp ×1

nltk ×1

python ×1