Package nltk :: Package corpus :: Package reader :: Module chunked :: Class ChunkedCorpusReader
[hide private]
[frames] | no frames]

Class ChunkedCorpusReader

source code

      object --+    
               |    
api.CorpusReader --+
                   |
                  ChunkedCorpusReader

Reader for chunked (and optionally tagged) corpora. Paragraphs are split using a block reader. They are then tokenized into sentences using a sentence tokenizer. Finally, these sentences are parsed into chunk trees using a string-to-chunktree conversion function. Each of these steps can be performed using a default function or a custom function. By default, paragraphs are split on blank lines; sentences are listed one per line; and sentences are parsed into chunk trees using chunk.tagstr2tree.

Instance Methods [hide private]
 
__init__(self, root, files, extension='', str2chunktree=<function tagstr2tree at 0x154bc70>, sent_tokenizer=RegexpTokenizer(pattern='\n', gaps=True, discard_empty=True, f..., para_block_reader=<function read_blankline_block at 0x1575470>, encoding=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
str
raw(self, files=None)
Returns: the given file or files as a single string.
source code
list of str
words(self, files=None)
Returns: the given file or files as a list of words and punctuation symbols.
source code
list of (list of str)
sents(self, files=None)
Returns: the given file or files as a list of sentences or utterances, each encoded as a list of word strings.
source code
list of (list of (list of str))
paras(self, files=None)
Returns: the given file or files as a list of paragraphs, each encoded as a list of sentences, which are in turn encoded as lists of word strings.
source code
list of (str,str)
tagged_words(self, files=None)
Returns: the given file or files as a list of tagged words and punctuation symbols, encoded as tuples (word,tag).
source code
list of (list of (str,str))
tagged_sents(self, files=None)
Returns: the given file or files as a list of sentences, each encoded as a list of (word,tag) tuples.
source code
list of (list of (list of (str,str)))
tagged_paras(self, files=None)
Returns: the given file or files as a list of paragraphs, each encoded as a list of sentences, which are in turn encoded as lists of (word,tag) tuples.
source code
list of ((str,str) and Tree)
chunked_words(self, files=None)
Returns: the given file or files as a list of tagged words and chunks.
source code
list of Tree
chunked_sents(self, files=None)
Returns: the given file or file as a list of sentences, each encoded as a shallow Tree.
source code
list of (list of Tree)
chunked_paras(self, files=None)
Returns: the given file or files as a list of paragraphs, each encoded as a list of sentences, which are in turn encoded as a shallow Tree.
source code
 
_read_block(self, stream) source code

Inherited from api.CorpusReader: __repr__, abspath, abspaths, encoding, files, open

Inherited from api.CorpusReader (private): _get_root

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

    Deprecated since 0.9.1

Inherited from api.CorpusReader: filenames

Inherited from api.CorpusReader (private): _get_items

Instance Variables [hide private]
  _cv_args
Arguments for corpus views generated by this corpus: a tuple (str2chunktree, sent_tokenizer, para_block_tokenizer)

Inherited from api.CorpusReader (private): _encoding, _files, _root

Properties [hide private]

Inherited from api.CorpusReader: root

Inherited from object: __class__

    Deprecated since 0.9.1

Inherited from api.CorpusReader: items

Method Details [hide private]

__init__(self, root, files, extension='', str2chunktree=<function tagstr2tree at 0x154bc70>, sent_tokenizer=RegexpTokenizer(pattern='\n', gaps=True, discard_empty=True, f..., para_block_reader=<function read_blankline_block at 0x1575470>, encoding=None)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • root - The root directory for this corpus.
  • files - A list or regexp specifying the files in this corpus.
Overrides: api.CorpusReader.__init__

raw(self, files=None)

source code 
Returns: str
the given file or files as a single string.

words(self, files=None)

source code 
Returns: list of str
the given file or files as a list of words and punctuation symbols.

sents(self, files=None)

source code 
Returns: list of (list of str)
the given file or files as a list of sentences or utterances, each encoded as a list of word strings.

paras(self, files=None)

source code 
Returns: list of (list of (list of str))
the given file or files as a list of paragraphs, each encoded as a list of sentences, which are in turn encoded as lists of word strings.

tagged_words(self, files=None)

source code 
Returns: list of (str,str)
the given file or files as a list of tagged words and punctuation symbols, encoded as tuples (word,tag).

tagged_sents(self, files=None)

source code 
Returns: list of (list of (str,str))
the given file or files as a list of sentences, each encoded as a list of (word,tag) tuples.

tagged_paras(self, files=None)

source code 
Returns: list of (list of (list of (str,str)))
the given file or files as a list of paragraphs, each encoded as a list of sentences, which are in turn encoded as lists of (word,tag) tuples.

chunked_words(self, files=None)

source code 
Returns: list of ((str,str) and Tree)
the given file or files as a list of tagged words and chunks. Words are encoded as (word, tag) tuples (if the corpus has tags) or word strings (if the corpus has no tags). Chunks are encoded as depth-one trees over (word,tag) tuples or word strings.

chunked_sents(self, files=None)

source code 
Returns: list of Tree
the given file or file as a list of sentences, each encoded as a shallow Tree. The leaves of these trees are encoded as (word, tag) tuples (if the corpus has tags) or word strings (if the corpus has no tags).

chunked_paras(self, files=None)

source code 
Returns: list of (list of Tree)
the given file or files as a list of paragraphs, each encoded as a list of sentences, which are in turn encoded as a shallow Tree. The leaves of these trees are encoded as (word, tag) tuples (if the corpus has tags) or word strings (if the corpus has no tags).