问题描述
该代码摘录自第119页的《使用Python进行自然语言处理》。布朗语料库不同部分的模态频率。我的问题是,它无法像书中所述那样进行制表。基本上我不知道为什么会这样。我的Python版本是3.7.9 64位。所有扩展都很顺利。
布朗语料库不同部分的语气频率
def tabulate(cfdist,words,categories):
print('%-16s' % 'Category')
for word in words: # column headings
print('%6s' % word,)
print()
for category in categories:
print('%-16s' % category,) # row headings
for word in words: # for each word
print('%6d' % cfdist[category][word]) # print table cell
print() # end the row
cfd = nltk.ConditionalFreqDist(
(genre,word)
for genre in brown.categories()
for word in brown.words(categories=genre))
genres = ['news','religion','hobbies','science_fiction','romance','humor']
modals = ['can','could','may','might','must','will']
tabulate(cfd,modals,genres)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)