Nltk: Die Kollokationsfunktion gibt einen Fehler zurück

Erstellt am 15. Mai 2019  ·  10Kommentare  ·  Quelle: nltk/nltk

Ich habe Kapitel 1 des Buches durchgearbeitet und die Kollokationsfunktion gibt einen Fehler zurück. Es scheint, als wäre Zeile 440 in text.py redundant, da die Funktion collocation_list eingeführt wurde. Ich habe das Problem behoben, indem ich die aktuellen Zeilen 440 und 441 in text.py umgeschrieben habe.

alter Code:
collocation_strings = [w1 + '' + w2 für w1, w2 in self.collocation_list (num, window_size)] *
print (Tokenwrap (collocation_strings, separator = ";"))

neuer Code:
print (tokenwrap (self.collocation_list (), separator = ";"))

bug goodfirstbug resolved text

Hilfreichster Kommentar

Es gibt auch immer noch Probleme mit .collocations() , aber .collocation_list() funktioniert.

Alle 10 Kommentare

Vielen Dank an @martinevanschouwenburg für das

Ja, es sieht so aus, als würde die Kollokationsliste benötigt. So replizieren Sie den Fehler:

$ 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)

Ich sehe diesen Fehler auch immer noch, wenn ich Kapitel 1 des Buches durchlaufe.

* Einführungsbeispiele für das NLTK-Buch *
Laden von text1, ..., text9 und sent1, ..., sent9
Geben Sie den Namen des Textes oder Satzes ein, um ihn anzuzeigen.
Geben Sie 'Texts ()' oder 'Sents ()' ein, um die Materialien aufzulisten.
text1: Moby Dick von Herman Melville 1851
text2: Sinn und Sinnlichkeit von Jane Austen 1811
text3: Das Buch Genesis
text4: Antrittsrede Corpus
text5: Chat Corpus
text6: Monty Python und der Heilige Gral
text7: Wall Street Journal
text8: Personals Corpus
text9: Der Mann, der Donnerstag war von G. K. Chesterton 1908
Traceback (letzter Anruf zuletzt):
Datei "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ ptvsd_launcher.py", Zeile 43, in
main (ptvsdArgs)
Datei "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. Py", Zeile 434, in main
Lauf()
Datei "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. Py", Zeile 312, in run_file
runpy.run_path (Ziel, run_name = '__ main__')
Datei "c: \ users \ adam \ appdata \ local \ programme \ python \ python37-32 \ Lib \ runpy.py", Zeile 263, in run_path
pkg_name = pkg_name, script_name = fname)
Datei "c: \ users \ adam \ appdata \ local \ programme \ python \ python37-32 \ Lib \ runpy.py", Zeile 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
Datei "c: \ users \ adam \ appdata \ local \ programme \ python \ python37-32 \ Lib \ runpy.py", Zeile 85, in _run_code
exec (Code, run_globals)
Datei "c: \ Benutzer \ Adam \ Dokumente \ Code \ Python \ natlang \ natlang.py", Zeile 4, in
text4.collocations ()
Datei "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site-packages \ nltk \ text.py", Zeile 444, in Kollokationen
w1 + "" + w2 für w1, w2 in self.collocation_list (num, window_size)
Datei "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site-packages \ nltk \ text.py", Zeile 444, in
w1 + "" + w2 für w1, w2 in self.collocation_list (num, window_size)
ValueError: Zu viele Werte zum Entpacken (erwartet 2)

@networkjr Das kann ich auch bestätigen. Vielleicht wurde das Update in # 2227 noch nicht auf PyPi übertragen?

@networkjr es ist das gleiche mit dem Anaconda-Paket

Ich arbeite das NLTK-Buch durch, bin völlig neu in NLTK und ziemlich neu in Python - und ich erhalte den gleichen Fehler.

$ 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)

Laut meinem Pipfile.lock ich NLTK 3.4.5, das meiner Meinung nach die neueste Version ist.

Gibt es eine Lösung für dieses Problem?

Dies wurde auf # 2377 behoben und sollte in der nächsten NLTK-Version bald behoben werden.

Ansonsten, wenn Sie nicht warten können =)

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

Ich habe immer noch den gleichen Fehler nach dem Update von cntk mit
pip install -U https://github.com/nltk/nltk/archive/develop.zip

Aktuelle cnkt-Version '3.4.5'

Wie kann ich es reparieren?

Danke vielmals.

Es gibt auch immer noch Probleme mit .collocations() , aber .collocation_list() funktioniert.

In Zeile 444 in /nltk/text.py ersetzen:
collocation_strings = [w1 + "" + w2 für w1, w2 in text.collocation_list (num, window_size)]

mit den folgenden:
collocation_strings = [w für w in text.collocation_list (num, window_size)]

Hier gilt das gleiche. Das Durcharbeiten des nltk-Buches führt zu Fehlern bei collocations (), während collocation_list () funktioniert.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen