Processing text corpora with NLTK

Aus Westslawische Sprachen

Wechseln zu: Navigation, Suche

Here is an elegant way to process your text data with professional CL tools: Import it into NLTK, the Natural Language Toolkit for Python3 and use all the processing tools available in NLTK.


Let us assume you have Python3 and the NLTK installed (if you haven't, follow the instructions in How to install Python3 and the NLTK. Furthermore, let us assume that your corpus texts are in UTF-8 format and stored in the folder `/Users/roland/mycorpus`. Then open a Python3 shell (IDLE, command line or other) and type

	> import nltk
	> from nltk.corpus import PlaintextCorpusReader
	> root = "/Users/roland/mycorpus"
	> mycorpus = PlaintextCorpusReader(root, '.*') # mycorpus is a nltk.Corpus
	> mycorpusText = nltk.Text(mycorpus.words()) # mycorpusText is a nltk.Text
	> mycorpus.words()
	> mycorpusText.concordance("кое-какое")