微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – nltk.concordance最多提供25行,无论我如何更改该参数

所以我开始通过nltk书学习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

到现在为止还挺好.现在我想知道Moby Dick中鲸鱼的一致性.

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次出现.单词“it”怎么样?

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次出现“它”这个词?
虽然这绝对是一个故障,但宽度参数会变得更糟(它根本不考虑它).

系统我使用nltk:

赢10 64位;

Python 3.6.5 32位

发生了什么,我该如何解决这个问题?

解决方法:

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

source code,行

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(其中一致性具有预期的行为).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐