Processing text corpora with NLTK: Unterschied zwischen den Versionen

Aus Westslawische Sprachen

Wechseln zu: Navigation, Suche
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 4: Zeile 4:
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
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


<code>
<pre>
> import nltk
> import nltk
> from nltk.corpus import PlaintextCorpusReader
> from nltk.corpus import PlaintextCorpusReader
Zeile 12: Zeile 12:
> mycorpus.words()
> mycorpus.words()
> mycorpusText.concordance("кое-какое")
> mycorpusText.concordance("кое-какое")
</code>
</pre>

Version vom 14. Mai 2017, 00:14 Uhr

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("кое-какое")