"Python Natural Language Processing" Chinese version-error correction "Update ... 】

Source: Internet
Author: User
Tags nltk

Recently in the "Python Natural language Processing," the Chinese version of the book, probably because it is from py2.x to py3.x, plus the reason for the update of NLTK, or some of the author's clerical errors, in the book a lot of code can not be run, the following I would like to tidy up a bit of problematic code.

The first chapter:

P3. The office is a small suggestion, there is no error in the book: About Nltk.book Download, it is best to download to the '/nltk_data ' folder, such as ' D:/nltk_data '

P7.text3.generate (). The Generate () function usage is obsolete and is looking for the latest method.

P18. About the Freqdist () function has been updated, if the code is typed according to the book, and will not get the expected results, you can use the following method to improve to get the same result:

>>>fdist1=freqdist (Text1)>>>len (fdist1)19317>>>vocabulary1=sorted (Fdist1.items (), key=Lambda jj:jj[1],reverse=True)>>>s=[]>>> for   in range (len (vocabulary1)):            s.append (vocabulary1[i][0])>>>print(s)

P22. The Freqdist function, which is the same as the 18-page problem, can be improved by copying the above workaround.

P32.babelize_shell () The function is no longer available in nltk3.0, skipping the explanation section of the function.

Chapter II:

P48 page: CFD=NLTK. Conditionalfreqdist ((Target,file[:4]) for Fileid in Inaugural.fileids () for W in Inaugural.words (Fileid) for Target in [' A Merica ', ' citizen '] if W.lower (). StartsWith (target) will display an error

Correction: Change the file[:4 in the first parenthesis] to Fileid[:4]. namely: CFD=NLTK. Conditionalfreqdist ((Target,fileid[:4]) for Fileid in Inaugural.fileids () for W in Inaugural.words (Fileid) for Target in [ ' America ', ' citizen '] if W.lower (). StartsWith (target))

P51: The last line of code Cfd.plot (cumulative=true less close brackets.

Because it is just beginning to see, so the latter has not seen, this article will continue to update the new errors encountered, but also welcome to add.

"Python Natural Language Processing" Chinese version-error correction "Update ... 】

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.