μ± μ 1 μ₯μ μ΄ν΄ λ΄€λλ° collocations ν¨μκ° μ€λ₯λ₯Ό λ°νν©λλ€. collocation_list ν¨μκ° λμ λμμΌλ―λ‘ text.pyμ 440 νμ΄ μ€λ³΅λλ κ²μ²λΌ 보μ λλ€. text.pyμμ νμ¬ μ€ 440κ³Ό μ€ 441μ λ€μ μμ±νμ¬ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ€.
μ΄μ μ½λ :
collocation_strings = [w1 + ''+ w2 for w1, w2 in self.collocation_list (num, window_size)] *
print (tokenwrap (collocation_strings, separator = ";"))
μ μ½λ :
print (tokenwrap (self.collocation_list (), separator = ";"))
λ²κ·Έλ₯Ό μ κΈ° ν΄ μ£Όμ @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)
μ± μ 1 μ₯μ μ§νν λλμ΄ μ€λ₯κ° κ³μ νμλ©λλ€.
* NLTK Bookμ μκ° μμ *
text1, ..., text9 λ° sent1, ..., sent9λ‘λ μ€
λ³Ό ν
μ€νΈ λλ λ¬Έμ₯μ μ΄λ¦μ μ
λ ₯νμμμ€.
μλ£λ₯Ό λμ΄νλ €λ©΄ 'texts ()'λλ 'sents ()'λ₯Ό μ
λ ₯νμμμ€.
text1 : Herman Melville 1851μ Moby Dick
text2 : Jane Austen 1811μ κ°κ°κ³Ό κ°μ±
text3 : μ°½μΈκΈ°
text4 : μ·¨μ μ°μ€ μ½νΌμ€
text5 : μ½νΌμ€ μ±ν
text6 : λͺ¬ν° νμ΄μ¬κ³Ό μ±λ°°
text7 : μμ€νΈλ¦¬νΈ μ λ
text8 : νΌμ€λ μ½νΌμ€
text9 : λͺ©μμΌμ μμλ λ¨μ by G. K. 체μ€ν°ν΄ 1908
μ μΆμ (κ°μ₯ μ΅κ·Ό νΈμΆ λ§μ§λ§) :
νμΌ "c : UsersAdam.vscodeextensionsms-python.python-2019.6.24221pythonFilesptvsd_launcher.py", 43 ν
main (ptvsdArgs)
νμΌ "c : UsersAdam.vscodeextensionsms-python.python-2019.6.24221pythonFileslibpythonptvsd__main __. py", μ€ 434, κΈ°λ³Έ
μ΄μ()
run_fileμ "c : UsersAdam.vscodeextensionsms-python.python-2019.6.24221pythonFileslibpythonptvsd__main __. py", 312 ν νμΌ
runpy.run_path (λμ, run_name = '__ main__')
run_pathμμλ "c : usersadamappdatalocalprogramspythonpython37-32Librunpy.py", 263 ν νμΌ
pkg_name = pkg_name, script_name = fname)
_run_module_codeμ νμΌ "c : usersadamappdatalocalprogramspythonpython37-32Librunpy.py", 96 ν
mod_name, mod_spec, pkg_name, script_name)
_run_codeμμλ νμΌ "c : usersadamappdatalocalprogramspythonpython37-32Librunpy.py", 85 ν
exec (μ½λ, run_globals)
νμΌ "c : UsersAdamDocumentscodepythonnatlangnatlang.py", 4 ν,
text4.collocations ()
λ°°μ΄μμλ νμΌ "C : UsersAdam.virtualenvsnatlang-9ek-vNymlibsite-packagesnltktext.py", 444 ν
w1 + ""+ w2 for w1, w2 in self.collocation_list (num, window_size)
νμΌ "C : UsersAdam.virtualenvsnatlang-9ek-vNymlibsite-packagesnltktext.py", μ€ 444, in
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()
λ μλν©λλ€.
/nltk/text.pyμ 444 νμμ κ΅μ²΄νμμμ€.
collocation_strings = [w1 + ""+ w2 for w1, w2 in text.collocation_list (num, window_size)]
λ€μκ³Ό ν¨κ» :
collocation_strings = [w for w in text.collocation_list (num, window_size)]
μ¬κΈ°λ λ§μ°¬κ°μ§μ λλ€. nltk μ± μ ν΅ν΄ μμ νλ©΄ collocations ()μ μ€λ₯κ° λ°μνλ λ°λ©΄ collocation_list ()λ μλν©λλ€.
κ°μ₯ μ μ©ν λκΈ
.collocations()
μλ μ¬μ ν λ¬Έμ κ° μμ§λ§.collocation_list()
λ μλν©λλ€.