Exercises
○ Create a variable
phrasecontaining 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_unioncorpus reader. Count occurrences ofmen,women, andpeoplein 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access