小编Dav*_*les的帖子

nltk模块中的类似方法在不同的机器上产生不同的结果.为什么?

我已经教过一些用Python进行文本挖掘的入门课程,并且该课程尝试了与提供的练习文本类似的方法.有些学生对text1.similar()的结果与其他学生不同.

所有版本等都是一样的.

有谁知道为什么会出现这些差异?谢谢.

在命令行使用的代码.

python
>>> import nltk
>>> nltk.download() #here you use the pop-up window to download texts
>>> from nltk.book import *
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: …
Run Code Online (Sandbox Code Playgroud)

python nlp similarity corpus nltk

15
推荐指数
2
解决办法
1846
查看次数

仅在OTHER字段中出现一次的组值

我有一个罗马硬币的集合,我试图ggplot在R中使用它.

数据中有25种不同的面额,但我想将只有一次出现的所有面额合并到一个"OTHER"字段中,以便图表更易于阅读.

  Medium Method Denom            Date                  Era
1 Silver Struck Denarius         112 B.C.E.:111 B.C.E. Period V – c. 119-91 B.C.E.
2 Bronze   Cast ????? ????????   181 B.C.E.:174 B.C.E. Period III – c. 187-155 B.C.E.
3 Bronze Struck Litra:Half-litra            269 B.C.E. Period I – 269 - c. 222 B.C.E.
4 Bronze Struck Litra:Half-litra            269 B.C.E. Period I – 269 - c. 222 B.C.E.
5 Silver Struck Didrachm         275 B.C.E.:270 B.C.E. Period I – 269 - c. 222 B.C.E.
6 …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

6
推荐指数
1
解决办法
59
查看次数

使用 nltk 查找特定的索引

我使用下面的代码从 nltk 获取索引,然后显示每个索引的索引。我得到的结果如下所示。到目前为止,一切都很好。

如何仅查找一个特定索引的索引?在这个小例子中,将索引与索引相匹配是很容易的,但如果我有 300 个索引,我想找到其中一个的索引。

.index不将列表中的多个项目作为参数。

有人可以指出我应该使用的命令/结构来获取与索引一起显示的索引吗?我在下面附加了一个更有用的结果的示例,该结果超出 nltk 以获得单独的索引列表。我想将这些合并为一个结果,但是如何实现呢?

import nltk 
nltk.download('punkt') 
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.text import Text

moby = open('mobydick.txt', 'r')

moby_read = moby.read() 
moby_text = nltk.Text(nltk.word_tokenize(moby_read))

moby_text.concordance("monstrous")

moby_indices  = [index for (index, item) in enumerate(moby_text) if item == "monstrous"]

print(moby_indices)
Run Code Online (Sandbox Code Playgroud)
Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . ... This came towards us , 
N OF THE PSALMS . `` Touching that monstrous bulk …
Run Code Online (Sandbox Code Playgroud)

python nltk

5
推荐指数
1
解决办法
305
查看次数

标签 统计

nltk ×2

python ×2

corpus ×1

ggplot2 ×1

nlp ×1

r ×1

similarity ×1