- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试打印 FreqDist 对象时,我在打印结束时得到“...”?我尝试在 Internet 上查找它,但没有找到。
请让我知道哪里出错了。
代码:
for word in nltk.word_tokenize(lin):
fdist.inc(word)
print fdist
最佳答案
当您使用 fdist
时,它会返回一个键值对列表。您必须使用循环将它们打印出来。像下面这样的东西应该可以工作:
import nltk
from nltk.tokenize import word_tokenize
lin = "A frequency distribution for the outcomes of an experiment. A frequency distribution records the number of times each outcome of an experiment has occurred. For example, a frequency distribution could be used to record the frequency of each word type in a document. Formally, a frequency distribution can be defined as a function mapping from each sample to the number of times that sample occurred as an outcome."
fdist = nltk.FreqDist()
for word in word_tokenize(lin):
fdist.inc(word)
for f in fdist:
print f, fdist[f]
结果是:
frequency 5
of 5
a 4
distribution 4
the 4
an 3
each 3
, 2
A 2
as 2
be 2
number 2
outcome 2
sample 2
times 2
to 2
. 1
For 1
Formally 1
can 1
could 1
defined 1
document. 1
example 1
experiment 1
experiment. 1
for 1
from 1
function 1
has 1
in 1
mapping 1
occurred 1
occurred. 1
outcomes 1
record 1
records 1
that 1
type 1
used 1
word 1
[Finished in 1.5s]
如果这有帮助,请告诉我们。
编辑:
另一种方法:
import nltk
from nltk.tokenize import word_tokenize
lin = "A frequency distribution for the outcomes of an experiment. A frequency distribution records the number of times each outcome of an experiment has occurred. For example, a frequency distribution could be used to record the frequency of each word type in a document. Formally, a frequency distribution can be defined as a function mapping from each sample to the number of times that sample occurred as an outcome."
tokens = word_tokenize(lin)
fdist = nltk.FreqDist(tokens)
for f in fdist:
print f, fdist[f]
输出相同。
关于python - FreqDist Python ... 最后一期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22415915/
我的目标是生成一个单词词典,在过去 3 年中具有不同的 FreqDist 键,但具有最新的出现时间。 我已经生成了一个字典,其中的键指的是日期,而值对应于当月提取的 FreqDist。 {'20151
我正在尝试分析应用评论中的一些数据。 我想使用 nltk 的 FreqDist 来查看文件中最常出现的短语。它可以是单个标记或关键短语。我不想对数据进行标记,因为这只会给我最常见的标记。但现在,Fre
当我尝试打印 FreqDist 对象时,我在打印结束时得到“...”?我尝试在 Internet 上查找它,但没有找到。 请让我知道哪里出错了。 代码: for word in nltk.word_t
在 NLTK 中,您可以轻松地计算文本中单词的计数,例如,通过执行以下操作 from nltk.probability import FreqDist fd = FreqDist([word for
我正在使用 NLTK 和 FreqDist().plot() 。但出于好奇,有没有办法将线图转换为直方图?以及如何在这两种情况下放置标签? 我在文档中进行了搜索,但遗憾的是它没有详细说明。 提前致谢
我尝试了不同的方法来保存我的情节,但我尝试过的每件事都出现了空白图像,而且我目前还没有没有想法。有其他可以解决此问题的建议吗?代码示例如下。 word_frequency = nltk.FreqDis
我正在尝试将单词列表(标记化字符串)分解为每个可能的子字符串。然后我想在每个子字符串上运行 FreqDist,以找到最常见的子字符串。第一部分工作正常。但是,当我运行 FreqDist 时,出现错误:
我正在尝试使用 Python 获取一组文档的频率分布。我的代码由于某种原因无法正常工作并产生此错误: Traceback (most recent call last): File "C:\Doc
我是 Python 的新手,我正在尝试自学语言处理。 python 中的 NLTK 有一个名为 FreqDist 的函数,它给出了文本中单词的频率,但由于某种原因它不能正常工作。 这是教程让我写的:
Python 包 nltk 具有 FreqDist函数为您提供文本中单词的频率。我正在尝试将我的文本作为参数传递,但结果是以下形式: [' ', 'e', 'a', 'o', 'n', 'i', 't
我有使用 NLTK 得到的频率分布: [(('ingeniería', 'informática'), 30), (('tecnologías', 'información'), 26), (('si
我有一个包含两列 id 和 text 的数据框 我想添加一个新列,其中包含每行文本的字数。 我创建了一个 userdefinedFunction,其中我从 nltk 实现了 word_tokenize
我是 Python 和 NLTK 的初学者。我正在尝试运行教程中的以下代码: from nltk.corpus import gutenberg from nltk import FreqDist f
我有一个小程序,它使用 NLTK 来获取相当大的数据集的频率分布。问题是,几百万字后,我开始耗尽系统上的所有 RAM。以下是我认为相关的代码行: freq_distribution = nltk.Fr
我正在学习 NLTK 和我的 mac 工作正常,除非我在 FreqDist() 上遇到问题。 (我看到另一个关于 FreqDist() 的问题,但他收到了不同的错误消息。TypeError: unha
我正在玩弄 NLTK 和模块 freqDist import nltk from nltk.corpus import gutenberg print(gutenberg.fileids()) fro
我想计算文本语料库中单词的词频。我一直在使用 NLTK 的 word_tokenize 后跟 probability.FreqDist 一段时间来完成这项工作。 word_tokenize 返回一个列
nltk.FreqDist('abc') > nltk.FreqDist('abd') 返回 True 和 nltk.FreqDist('abd') >> abc = nltk.FreqDist('a
我是一名优秀的程序员,十分优秀!