mmax2conll/mmax2conll/mmax_document_readers.py
def validate_part_number(sentences):
        """
        Validate part number of these sentences

        Assumes `word_number` is already validated.

        `part_number` must be:
         - an integer, None or missing
         - increasing or (missing or None) everywhere
         - the same within a sentence
        """
        prev_part_number = None
        for senti, sentence in enumerate(sentences):
            if len(sentence) == 0:
                logger.warn(f"Sentence #{senti} is empty")

            for word in sentence:
                part_number = word.get('part_number', None)
                if part_number is None:
                    break
                try:
                    part_number = int(part_number)
                except ValueError as e:
                    raise ValidationError(
                        f"The part number of {word['word']!r} is not a"
                        f" number but {word['part_number']!r}."
                        f" This is in sentence #{senti}: {sentence!r}."
                    ) from e
                if word['word_number'] == '0':
                    prev_part_number = part_number
                elif prev_part_number != part_number:
                    raise ValidationError(
                        f"The part number of {word['word']!r} is different"
                        f" from the part number of the first word of the"
                        f" sentence. Expected {prev_part_number}, found:"
                        f" {part_number}."
                        f" This is in sentence #{senti}: {sentence!r}."
                    )

            if part_number is None:
                # The first part number was None, which means _all_ part
                # numbers should be None
                others_have_number = (
                    word.get('part_number', None) is not None
                    for sentence in sentences
                    for word in sentence
                )
                if prev_part_number is not None or any(others_have_number):
                    raise ValidationError(
                        f"Sentence #{senti} is missing a part number:"
                        f" {sentence!r}."
                    )
                else:
                    # Everything is None, so we're Done!
                    break

            if prev_part_number != part_number:
                if prev_part_number > part_number:
                    raise ValidationError(
                        f"The part number of sentence #{senti} should be"
                        f" greater than {prev_part_number}."
                        f" Found: {part_number}"
                    )

        Validate part number of these sentences

        Assumes `word_number` is already validated.

        `part_number` must be:
         - an integer, None or missing
         - increasing or (missing or None) everywhere
         - the same within a sentence
        
Validate part number of these sentences
Assumes `word_number` is already validated.

`part_number` must be:
an integer, None or missing
increasing or (missing or None) everywhere
the same within a sentence
Validate part number of these sentences Assumes ` word_number ` is already validated . ` part_number ` must be : an integer None or missing increasing or ( missing or None ) everywhere the same within a sentence
def validate_part_number(sentences):
        prev_part_number = None
        for senti, sentence in enumerate(sentences):
            if len(sentence) == 0:
                logger.warn(f"Sentence #{senti} is empty")
            for word in sentence:
                part_number = word.get('part_number', None)
                if part_number is None:
                    break
                try:
                    part_number = int(part_number)
                except ValueError as e:
                    raise ValidationError(
                        f"The part number of {word['word']!r} is not a"
                        f" number but {word['part_number']!r}."
                        f" This is in sentence #{senti}: {sentence!r}."
                    ) from e
                if word['word_number'] == '0':
                    prev_part_number = part_number
                elif prev_part_number != part_number:
                    raise ValidationError(
                        f"The part number of {word['word']!r} is different"
                        f" from the part number of the first word of the"
                        f" sentence. Expected {prev_part_number}, found:"
                        f" {part_number}."
                        f" This is in sentence #{senti}: {sentence!r}."
                    )
            if part_number is None:
                others_have_number = (
                    word.get('part_number', None) is not None
                    for sentence in sentences
                    for word in sentence
                )
                if prev_part_number is not None or any(others_have_number):
                    raise ValidationError(
                        f"Sentence #{senti} is missing a part number:"
                        f" {sentence!r}."
                    )
                else:
                    break
            if prev_part_number != part_number:
                if prev_part_number > part_number:
                    raise ValidationError(
                        f"The part number of sentence #{senti} should be"
                        f" greater than {prev_part_number}."
                        f" Found: {part_number}"
                    )
def validate_part_number ( sentences ) : prev_part_number = None for senti , sentence in enumerate ( sentences ) : if len ( sentence ) == 0 : logger . warn ( f"Sentence #{senti} is empty" ) for word in sentence : part_number = word . get ( 'part_number' , None ) if part_number is None : break try : part_number = int ( part_number ) except ValueError as e : raise ValidationError ( f"The part number of {word['word']!r} is not a" f" number but {word['part_number']!r}." f" This is in sentence #{senti}: {sentence!r}." ) from e if word [ 'word_number' ] == '0' : prev_part_number = part_number elif prev_part_number != part_number : raise ValidationError ( f"The part number of {word['word']!r} is different" f" from the part number of the first word of the" f" sentence. Expected {prev_part_number}, found:" f" {part_number}." f" This is in sentence #{senti}: {sentence!r}." ) if part_number is None : others_have_number = ( word . get ( 'part_number' , None ) is not None for sentence in sentences for word in sentence ) if prev_part_number is not None or any ( others_have_number ) : raise ValidationError ( f"Sentence #{senti} is missing a part number:" f" {sentence!r}." ) else : break if prev_part_number != part_number : if prev_part_number > part_number : raise ValidationError ( f"The part number of sentence #{senti} should be" f" greater than {prev_part_number}." f" Found: {part_number}" )
Validate part number of these sentences
Assumes `word_number` is already validated.
Validate part number of these sentences Assumes ` word_number ` is already validated .
"""
        Validate part number of these sentences

        Assumes `word_number` is already validated.

        `part_number` must be:
         - an integer, None or missing
         - increasing or (missing or None) everywhere
         - the same within a sentence
        """ # The first part number was None, which means _all_ part # numbers should be None # Everything is None, so we're Done!
sentences