Code from the Python NLTK book.