Nltk 条件频率分布问题
我有以下代码:Nltk 条件频率分布问题,nltk,Nltk,我有以下代码: corpus= CategorizedPlaintextCorpusReader(loc,'(?!\.svn).*\.txt', cat_pattern=r'(Shakespeare|Milton)/.*') cfd=nltk.ConditionalFreqDist ((genre,word) for genre in corpus.categories() for w
corpus= CategorizedPlaintextCorpusReader(loc,'(?!\.svn).*\.txt', cat_pattern=r'(Shakespeare|Milton)/.*')
cfd=nltk.ConditionalFreqDist ((genre,word)
for genre in corpus.categories()
for word in corpus.words(categories = genre))
genres=['Shakespeare','Milton']
pronouns=['I','you','he','she', 'it','we','they']
cfd.tabulate (conditions=genres,samples=pronouns)
现在,出于某种强烈的perculiar原因,我得到了以下错误:
“category=re.match(自我模式,文件id).group(1)
AttributeError:“非类型”对象没有属性“组”
有人知道这是怎么回事吗
category = re.match(self._pattern, file_id).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
此错误消息告诉您,re.match
返回了None
。换句话说,没有对手。当您查找组(1)时,它会抛出错误
在前进方面,您有几个选择:
if
检查是否存在匹配项
,然后查找其组re.match
返回了None
。换句话说,没有对手。当您查找组(1)时,它会抛出错误
在前进方面,您有几个选择:
if
检查是否存在匹配项
,然后查找其组