كنت أتصفح الفصل الأول من الكتاب وتعيد وظيفة التجميع خطأ. يبدو أن السطر 440 في text.py زائد عن الحاجة ، منذ أن تم تقديم وظيفة collocation_list. أصلحت المشكلة عن طريق إعادة كتابة السطر الحالي 440 والسطر 441 في text.py.
الكود القديم:
collocation_strings = [w1 + '+ w2 for w1، w2 in self.collocation_list (num، window_size)] *
طباعة (tokenwrap (collocation_strings ، الفاصل = "؛"))
رمز جديد:
طباعة (tokenwrap (self.collocation_list () ، فاصل = "؛"))
شكرا martinevanschouwenburg لرفع الخطأ!
نعم ، يبدو أن هناك حاجة إلى قائمة التجميع. لتكرار الخطأ:
$ 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)
ما زلت أرى هذا الخطأ أيضًا عند الانتقال إلى الفصل الأول من الكتاب.
* أمثلة تمهيدية عن كتاب NLTK *
جارٍ تحميل النص 1 و ... و text9 و sent1 ، ... ، sent9
اكتب اسم النص أو الجملة لعرضها.
اكتب: "text ()" أو "sents ()" لسرد المواد.
النص 1: موبي ديك بقلم هيرمان ميلفيل 1851
النص 2: العقل والعاطفة لجين أوستن 1811
النص 3: كتاب التكوين
النص 4: مجموعة العنوان الافتتاحي
النص 5: مجموعة الدردشة
النص 6: مونتي بايثون والكأس المقدسة
النص 7: وول ستريت جورنال
النص 8: مجموعة العناصر الشخصية
النص 9: الرجل الذي كان الخميس بقلم ج. ك . تشيسترتون 1908
Traceback (أحدث مكالمة أخيرة):
ملف "c: \ Users \ Adam.vscode \ extension \ ms-python.python-2019.6.24221 \ pythonFiles \ ptvsd_launcher.py" ، السطر 43 ، في
رئيسي (ptvsdArgs)
ملف "c: \ Users \ Adam.vscode \ extension \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. py" ، السطر 434 ، بشكل رئيسي
يركض()
ملف "c: \ Users \ Adam.vscode \ extension \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. py" ، السطر 312 ، في run_file
runpy.run_path (الهدف ، اسم المدى = '__ main__')
ملف "c: \ users \ adam \ appdata \ local \ software \ python \ python37-32 \ Lib \ runpy.py" ، السطر 263 ، في run_path
pkg_name = pkg_name ، script_name = fname)
ملف "c: \ users \ adam \ appdata \ local \ software \ python \ python37-32 \ Lib \ runpy.py" ، السطر 96 ، في _run_module_code
mod_name ، mod_spec ، pkg_name ، script_name)
ملف "c: \ users \ adam \ appdata \ local \ software \ python \ python37-32 \ Lib \ runpy.py" ، السطر 85 ، في _run_code
exec (كود ، run_globals)
ملف "c: \ Users \ Adam \ Documents \ code \ python \ natlang \ natlang.py" ، السطر 4 ، في
text4.collocations ()
ملف "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site -pack \ nltk \ text.py" ، السطر 444 ، في التجميعات
w1 + "" + w2 for w1، w2 in self.collocation_list (num، window_size)
ملف "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site -pack \ nltk \ text.py" ، السطر 444 ، في
w1 + "" + w2 for w1، w2 in self.collocation_list (num، window_size)
ValueError: قيم كثيرة جدًا لتفكيكها (المتوقع 2)
networkjr يمكنني تأكيد ذلك أيضًا. ربما لم يتم دفع الإصلاح في # 2227 إلى PyPi حتى الآن؟
networkjr نفس الشيء مع حزمة Anaconda
أنا أعمل على كتاب NLTK ، فأنا جديد تمامًا على NLTK وجديد إلى حد ما في Python - وأتلقى نفس الخطأ.
$ 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)
وفقًا لـ Pipfile.lock
أنا أستخدم NLTK 3.4.5 والذي أعتقد أنه أحدث إصدار.
هل هناك حل لهذه المشكلة؟
تم إصلاح هذا في # 2377 ، ويجب إصلاحه في إصدار NLTK التالي قريبًا.
خلاف ذلك ، إذا كنت لا تستطيع الانتظار =)
pip install -U https://github.com/nltk/nltk/archive/develop.zip
لا يزال لدي نفس الخطأ بعد تحديث cntk مع
pip install -U https://github.com/nltk/nltk/archive/develop.zip
إصدار cnkt الحالي "3.4.5"
كيف يمكنني إصلاح ذلك؟
تشكرات.
لا تزال أيضًا تواجه مشكلات مع .collocations()
، لكن .collocation_list()
يعمل.
استبدل في السطر 444 في /nltk/text.py:
collocation_strings = [w1 + "" + w2 for w1، w2 in text.collocation_list (num، window_size)]
كالآتي:
collocation_strings = [w لـ w في text.collocation_list (num، window_size)]
نفسه هنا. يؤدي العمل من خلال كتاب nltk إلى حدوث خطأ في عمليات التجميع () بينما يعمل collocation_list ().
التعليق الأكثر فائدة
لا تزال أيضًا تواجه مشكلات مع
.collocations()
، لكن.collocation_list()
يعمل.