首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何计算python库中古腾堡语料库中的单词覆盖率?

如何计算python库中古腾堡语料库中的单词覆盖率?
EN

Stack Overflow用户
提问于 2019-11-29 05:32:35
回答 1查看 2.4K关注 0票数 0

计算与文本语料库gutenberg相关联的所有文件ID的单词覆盖率。它的编写代码是什么,

代码语言:javascript
复制
import nltk
from nltk.corpus import gutenburg
from decimal import Decimal

for fileid in gutenburg.fileids():
  n_chars = len(gutenburg.raw(fileid))
  n_words = len(gutenburg.words(fileids))
  print(round(Decimal(n_chars/n_words), 7), fileids)
EN

回答 1

Stack Overflow用户

发布于 2020-02-09 11:29:55

代码语言:javascript
复制
import nltk

from nltk.corpus import gutenberg

for fileid in gutenberg.fileids():
    total_unique_words = len(set(gutenberg.words(fileid)))
    total_words = len(gutenberg.words(fileid))
    print(total_words/total_unique_words,fileid)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59099224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档