首页 > 解决方案 > nltk.concordance 最多提供 25 行,无论我如何更改该参数

问题描述

所以我开始通过 nltk book 学习 NLP,似乎我立即遇到了一个以前没有人提到过的问题。

让我们从 nltk.book 导入数据,就像书上说的那样:

from nltk.book import *

现在我想继续书中的例子:

text1.concordance("monstrous")

给我:

Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . ... This came towards us ,
ON OF THE PSALMS . " Touching that monstrous bulk of the whale or ork we have r
ll over with a heathenish array of monstrous clubs and spears . Some were thick
d as you gazed , and wondered what monstrous cannibal and savage could ever hav
that has survived the flood ; most monstrous and most mountainous ! That Himmal
they might scout at Moby Dick as a monstrous fable , or still worse and more de
th of Radney .'" CHAPTER 55 Of the monstrous Pictures of Whales . I shall ere l
ing Scenes . In connexion with the monstrous pictures of whales , I am strongly
ere to enter upon those still more monstrous stories of them which are to be fo
ght have been rummaged out of this monstrous cabinet there is no telling . But
of Whale - Bones ; for Whales of a monstrous size are oftentimes cast up dead u

到目前为止,一切都很好。现在我想知道《白whale鲸记》中单词的一致性。

text1.concordance("whale")
Displaying 25 of 25 matches:
s , and to teach them by what name a whale - fish is to be called in our tongue
t which is not true ." -- HACKLUYT " WHALE . ... Sw . and Dan . HVAL . This ani
ulted ." -- WEBSTER ' S DICTIONARY " WHALE . ... It is more immediately from th
ISH . WAL , DUTCH . HWAL , SWEDISH . WHALE , ICELANDIC . WHALE , ENGLISH . BALE
HWAL , SWEDISH . WHALE , ICELANDIC . WHALE , ENGLISH . BALEINE , FRENCH . BALLE
least , take the higgledy - piggledy whale statements , however authentic , in
 dreadful gulf of this monster ' s ( whale ' s ) mouth , are immediately lost a
 patient Job ." -- RABELAIS . " This whale ' s liver was two cartloads ." -- ST
 Touching that monstrous bulk of the whale or ork we have received nothing cert
 of oil will be extracted out of one whale ." -- IBID . " HISTORY OF LIFE AND D
ise ." -- KING HENRY . " Very like a whale ." -- HAMLET . " Which to secure , n
restless paine , Like as the wounded whale to shore flies thro ' the maine ." -
. OF SPERMA CETI AND THE SPERMA CETI WHALE . VIDE HIS V . E . " Like Spencer '
t had been a sprat in the mouth of a whale ." -- PILGRIM ' S PROGRESS . " That
EN ' S ANNUS MIRABILIS . " While the whale is floating at the stern of the ship
e ship called The Jonas - in - the - Whale . ... Some say the whale can ' t ope
 in - the - Whale . ... Some say the whale can ' t open his mouth , but that is
 masts to see whether they can see a whale , for the first discoverer has a duc
 for his pains . ... I was told of a whale taken near Shetland , that had above
oneers told me that he caught once a whale in Spitzbergen that was white all ov
2 , one eighty feet in length of the whale - bone kind came in , which ( as I w
n master and kill this Sperma - ceti whale , for I could never hear of any of t
 . 1729 . "... and the breath of the whale is frequendy attended with such an i
ed with hoops and armed with ribs of whale ." -- RAPE OF THE LOCK . " If we com
contemptible in the comparison . The whale is doubtless the largest animal in c

什么,不可能是对的。“鲸鱼”这个词不可能在《白鲸记》中只出现 25 次。“它”这个词怎么说?

text1.concordance("it")
Displaying 25 of 25 matches:

好的,让我们增加显示的行数:

text1.concordance("it", lines=100)
Displaying 25 of 25 matches:

怎么减呢?

text1.concordance("it", lines=10)
Displaying 10 of 25 matches:

它要我相信“它”这个词只出现了 25 次?虽然这绝对是一个故障,但争论会变得更糟width(它根本没有考虑到它)。

我使用 nltk 的系统:

赢10 64位;

Python 3.6.5 32 位

发生了什么事,我该如何解决?

标签: pythonnlpnltk

解决方案


这似乎是 NLTK 3.3 的一个错误。

源代码中,行

concordance_list = self.find_concordance(word, width=80, lines=25)

强制结果为 <= 25 行,宽度 <= 80 并且应该是

concordance_list = self.find_concordance(word, width=width, lines=lines)

最简单的解决方法是将您的 NLTK 安装降级到 3.2 版(其中concordance具有预期的行为)。


推荐阅读