nltk.concordance дает максимум 25 строк, независимо от того, как я изменяю этот аргумент - PullRequest
0 голосов
/ 21 мая 2018

Итак, я начал изучать НЛП через книгу nltk, и, похоже, я сразу столкнулся с проблемой, о которой никто не упоминал ранее.

Давайте импортируем данные из 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 с:

Win 10 64 бит;

Python 3.6.5 32 бит

Что происходит и как я могу это исправить?

1 Ответ

0 голосов
/ 21 мая 2018

Кажется, это ошибка в NLTK 3.3.

В исходном коде строка

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

заставляет результаты быть <= 25 строкс шириной <= 80 и должно быть </p>

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

Самый простой обходной путь - это понизить версию вашей установки NLTK до версии 3.2 (в которой concordance имеет ожидаемое поведение).

...