def _read_para_block(self, stream):
        """
        Method for retrieving paragraph annotations from text, 
        and the sentence and word annotations within each paragraph.
        @type stream: SeekableUnicodeStreamReader
        @param stream: file stream from StreamBackedCorpusView 
                        in corpus/reader/util.py
        @return: list of paragraphs, each of which is a list of sentences, 
                        each of which is a list of words, 
                        from a block of the file stream
        @rtype: C{list} of C{list} of C{str}
        """
        file = self._get_basename(stream.name) + '-logical.xml'
        sents_file = self._get_basename(stream.name) + '-s.xml'
        words_file = self._get_basename(stream.name) + '-ptbtok.xml'

        if not file == self._cur_paras_file:
            self._cur_paras_file = file
            self._cur_sents_file = sents_file
            self._cur_words_file = words_file
            offsets = self._get_annotation(file, 'p')
            sents_offsets = self._get_annotation(sents_file, 's')
            words_offsets = self._get_annotation(words_file, 'tok')
            self._cur_paras_offsets = offsets
            self._cur_sents_offsets = sents_offsets
            self._cur_words_offsets = words_offsets
            self._get_disc(stream)
            char_to_byte = self._char_to_byte
            byte_to_char = self._byte_to_char
        else:
            offsets = self._cur_paras_offsets
            sents_offsets = self._cur_sents_offsets
            words_offsets = self._cur_words_offsets
            char_to_byte = self._char_to_byte
            byte_to_char = self._byte_to_char

#        if len(offsets) == 0:
#            print "No paragraph annotations for file " + file
            # TODO skip file (advance file stream) if no tokens are found

        slimit = stream.tell()
        offset_slimit = byte_to_char.get(slimit, slimit)
        offset_elimit = offset_slimit + 500

        subset = []
        for i in offsets:
            if (i[0] >= offset_slimit and i[1] <= offset_elimit 
                                        and i[0] != i[1]):
                subset.append(i)
            if (i[0] >= offset_slimit and i[1] > offset_elimit 
                                        and i[0] != i[1]):
                subset.append(i)
                break

        if len(subset) != 0:
            last1 = subset[len(subset)-1]
            last = last1[1]
            last = char_to_byte.get(last, last)
            read_size = last - slimit
            text = stream.read(read_size)
        else:
            if offset_elimit < self._file_end:
                elimit = char_to_byte.get(offset_elimit, offset_elimit)
                read_size = elimit - slimit
                text = stream.read(read_size)
            else:
                stream.read()

        block = []
        for p in subset:
            para = []
            for s in sents_offsets:
                if s[0] >= p[0] and s[1] <= p[1] and s[0] != s[1]:
                    sent = []
                    for w in words_offsets:
                        if w[0] >= s[0] and w[1] <= s[1] and w[0] != w[1]:
                            start = w[0] - offset_slimit
                            end = w[1] - offset_slimit
                            chunk = text[start:end].encode('utf-8')
                            chunk = self._remove_ws(chunk)
                            sent.append(chunk)
                    para.append(sent)
            if len(para) != 0:    # If a paragraph has no internal 
                                  # sentence tokens, we disregard it
                block.append(para)
        return block
dataset/ETHPy150Open cidles/graf-python/nltk/masc.py/MascCorpusReader._read_para_block/original