我编写了这个小脚本来查找我的语料库中 10 个最常用单词的上下文。但它不起作用,我不知道我做错了什么。 tien_frequentste(mijn_corpus) 定义独立工作。
tienfrequentste = tien_frequentste(mijncorpus)
def context (corpus, most_freq):
for category in corpus.categories():
print "Context voor" , category, ":"
for word in most_freq:
print nltk.Text(corpus.words(categories=category)).concordance(word)
更新:
我在回溯
for context(corpus, most_freq)
、
for category in corpus.categories()
、
forself.init()
和in_init
. 和一个AttributeError:'NoneType' object has no attribute 'group'
。
不知道这些错误是什么意思..
Traceback (most recent call last):
File "/Users/...document.py", line 92, in <module> context (mijn_corpus, tienfrequentste)
File "/Users/...document.py", line 87, in context for category in corpus.categories(): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk.corpus.reader.api.py, line 317, in categories self.init().
File "/Users/...document.py", line 87, in context for category in corpus.categories(): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk.corpus.reader.api.py, line 289, in_init category = re.match(self._pattern, file id).group(1)
attributeError: 'Nonetype' object has no attribute "group"