Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Python 3 Text Processing with NLTK 3 Cookbook

You're reading from  Python 3 Text Processing with NLTK 3 Cookbook

Product type Book
Published in Aug 2014
Publisher
ISBN-13 9781782167853
Pages 304 pages
Edition 1st Edition
Languages
Author (1):
Jacob Perkins Jacob Perkins
Profile icon Jacob Perkins

Table of Contents (17) Chapters

Python 3 Text Processing with NLTK 3 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Tokenizing Text and WordNet Basics Replacing and Correcting Words Creating Custom Corpora Part-of-speech Tagging Extracting Chunks Transforming Chunks and Trees Text Classification Distributed Processing and Handling Large Datasets Parsing Specific Data Types Penn Treebank Part-of-speech Tags
Index

Creating a MongoDB-backed corpus reader


All the corpus readers we've dealt with so far have been file-based. That is in part due to the design of the CorpusReader base class, and also the assumption that most corpus data will be in text files. However, sometimes you'll have a bunch of data stored in a database that you want to access and use just like a text file corpus. In this recipe, we'll cover the case where you have documents in MongoDB, and you want to use a particular field of each document as your block of text.

Getting ready

MongoDB is a document-oriented database that has become a popular alternative to relational databases such as MySQL. The installation and setup of MongoDB is outside the scope of this book, but you can find instructions at http://docs.mongodb.org/manual/.

You'll also need to install PyMongo, a Python driver for MongoDB. You should be able to do this with either easy_install or pip, by typing sudo easy_install pymongo or sudo pip install pymongo.

The following code...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}