Exemple #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"),
        ]
    )
Exemple #2
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))),
            ]
        )
Exemple #3
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()),
            ]
        )
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 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"), ),
            ),
        ),
    )
Exemple #6
0
 def ebl_atf_text_line__translation_extent(self, labels,
                                           line_number) -> Extent:
     return Extent(line_number, labels or tuple())
            "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"),),
            "ar",
            Extent(
                LineNumber(1),
                (SurfaceLabel(tuple(), Surface.OBVERSE), ColumnLabel(tuple(), 2)),
            ),
        ),
        {
            "type": "TranslationLine",
            "prefix": "#tr.ar.(o ii 1): ",
            "content": [OneOfTokenSchema().dump(ValueToken.of("foo"))],
            "parts": [{"type": "StringPart", "text": "foo"}],
            "language": "ar",
            "extent": {
                "number": OneOfLineNumberSchema().dump(LineNumber(1)),
                "labels": ["o", "ii"],
            },
        },
    ),
]
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())
            ),
        ),
        (
            "#tr.de.(o iii 1): translation",
            TranslationLine(
                (StringPart("translation"),),
                "de",
                Extent(
                    LineNumber(1),
Exemple #9
0
 def make_extent(self, data, **kwargs) -> Extent:
     return Extent(data["number"], data["labels"])
import pytest

from ebl.lemmatization.domain.lemmatization import LemmatizationToken
from ebl.transliteration.domain.atf import Atf, Surface
from ebl.transliteration.domain.labels import ColumnLabel, SurfaceLabel
from ebl.transliteration.domain.line_number import LineNumber
from ebl.transliteration.domain.markup import StringPart
from ebl.transliteration.domain.translation_line import Extent, TranslationLine


@pytest.mark.parametrize(  # pyre-ignore[56]
    "parts,language,extent,prefix,translation",
    [
        ((StringPart("foo"), StringPart("bar")), "en", None, "#tr.en",
         "foobar"),
        ((StringPart("foo"), ), "de", Extent(
            LineNumber(1)), "#tr.de.(1)", "foo"),
        (
            (StringPart("foo"), ),
            "de",
            Extent(
                LineNumber(1),
                (SurfaceLabel(tuple(), Surface.OBVERSE), ColumnLabel(
                    tuple(), 2)),
            ),
            "#tr.de.(o ii 1)",
            "foo",
        ),
    ],
)
def test_parallel_fragment(parts, language, extent, prefix,
                           translation) -> None: