Nltk: fungsi collocations mengembalikan kesalahan

Dibuat pada 15 Mei 2019  ·  10Komentar  ·  Sumber: nltk/nltk

Saya sedang melalui bab 1 buku dan fungsi collocations mengembalikan kesalahan. Sepertinya baris 440 dalam text.py adalah redundan, karena fungsi collocation_list telah diperkenalkan. Saya memperbaiki masalah ini dengan menulis ulang baris 440 saat ini dan baris 441 di text.py.

kode lama:
collocation_strings = [w1 + '' + w2 untuk w1, w2 di self.collocation_list (num, window_size)] *
cetak (tokenwrap (collocation_strings, separator = ";"))

kode baru:
cetak (tokenwrap (self.collocation_list (), separator = ";"))

bug goodfirstbug resolved text

Komentar yang paling membantu

Juga masih mengalami masalah dengan .collocations() , tetapi .collocation_list() berfungsi.

Semua 10 komentar

Terima kasih @martinevanschouwenburg karena telah

Ya, sepertinya daftar kolokasi diperlukan. Untuk mereplikasi bug:

$ python3
Python 3.6.4rc1 (v3.6.4rc1:3398dcb14f, Dec  5 2017, 00:58:30) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 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: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>> text4.collocations()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/text.py", line 440, in collocations
    collocation_strings = [w1 + ' ' + w2 for w1, w2 in self.collocation_list(num, window_size)]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/text.py", line 440, in <listcomp>
    collocation_strings = [w1 + ' ' + w2 for w1, w2 in self.collocation_list(num, window_size)]
ValueError: too many values to unpack (expected 2)

Saya masih melihat kesalahan ini juga saat membaca bab 1 buku ini.

* Contoh Pengantar untuk Buku NLTK *
Memuat teks1, ..., teks9 dan terkirim1, ..., terkirim9
Ketik nama teks atau kalimat untuk melihatnya.
Ketik: 'teks ()' atau 'sents ()' untuk mendaftar materi.
Teks1: Moby Dick oleh Herman Melville 1851
teks2: Sense and Sensibility oleh Jane Austen 1811
teks3: Kitab Kejadian
teks4: Corpus Alamat Pelantikan
teks5: Obrolan Corpus
text6: Monty Python dan Holy Grail
Teks7: Wall Street Journal
teks8: Korpus Pribadi
Teks9: The Man Who Was Thursday oleh G. K. Chesterton 1908
Traceback (panggilan terakhir terakhir):
File "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ ptvsd_launcher.py", baris 43, di
utama (ptvsdArgs)
File "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. Py", baris 434, di main
Lari()
File "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. Py", baris 312, di run_file
runpy.run_path (target, run_name = '__ main__')
File "c: \ users \ adam \ appdata \ local \ program \ python \ python37-32 \ Lib \ runpy.py", baris 263, di run_path
pkg_name = pkg_name, script_name = fname)
File "c: \ users \ adam \ appdata \ local \ program \ python \ python37-32 \ Lib \ runpy.py", baris 96, di _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "c: \ users \ adam \ appdata \ local \ program \ python \ python37-32 \ Lib \ runpy.py", baris 85, dalam _run_code
exec (kode, run_globals)
File "c: \ Users \ Adam \ Documents \ code \ python \ natlang \ natlang.py", baris 4, di
text4.collocations ()
File "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site-packages \ nltk \ text.py", baris 444, di collocations
w1 + "" + w2 untuk w1, w2 di self.collocation_list (num, window_size)
File "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site-packages \ nltk \ text.py", baris 444, di
w1 + "" + w2 untuk w1, w2 di self.collocation_list (num, window_size)
ValueError: terlalu banyak nilai untuk dibuka kemasannya (diharapkan 2)

@networkjr Saya dapat mengonfirmasi itu juga. Mungkin perbaikan di # 2227 belum didorong ke PyPi?

@networkjr itu sama dengan paket Anaconda

Saya sedang mengerjakan buku NLTK, saya benar-benar baru mengenal NLTK dan cukup baru mengenal Python - dan saya mendapatkan kesalahan yang sama.

$ python
Python 3.7.2 (default, Feb 14 2019, 11:13:53) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> 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: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>> text4.collocations()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/george/code/nltk/py3env/lib/python3.7/site-packages/nltk/text.py", line 444, in collocations
    w1 + " " + w2 for w1, w2 in self.collocation_list(num, window_size)
  File "/Users/george/code/nltk/py3env/lib/python3.7/site-packages/nltk/text.py", line 444, in <listcomp>
    w1 + " " + w2 for w1, w2 in self.collocation_list(num, window_size)
ValueError: too many values to unpack (expected 2)

Menurut Pipfile.lock saya, saya menggunakan NLTK 3.4.5 yang menurut saya adalah rilis terbaru.

Apakah ada perbaikan untuk masalah ini?

Ini telah diperbaiki pada # 2377, harus diperbaiki dalam rilis NLTK berikutnya segera.

Sebaliknya, jika Anda tidak bisa menunggu =)

pip install -U https://github.com/nltk/nltk/archive/develop.zip

Saya masih memiliki kesalahan yang sama setelah memperbarui cntk dengan
pip install -U https://github.com/nltk/nltk/archive/develop.zip

Versi cnkt saat ini '3.4.5'

Bagaimana cara memperbaikinya?

Terimakasih banyak.

Juga masih mengalami masalah dengan .collocations() , tetapi .collocation_list() berfungsi.

Ganti pada baris 444 di /nltk/text.py:
collocation_strings = [w1 + "" + w2 untuk w1, w2 di text.collocation_list (num, window_size)]

dengan berikut ini:
collocation_strings = [w untuk w di text.collocation_list (num, window_size)]

Sama disini. Bekerja melalui buku nltk memberikan kesalahan untuk collocations () sedangkan collocation_list () berfungsi.

Apakah halaman ini membantu?
0 / 5 - 0 peringkat