def of(chapter: Chapter, query: TransliterationQuery) -> "ChapterInfo": matching_lines = chapter.get_matching_lines(query) matching_colophon_lines = chapter.get_matching_colophon_lines(query) return ChapterInfo( chapter.id_, { manuscript.id: manuscript.siglum for manuscript in chapter.manuscripts }, matching_lines, matching_colophon_lines, )
def _update_chapter(self, chapter: Chapter) -> Chapter: return self._sing_updater.update( chapter.merge( attr.evolve( chapter, lines=(*self._lines, *self._lines_update.new), parser_version=ATF_PARSER_VERSION, )))
def test_duplicate_ids_are_invalid(): with pytest.raises(ValueError): Chapter( TEXT_ID, manuscripts=( Manuscript(MANUSCRIPT_ID, siglum_disambiguator="a"), Manuscript(MANUSCRIPT_ID, siglum_disambiguator="b"), ), )
def test_invalid_extent() -> None: with pytest.raises(ValueError): Chapter( TextId(GENRE, 0, 0), manuscripts=(Manuscript(MANUSCRIPT_ID), ), lines=(Line( LineNumber(1), (LINE_VARIANT_1, ), translation=(TranslationLine(tuple(), extent=Extent(LineNumber(2))), ), ), ), )
def make_chapter(self, data: dict, **kwargs) -> Chapter: return Chapter( data["text_id"], Classification(data["classification"]), Stage(data["stage"]), data["version"], data["name"], data["order"], tuple(data["manuscripts"]), tuple(data["uncertain_fragments"]), tuple(data["lines"]), tuple(data["signs"]), data["record"], data["parser_version"], )
def test_extant_lines() -> None: manuscript = Manuscript(MANUSCRIPT_ID) manuscript_line = LINE_VARIANT_1.manuscripts[0] chapter = Chapter( TEXT_ID, manuscripts=(manuscript, ), lines=( Line(LineNumber(1), (LINE_VARIANT_1, )), Line(LineNumber(2), (LINE_VARIANT_2, )), ), ) assert chapter.extant_lines == { manuscript.siglum: { manuscript_line.labels: [ExtantLine(manuscript_line.labels, LineNumber(1), True)] } }
def test_missing_manuscripts_are_invalid(): with pytest.raises(ValueError): Chapter( TEXT_ID, manuscripts=(Manuscript(MANUSCRIPT_ID), ), lines=(Line( LINE_NUMBER, (LineVariant( LINE_RECONSTRUCTION, NOTE, (ManuscriptLine(MANUSCRIPT_ID + 1, LABELS, MANUSCRIPT_TEXT_1), ), ), ), IS_SECOND_LINE_OF_PARALLELISM, IS_BEGINNING_OF_SECTION, ), ), )
def test_overlapping_languages() -> None: Chapter( TextId(GENRE, 0, 0), manuscripts=(Manuscript(MANUSCRIPT_ID), ), lines=( Line( LineNumber(1), (LINE_VARIANT_1, ), translation=(TranslationLine(tuple(), "en", Extent(LineNumber(2))), ), ), Line( LineNumber(2), (LINE_VARIANT_2, ), translation=(TranslationLine(tuple(), "de"), ), ), ), )
def test_extant_lines_schema() -> None: manuscript = Manuscript(1) manuscript_line = ManuscriptLine(1, LABELS, MANUSCRIPT_TEXT_1) variant = LineVariant(tuple(), manuscripts=(manuscript_line, )) text_line = Line(LineNumber(1), (variant, )) chapter = Chapter(TextId(Genre.LITERATURE, 0, 0), manuscripts=(manuscript, ), lines=(text_line, )) assert ExtantLinesSchema().dump(chapter) == { "extantLines": { str(manuscript.siglum): { " ".join(label.to_value() for label in manuscript_line.labels): [{ "isSideBoundary": False, "lineNumber": OneOfLineNumberSchema().dump(text_line.number), }] } } }
def test_duplicate_sigla_are_invalid(): with pytest.raises(ValueError): Chapter( TEXT_ID, manuscripts=( Manuscript( MANUSCRIPT_ID, siglum_disambiguator=SIGLUM_DISAMBIGUATOR, period=PERIOD, provenance=PROVENANCE, type=TYPE, ), Manuscript( MANUSCRIPT_ID + 1, siglum_disambiguator=SIGLUM_DISAMBIGUATOR, period=PERIOD, provenance=PROVENANCE, type=TYPE, ), ), )
def test_extant_lines_mixed_sides() -> None: manuscript = Manuscript( MANUSCRIPT_ID, siglum_disambiguator="1", period_modifier=PeriodModifier.NONE, period=Period.LATE_BABYLONIAN, provenance=Provenance.BABYLON, type=ManuscriptType.SCHOOL, ) manuscript_line = ManuscriptLine( MANUSCRIPT_ID, LABELS, TextLine( LineNumberRange(LineNumber(1), LineNumber(3, suffix_modifier="b")), (UnknownNumberOfSigns.of(), ), ), PARATEXT, OMITTED_WORDS, ) manuscript_line2 = ManuscriptLine( MANUSCRIPT_ID, tuple(), TextLine(LineNumber(2), (UnknownNumberOfSigns.of(), )), PARATEXT, OMITTED_WORDS, ) manuscript_line3 = ManuscriptLine( MANUSCRIPT_ID, LABELS, TextLine(LineNumber(3), (UnknownNumberOfSigns.of(), )), PARATEXT, OMITTED_WORDS, ) chapter = Chapter( TEXT_ID, manuscripts=(manuscript, ), lines=( Line( LineNumber(1), (LineVariant(LINE_RECONSTRUCTION, NOTE, (manuscript_line, ), PARALLEL_LINES), ), ), Line( LineNumber(2), (LineVariant(LINE_RECONSTRUCTION, NOTE, (manuscript_line2, ), PARALLEL_LINES), ), ), Line( LineNumber(3), (LineVariant(LINE_RECONSTRUCTION, NOTE, (manuscript_line3, ), PARALLEL_LINES), ), ), ), ) assert chapter.extant_lines == { manuscript.siglum: { manuscript_line.labels: [ ExtantLine(manuscript_line.labels, LineNumber(1), True), ExtantLine(manuscript_line3.labels, LineNumber(3), False), ], manuscript_line2.labels: [ExtantLine(manuscript_line2.labels, LineNumber(2), False)], } }
def test_duplicate_line_numbers_invalid(): with pytest.raises(ValueError): Chapter(TEXT_ID, lines=(LINE_1, LINE_1))
) TEXT_ID = TextId(GENRE, CATEGORY, INDEX) CHAPTER = Chapter( TEXT_ID, CLASSIFICATION, STAGE, VERSION, CHAPTER_NAME, ORDER, (Manuscript( MANUSCRIPT_ID, SIGLUM_DISAMBIGUATOR, MUSEUM_NUMBER, ACCESSION, PERIOD_MODIFIER, PERIOD, PROVENANCE, TYPE, NOTES, COLOPHON, UNPLACED_LINES, REFERENCES, ), ), (MUSEUM_NUMBER, ), (LINE_1, LINE_2, LINE_3), SIGNS, RECORD, ) def test_constructor_sets_correct_fields():
TEXT_ID = TextId(Genre.LITERATURE, 0, 0) CLASSIFICATION = Classification.ANCIENT STAGE = Stage.NEO_BABYLONIAN VERSION = "A" CHAPTER_NAME = "I" ORDER = 1 MANUSCRIPT = Manuscript(MANUSCRIPT_ID) MUSEUM_NUMBER = MuseumNumber.of("K.1") CHAPTER = Chapter( TEXT_ID, CLASSIFICATION, STAGE, VERSION, CHAPTER_NAME, ORDER, (MANUSCRIPT, ), (MUSEUM_NUMBER, ), (LINE, ), ) NEW_CLASSIFICATION = Classification.MODERN NEW_STAGE = Stage.MIDDLE_ASSYRIAN NEW_VERSION = "B" NEW_CHAPTER_NAME = "II" NEW_ORDER = 2 NEW_MANUSCRIPT = Manuscript(2, siglum_disambiguator="b") NOTE = NoteLine((StringPart("a note"), )) NEW_LINE = Line( LineNumber(1),