class PlaintextCorpusReader(CorpusReader): (source)
Known subclasses: nltk.corpus.reader.CategorizedPlaintextCorpusReader
, nltk.corpus.reader.EuroparlCorpusReader
, nltk.corpus.reader.UdhrCorpusReader
Constructor: PlaintextCorpusReader(root, fileids, word_tokenizer, sent_tokenizer, ...)
Reader for corpora that consist of plaintext documents. Paragraphs are assumed to be split using blank lines. Sentences and words can be tokenized using the default tokenizers, or by custom tokenizers specificed as parameters to the constructor.
This corpus reader can be customized (e.g., to skip preface sections of specific document formats) by creating a subclass and overriding the CorpusView class variable.
Method | __init__ |
Construct a new plaintext corpus reader for a set of documents located at the given root directory. Example usage: |
Method | paras |
No summary |
Method | raw |
No summary |
Method | sents |
No summary |
Method | words |
No summary |
Method | _read |
Undocumented |
Method | _read |
Undocumented |
Method | _read |
Undocumented |
Instance Variable | _para |
Undocumented |
Instance Variable | _sent |
Undocumented |
Instance Variable | _word |
Undocumented |
Inherited from CorpusReader
:
Method | __repr__ |
Undocumented |
Method | abspath |
Return the absolute path for the given file. |
Method | abspaths |
Return a list of the absolute paths for all fileids in this corpus; or for the given list of fileids, if specified. |
Method | citation |
Return the contents of the corpus citation.bib file, if it exists. |
Method | encoding |
Return the unicode encoding for the given corpus file, if known. If the encoding is unknown, or if the given file should be processed using byte strings (str), then return None. |
Method | ensure |
Load this corpus (if it has not already been loaded). This is used by LazyCorpusLoader as a simple method that can be used to make sure a corpus is loaded -- e.g., in case a user wants to do help(some_corpus). |
Method | fileids |
Return a list of file identifiers for the fileids that make up this corpus. |
Method | license |
Return the contents of the corpus LICENSE file, if it exists. |
Method | open |
Return an open stream that can be used to read the given file. If the file's encoding is not None, then the stream will automatically decode the file's contents into unicode. |
Method | readme |
Return the contents of the corpus README file, if it exists. |
Class Variable | root |
Undocumented |
Method | _get |
Undocumented |
Instance Variable | _encoding |
The default unicode encoding for the fileids that make up this corpus. If encoding is None, then the file contents are processed using byte strings. |
Instance Variable | _fileids |
A list of the relative paths for the fileids that make up this corpus. |
Instance Variable | _root |
The root directory for this corpus. |
Instance Variable | _tagset |
Undocumented |
nltk.corpus.reader.CorpusReader.__init__
nltk.corpus.reader.CategorizedPlaintextCorpusReader
, nltk.corpus.reader.UdhrCorpusReader
Construct a new plaintext corpus reader for a set of documents located at the given root directory. Example usage:
>>> root = '/usr/local/share/nltk_data/corpora/webtext/' >>> reader = PlaintextCorpusReader(root, '.*\.txt') # doctest: +SKIP
Parameters | |
root | The root directory for this corpus. |
fileids | A list or regexp specifying the fileids in this corpus. |
word | Tokenizer for breaking sentences or paragraphs into words. |
sent | Tokenizer for breaking paragraphs into words. |
para | The block reader used to divide the corpus into paragraph blocks. |
encoding | Undocumented |
nltk.corpus.reader.CategorizedPlaintextCorpusReader
, nltk.corpus.reader.EuroparlCorpusReader
Returns | |
list(list(list(str))) | the given file(s) as a list of paragraphs, each encoded as a list of sentences, which are in turn encoded as lists of word strings. |
nltk.corpus.reader.CategorizedPlaintextCorpusReader
Returns | |
str | the given file(s) as a single string. |
nltk.corpus.reader.CategorizedPlaintextCorpusReader
Returns | |
list(list(str)) | the given file(s) as a list of sentences or utterances, each encoded as a list of word strings. |
nltk.corpus.reader.CategorizedPlaintextCorpusReader
Returns | |
list(str) | the given file(s) as a list of words and punctuation symbols. |