예제 #1
0
def test_extent_overlapping_languages() -> None:
    Text.of_iterable(
        [
            TextLine.of_iterable(LineNumber(1), [Word.of([Reading.of_name("bu")])]),
            TranslationLine(tuple(), "en", Extent(LineNumber(2))),
            TextLine.of_iterable(LineNumber(2), [Word.of([Reading.of_name("bu")])]),
            TranslationLine(tuple(), "de"),
        ]
    )
예제 #2
0
def test_exent_overlapping() -> None:
    with pytest.raises(ValueError):
        Text.of_iterable(
            [
                TextLine.of_iterable(LineNumber(1), [Word.of([Reading.of_name("bu")])]),
                TranslationLine(tuple(), extent=Extent(LineNumber(2))),
                TextLine.of_iterable(LineNumber(2), [Word.of([Reading.of_name("bu")])]),
                TranslationLine(tuple()),
            ]
        )
class ChapterListingFactory(factory.Factory):
    class Meta:
        model = ChapterListing

    stage = factory.fuzzy.FuzzyChoice(Stage)
    name = factory.Faker("sentence")
    translation = (TranslationLine((StringPart("foo"),), "en", None),)
    uncertain_fragments = tuple()
예제 #4
0
def test_extent_before_translation() -> None:
    with pytest.raises(ValueError):
        Text.of_iterable(
            [
                TextLine.of_iterable(LineNumber(1), [Word.of([Reading.of_name("bu")])]),
                TextLine.of_iterable(LineNumber(2), [Word.of([Reading.of_name("bu")])]),
                TranslationLine(tuple(), "en", Extent(LineNumber(1))),
            ]
        )
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_parallel_fragment(parts, language, extent, prefix,
                           translation) -> None:
    line = TranslationLine(parts, language, extent)

    assert line.parts == parts
    assert line.language == language
    assert line.extent == extent
    assert line.translation == translation
    assert line.atf == Atf(f"{prefix}: {translation}")
    assert line.lemmatization == (LemmatizationToken(translation), )
예제 #7
0
def test_line_display_of_line() -> None:
    translation_lines = (
        TranslationLine((StringPart("bar"),), "de", None),
        TranslationLine((StringPart("foo"),), DEFAULT_LANGUAGE, None),
    )
    line = LineFactory.build(translation=translation_lines)

    line_display = LineDisplay.of_line(line)

    assert line_display == LineDisplay(
        line.number,
        line.is_second_line_of_parallelism,
        line.is_beginning_of_section,
        line.variants[0].intertext,
        line.variants[0].reconstruction,
        translation_lines,
        line.variants[0].note,
        line.variants[0].parallel_lines,
    )
    assert line_display.title == make_title(translation_lines)
def test_overlapping() -> 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))), ),
                ),
                Line(
                    LineNumber(2),
                    (LINE_VARIANT_2, ),
                    translation=(TranslationLine(tuple()), ),
                ),
            ),
        )
class LineFactory(factory.Factory):
    class Meta:
        model = Line

    class Params:
        manuscript_id = factory.Sequence(lambda n: n)
        variant = factory.SubFactory(
            LineVariantFactory, manuscript_id=factory.SelfAttribute("..manuscript_id")
        )

    number = factory.Sequence(lambda n: LineNumber(n))
    variants = factory.List([factory.SelfAttribute("..variant")], TupleFactory)
    is_second_line_of_parallelism = factory.Faker("boolean")
    is_beginning_of_section = factory.Faker("boolean")
    translation = (TranslationLine((StringPart("foo"),), "en", None),)
예제 #10
0
def test_translation_berofe_text() -> None:
    with pytest.raises(ValueError):
        Text.of_iterable([TranslationLine(tuple()), *LINES])
예제 #11
0
 def translation_line(self, language, extent,
                      *markup: MarkupPart) -> TranslationLine:
     return TranslationLine(tuple(markup),
                            language.value if language else "en", extent)
COLOPHON = Transliteration.of_iterable(
    [TextLine(LineNumber(1, True), (Word.of([Reading.of_name("ku")]), ))])
UNPLACED_LINES = Transliteration.of_iterable(
    [TextLine(LineNumber(4, True), (Word.of([Reading.of_name("bu")]), ))])
REFERENCES = (ReferenceFactory.build(), )
LINE_NUMBER = LineNumber(1)
LINE_RECONSTRUCTION = (AkkadianWord.of((ValueToken.of("buāru"), )), )
IS_SECOND_LINE_OF_PARALLELISM = True
IS_BEGINNING_OF_SECTION = True
LABELS = (SurfaceLabel.from_label(Surface.OBVERSE), )
PARATEXT = (NoteLine((StringPart("note"), )), RulingDollarLine(Ruling.SINGLE))
OMITTED_WORDS = (1, )

NOTE = None
PARALLEL_LINES = (ParallelComposition(False, "a composition", LineNumber(7)), )
TRANSLATION = (TranslationLine((StringPart("foo"), ), "en", None), )
SIGNS = ("FOO BAR", )

MANUSCRIPT_TEXT_1 = TextLine(LineNumber(1),
                             (Word.of([Reading.of([ValueToken.of("ku")])]), ))

LINE_VARIANT_1 = LineVariant(
    LINE_RECONSTRUCTION,
    NOTE,
    (ManuscriptLine(MANUSCRIPT_ID, LABELS, MANUSCRIPT_TEXT_1, PARATEXT,
                    OMITTED_WORDS), ),
    PARALLEL_LINES,
)
LINE_1 = Line(
    LINE_NUMBER,
    (LINE_VARIANT_1, ),
예제 #13
0
from ebl.transliteration.domain.markup import StringPart
from ebl.transliteration.domain.translation_line import TranslationLine

GENRE = Genre.LITERATURE
CATEGORY = 1
INDEX = 2
NAME = "Palm & Vine"
HAS_DOI = True
VERSES = 100
APPROXIMATE = True
CLASSIFICATION = Classification.ANCIENT
STAGE = Stage.NEO_BABYLONIAN
INTRO = "**Intro**"
CHAPTER_NAME = "I"
TRANSLATION = (
    TranslationLine([StringPart("not the title")], "de"),
    TranslationLine([StringPart("the title,")], "en"),
)
UNCERTAIN_FRAGMENTS = (UncertainFragment(MuseumNumber("X", "1"), True), )
CHAPTER = ChapterListing(STAGE, CHAPTER_NAME, TRANSLATION, UNCERTAIN_FRAGMENTS)

TEXT = Text(GENRE, CATEGORY, INDEX, NAME, HAS_DOI, VERSES, APPROXIMATE, INTRO,
            (CHAPTER, ))


def test_text_constructor_sets_correct_fields() -> None:
    assert TEXT.id == TextId(GENRE, CATEGORY, INDEX)
    assert TEXT.genre == GENRE
    assert TEXT.category == CATEGORY
    assert TEXT.index == INDEX
    assert TEXT.name == NAME
     },
 ),
 (
     ParallelComposition(True, "name", LineNumber(1)),
     {
         "type": "ParallelComposition",
         "prefix": "//",
         "content": [OneOfTokenSchema().dump(ValueToken.of("cf. (name 1)"))],
         "displayValue": "cf. (name 1)",
         "hasCf": True,
         "name": "name",
         "lineNumber": OneOfLineNumberSchema().dump(LineNumber(1)),
     },
 ),
 (
     TranslationLine((StringPart("foo"), EmphasisPart("bar")), "en", None),
     {
         "type": "TranslationLine",
         "prefix": "#tr.en: ",
         "content": [OneOfTokenSchema().dump(ValueToken.of("foo@i{bar}"))],
         "parts": [
             {"type": "StringPart", "text": "foo"},
             {"type": "EmphasisPart", "text": "bar"},
         ],
         "language": "en",
         "extent": None,
     },
 ),
 (
     TranslationLine(
         (StringPart("foo"),),
import pytest

from ebl.transliteration.domain.lark_parser import parse_translation_line
from ebl.transliteration.domain.markup import StringPart
from ebl.transliteration.domain.translation_line import Extent, TranslationLine
from ebl.transliteration.domain.labels import ColumnLabel, SurfaceLabel
from ebl.transliteration.domain.line_number import LineNumber
from ebl.transliteration.domain.atf import Surface


@pytest.mark.parametrize(
    "atf,expected_line",
    [
        ("#tr: translation", TranslationLine((StringPart("translation"),), "en", None)),
        (
            "#tr.en: translation",
            TranslationLine((StringPart("translation"),), "en", None),
        ),
        (
            "#tr.ar.(2): translation",
            TranslationLine(
                (StringPart("translation"),), "ar", Extent(LineNumber(2), tuple())
            ),
        ),
        (
            "#tr.(2): translation",
            TranslationLine(
                (StringPart("translation"),), "en", Extent(LineNumber(2), tuple())
            ),
        ),
        (
예제 #16
0
 def make_line(self, data, **kwargs) -> TranslationLine:
     return TranslationLine(data["parts"], data["language"], data["extent"])