NLTK布朗语料库:制表功能不起作用

问题描述

该代码摘录自第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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...