mmax2conll/mmax2conll/mmax_document_readers.py
def extract_sentences(self, xml):
        """
        Extract all sentences and validate them.

        Returns a list of sentences, where a sentence is a list of things
        returned by `self.item_reader.read`.
        """
        words = self.extract_items(xml)
        sentences = []
        sentence = None

        # Because sentence is None, an error will be raised if the first word
        # has a word_number different from '0'
        while True:
            # Get the next word or stop if there isn't one
            try:
                word = next(words)
            except StopIteration:
                break

            # Check if we should start a new sentence and use `continue` if
            # we should not start a new sentence.
            if word['word_number'] != self.sent_start_word_number:
                # I'm using try-catch because this is an edge case and checking
                # every time is therefore more costly than catching once.
                try:
                    sentence.append(word)
                except AttributeError as e:
                    if sentence is None:
                        # We know what's wrong!
                        # Ignore if we're not validating
                        if self.validate:
                            raise ValidationError(
                                f"The first word ({word['word']!r}) does not"
                                f" have 'word_number' =="
                                f" {self.sent_start_word_number!r}. Found:"
                                f" {word['word_number']!r}"
                            ) from e
                        # else ignore this problem and fix it by starting a new
                        # sentence. The program flow will end up in the piece
                        # of code below that creates a new sentence.
                    else:
                        # We don't know what's wrong :(
                        raise e
                else:
                    # Adding the word to the existing sentence worked just fine
                    # So prevent creating a new sentence.
                    continue

            # This is the start of a new sentence, because the previous code
            # block would have called `continue` if it wasn't.
            # This is to prevent duplication of the following two lines.
            # The word_number is now validated
            sentence = [word]
            sentences.append(sentence)

        if self.validate:
            self.validate_sentences(sentences)

        return sentences

        Extract all sentences and validate them.

        Returns a list of sentences, where a sentence is a list of things
        returned by `self.item_reader.read`.
        
Extract all sentences and validate them.
Returns a list of sentences, where a sentence is a list of things
returned by `self.item_reader.read`.
Extract all sentences and validate them . Returns a list of sentences where a sentence is a list of things returned by ` self . item_reader . read ` .
def extract_sentences(self, xml):
        words = self.extract_items(xml)
        sentences = []
        sentence = None
        while True:
            try:
                word = next(words)
            except StopIteration:
                break
            if word['word_number'] != self.sent_start_word_number:
                try:
                    sentence.append(word)
                except AttributeError as e:
                    if sentence is None:
                        if self.validate:
                            raise ValidationError(
                                f"The first word ({word['word']!r}) does not"
                                f" have 'word_number' =="
                                f" {self.sent_start_word_number!r}. Found:"
                                f" {word['word_number']!r}"
                            ) from e
                    else:
                        raise e
                else:
                    continue
            sentence = [word]
            sentences.append(sentence)
        if self.validate:
            self.validate_sentences(sentences)
        return sentences
def extract_sentences ( self , xml ) : words = self . extract_items ( xml ) sentences = [ ] sentence = None while True : try : word = next ( words ) except StopIteration : break if word [ 'word_number' ] != self . sent_start_word_number : try : sentence . append ( word ) except AttributeError as e : if sentence is None : if self . validate : raise ValidationError ( f"The first word ({word['word']!r}) does not" f" have 'word_number' ==" f" {self.sent_start_word_number!r}. Found:" f" {word['word_number']!r}" ) from e else : raise e else : continue sentence = [ word ] sentences . append ( sentence ) if self . validate : self . validate_sentences ( sentences ) return sentences
Extract all sentences and validate them.
Extract all sentences and validate them .
"""
        Extract all sentences and validate them.

        Returns a list of sentences, where a sentence is a list of things
        returned by `self.item_reader.read`.
        """ # Because sentence is None, an error will be raised if the first word # has a word_number different from '0' # Get the next word or stop if there isn't one # Check if we should start a new sentence and use `continue` if # we should not start a new sentence. # I'm using try-catch because this is an edge case and checking # every time is therefore more costly than catching once. # We know what's wrong! # Ignore if we're not validating # else ignore this problem and fix it by starting a new # sentence. The program flow will end up in the piece # of code below that creates a new sentence. # We don't know what's wrong :( # Adding the word to the existing sentence worked just fine # So prevent creating a new sentence. # This is the start of a new sentence, because the previous code # block would have called `continue` if it wasn't. # This is to prevent duplication of the following two lines. # The word_number is now validated
self
xml