Exercises
○ Create a variable
phrase
containing a list of words. Experiment with the operations described in this chapter, including addition, multiplication, indexing, slicing, and sorting.○ Use the corpus module to explore
austen-persuasion.txt
. How many word tokens does this book have? How many word types?○ Use the Brown Corpus reader
nltk.corpus.brown.words()
or the Web Text Corpus readernltk.corpus.webtext.words()
to access some sample text in two different genres.○ Read in the texts of the State of the Union addresses, using the
state_union
corpus reader. Count occurrences ofmen
,women
, andpeople
in each document. What has happened to the usage of these words over time?○ Investigate the holonym-meronym relations for some nouns. Remember that there are three kinds of holonym-meronym relation, so you need to use
member_meronyms()
,part_meronyms()
,substance_meronyms()
,member_holonyms()
,part_holonyms()
, andsubstance_holonyms()
.○ In the discussion of comparative wordlists, we created an object called
translate
, which you could look up using words in both German and Italian in order to get corresponding words in English. What problem might arise with this approach? Can you suggest a way to avoid this problem?○ According to Strunk and White’s Elements of Style, the word however, used at the start of a sentence, means “in whatever way” or “to whatever extent,” and not “nevertheless.” They give this example of correct usage: However you advise him, he will probably do as he ...
Get Natural Language Processing with Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.