【发布时间】:2017-09-28 23:46:40
【问题描述】:
我正在尝试从莎士比亚的 NLTK 语料库中导入句子——关注this 帮助站点——但我无法访问这些句子(为了训练 word2vec 模型):
from nltk.corpus import shakespeare #XMLCorpusreader
shakespeare.fileids()
['a_and_c.xml', 'dream.xml', 'hamlet.xml', 'j_caesar.xml', ...]
play = shakespeare.xml('dream.xml') #ElementTree object
print(play)
<Element 'PLAY' at ...>
for i in range(9):
print('%s: %s' % (play[i].tag, play[i].text))
返回以下内容:
TITLE: A Midsummer Night's Dream
PERSONAE:
SCNDESCR: SCENE Athens, and a wood near it.
PLAYSUBT: A MIDSUMMER NIGHT'S DREAM
ACT: None
ACT: None
ACT: None
ACT: None
ACT: None
为什么所有的行为都没有?
这里定义的所有方法 (http://www.nltk.org/howto/corpus.html#data-access-methods) (.sents(), tagged_sents(), chunked_sents(), parsed_sents()) 在应用于莎士比亚 XMLCorpusReader 时似乎都不起作用
我想了解:
1/ 如何获取句子
2/ 如何知道如何在 ElementTree 对象中查找它们
【问题讨论】: