def test_deserialize_manuscript() -> None:
    references = (ReferenceFactory.build(with_document=False),)
    manuscript = ManuscriptFactory.build(references=references)
    assert (
        ApiManuscriptSchema().load(
            {
                "id": manuscript.id,
                "siglumDisambiguator": manuscript.siglum_disambiguator,
                "museumNumber": str(manuscript.museum_number)
                if manuscript.museum_number
                else "",
                "accession": manuscript.accession,
                "periodModifier": manuscript.period_modifier.value,
                "period": manuscript.period.long_name,
                "provenance": manuscript.provenance.long_name,
                "type": manuscript.type.long_name,
                "notes": manuscript.notes,
                "colophon": manuscript.colophon.atf,
                "unplacedLines": manuscript.unplaced_lines.atf,
                "references": ApiReferenceSchema().dump(
                    manuscript.references, many=True
                ),
            }
        )
        == manuscript
    )
Ejemplo n.º 2
0
def test_get(client, text_repository):
    chapter = ChapterFactory.build(
        manuscripts=(ManuscriptFactory.build(id=1, references=tuple()), ))
    text_repository.create_chapter(chapter)

    result = client.simulate_get(create_chapter_url(chapter, "/extant_lines"))

    assert result.status == falcon.HTTP_OK
    assert result.json == ExtantLinesSchema().dump(chapter)["extantLines"]
Ejemplo n.º 3
0
def test_get(client, text_repository):
    chapter = ChapterFactory.build(
        lines=tuple(),
        manuscripts=(
            ManuscriptFactory.build(references=tuple()),
            ManuscriptFactory.build(colophon=Text(), references=tuple()),
            ManuscriptFactory.build(references=tuple()),
        ),
    )
    text_repository.create_chapter(chapter)

    result = client.simulate_get(create_chapter_url(chapter, "/colophons"))

    assert result.status == falcon.HTTP_OK
    assert result.json == [{
        "siglum": str(manuscript.siglum),
        "text": TextSchema().dump(manuscript.colophon),
    } for manuscript in chapter.manuscripts
                           if not manuscript.colophon.is_empty]
def create(include_documents: bool) -> Tuple[Chapter, dict]:
    references = (ReferenceFactory.build(with_document=include_documents),)
    manuscript = ManuscriptFactory.build(references=references)

    first_manuscript_line = ManuscriptLineFactory.build(manuscript_id=manuscript.id)
    second_manuscript_line = ManuscriptLineFactory.build(manuscript_id=manuscript.id)
    line = LineFactory.build(
        variants=(
            LineVariantFactory.build(
                manuscripts=(first_manuscript_line, second_manuscript_line),
                parallel_lines=(ParallelComposition(False, "name", LineNumber(1)),),
            ),
        )
    )

    chapter = ChapterFactory.build(
        manuscripts=(manuscript,),
        uncertain_fragments=(MuseumNumber.of("K.1"),),
        lines=(line,),
    )
    dto = {
        "textId": {
            "genre": chapter.text_id.genre.value,
            "category": chapter.text_id.category,
            "index": chapter.text_id.index,
        },
        "classification": chapter.classification.value,
        "stage": chapter.stage.value,
        "version": chapter.version,
        "name": chapter.name,
        "order": chapter.order,
        "signs": list(chapter.signs),
        "record": RecordSchema().dump(chapter.record),
        "parserVersion": chapter.parser_version,
        "manuscripts": ApiManuscriptSchema(
            exclude=[] if include_documents else ["joins"]
        ).dump(chapter.manuscripts, many=True),
        "uncertainFragments": [str(number) for number in chapter.uncertain_fragments],
        "lines": [
            {
                "number": line.number.label,
                "variants": [
                    {
                        "reconstruction": "".join(
                            [
                                convert_to_atf(None, variant.reconstruction),
                                f"\n{variant.note.atf}" if variant.note else "",
                                *[
                                    f"\n{parallel_line.atf}"
                                    for parallel_line in variant.parallel_lines
                                ],
                            ]
                        ),
                        "reconstructionTokens": OneOfTokenSchema().dump(
                            variant.reconstruction, many=True
                        ),
                        "intertext": "".join(part.value for part in variant.intertext),
                        "manuscripts": [
                            {
                                "manuscriptId": manuscript_line.manuscript_id,
                                "labels": [
                                    label.to_value() for label in manuscript_line.labels
                                ],
                                "number": manuscript_line.line.line_number.atf[:-1]
                                if isinstance(manuscript_line.line, TextLine)
                                else "",
                                "atf": "\n".join(
                                    [
                                        manuscript_line.line.atf[
                                            len(manuscript_line.line.line_number.atf)
                                            + 1 :
                                        ]
                                        if isinstance(manuscript_line.line, TextLine)
                                        else "",
                                        *[
                                            line.atf
                                            for line in manuscript_line.paratext
                                        ],
                                    ]
                                ).strip(),
                                "atfTokens": (
                                    OneOfLineSchema().dump(manuscript_line.line)[
                                        "content"
                                    ]
                                ),
                                "omittedWords": list(manuscript_line.omitted_words),
                            }
                            for manuscript_line in variant.manuscripts
                        ],
                    }
                    for variant in line.variants
                ],
                "isSecondLineOfParallelism": line.is_second_line_of_parallelism,
                "isBeginningOfSection": line.is_beginning_of_section,
                "translation": "\n".join(
                    translation.atf for translation in line.translation
                ),
            }
            for line in chapter.lines
        ],
    }

    return chapter, dto
from ebl.transliteration.domain.genre import Genre
from ebl.transliteration.domain.transliteration_query import TransliterationQuery

TEXTS_COLLECTION = "texts"
CHAPTERS_COLLECTION = "chapters"
JOINS_COLLECTION = "joins"
MANUSCRIPT_ID = 1
MUSEUM_NUMBER = MuseumNumber("X", "1")
UNCERTAIN_FRAGMET = MuseumNumber("X", "2")
TEXT = TextFactory.build()
CHAPTER = ChapterFactory.build(
    text_id=TEXT.id,
    stage=TEXT.chapters[0].stage,
    name=TEXT.chapters[0].name,
    manuscripts=(ManuscriptFactory.build(id=1,
                                         museum_number=MUSEUM_NUMBER,
                                         accession="",
                                         references=tuple()), ),
    lines=(LineFactory.build(manuscript_id=1,
                             translation=TEXT.chapters[0].translation), ),
    uncertain_fragments=tuple(),
)


def when_text_in_collection(database, text=TEXT) -> None:
    database[TEXTS_COLLECTION].insert_one(
        TextSchema(exclude=["chapters"]).dump(text))


def when_chapter_in_collection(database, chapter=CHAPTER) -> None:
    database[CHAPTERS_COLLECTION].insert_one(ChapterSchema().dump(chapter))
    Siglum,
)
from ebl.corpus.domain.parser import parse_chapter, parse_paratext
from ebl.errors import DataError
from ebl.tests.factories.corpus import ManuscriptFactory
from ebl.transliteration.domain.labels import parse_labels
from ebl.transliteration.domain.lark_parser import (
    parse_note_line,
    parse_parallel_line,
    parse_text_line,
    parse_translation_line,
)
from ebl.transliteration.domain.line import EmptyLine
from ebl.transliteration.domain.line_number import LineNumber

UNKNOWN_MANUSCRIPT: Manuscript = ManuscriptFactory.build()
MANUSCRIPTS: Sequence[Manuscript] = (
    ManuscriptFactory.build(),
    ManuscriptFactory.build(),
    ManuscriptFactory.build(),
)


def parse_siglum(siglum):
    return parse_chapter(siglum, MANUSCRIPTS, "siglum")


@pytest.mark.parametrize("period", [Period.NEO_ASSYRIAN])
@pytest.mark.parametrize(
    "provenance", [Provenance.URUK, Provenance.UR, Provenance.PERIPHERY])
#  pyre-ignore[56]
)
from ebl.transliteration.application.note_line_part_schemas import (
    OneOfNoteLinePartSchema, )
from ebl.transliteration.application.one_of_line_schema import (
    OneOfLineSchema,
    ParallelLineSchema,
)
from ebl.transliteration.application.text_schema import TextSchema
from ebl.transliteration.application.token_schemas import OneOfTokenSchema
from ebl.transliteration.domain.line_number import LineNumber
from ebl.transliteration.domain.markup import StringPart
from ebl.transliteration.domain.parallel_line import ParallelComposition
from ebl.transliteration.domain.translation_line import TranslationLine

REFERENCES = (ReferenceFactory.build(with_document=True), )
MANUSCRIPT = ManuscriptFactory.build(references=REFERENCES)
UNCERTAIN_FRAGMENTS = (MuseumNumber.of("K.1"), )
FIRST_MANUSCRIPT_LINE = ManuscriptLineFactory.build(
    manuscript_id=MANUSCRIPT.id)
SECOND_MANUSCRIPT_LINE = ManuscriptLineFactory.build(
    manuscript_id=MANUSCRIPT.id)

LINE_VARIANT = LineVariantFactory.build(
    manuscripts=(FIRST_MANUSCRIPT_LINE, SECOND_MANUSCRIPT_LINE),
    parallel_lines=(ParallelComposition(False, "name", LineNumber(2)), ),
    intertext=(StringPart("bar"), ),
)
TRANSLATION_LINE = TranslationLine((StringPart("foo"), ), "en", None)
LINE = LineFactory.build(variants=(LINE_VARIANT, ),
                         translation=(TRANSLATION_LINE, ))
CHAPTER = ChapterFactory.build(manuscripts=(MANUSCRIPT, ),