示例#1
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))),
            ]
        )
示例#2
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"),
        ]
    )
示例#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()),
            ]
        )
示例#4
0
def test_parse_ruling_dollar_line(prefix, ruling, expected_ruling, status,
                                  expected_status, status_space, parenthesis):
    ruling = f"{ruling} ruling"
    ruling_with_status = (f"{ruling} {status}" if
                          (status and status_space) else f"{ruling}{status}")
    line = f"({ruling_with_status})" if parenthesis else ruling_with_status
    assert (parse_atf_lark(f"{prefix}{line}").lines == Text.of_iterable(
        [RulingDollarLine(expected_ruling, expected_status)]).lines)
def text_with_labels():
    return Text.of_iterable([
        TextLine.of_iterable(LineNumber(1),
                             [Word.of([Reading.of_name("bu")])]),
        ColumnAtLine(ColumnLabel.from_int(1)),
        SurfaceAtLine(SurfaceLabel([], atf.Surface.SURFACE, "Stone wig")),
        ObjectAtLine(ObjectLabel([], atf.Object.OBJECT, "Stone wig")),
        TextLine.of_iterable(LineNumber(2),
                             [Word.of([Reading.of_name("bu")])]),
    ])
示例#6
0
def test_load_line(lines):
    parser_version = "2.3.1"
    serialized_lines = OneOfLineSchema().dump(lines, many=True)
    assert TextSchema().load(
        {
            "lines": serialized_lines,
            "parser_version": parser_version,
            "numberOfLines": 1,
        }
    ) == Text.of_iterable(lines).set_parser_version(parser_version)
示例#7
0
def test_query_lemmas_ignores_in_value(parts, expected, fragment_repository,
                                       lemma_repository):
    fragment = FragmentFactory.build(
        text=Text.of_iterable([
            TextLine.of_iterable(
                LineNumber(1),
                [Word.of(parts, unique_lemma=(WordId("ana I"), ))])
        ]),
        signs="DIŠ",
    )
    fragment_repository.create(fragment)

    assert lemma_repository.query_lemmas("ana", False) == expected
def test_updating_manuscripts(corpus, text_repository, bibliography, changelog,
                              signs, sign_repository, user, when) -> None:
    uncertain_fragments = (MuseumNumber.of("K.1"), )
    updated_chapter = attr.evolve(
        CHAPTER,
        manuscripts=(attr.evolve(
            CHAPTER.manuscripts[0],
            colophon=Transliteration.of_iterable([
                TextLine.of_iterable(LineNumber(1, True),
                                     (Word.of([Reading.of_name("ba")]), ))
            ]),
            unplaced_lines=Transliteration.of_iterable([
                TextLine.of_iterable(LineNumber(1, True),
                                     (Word.of([Reading.of_name("ku")]), ))
            ]),
            notes="Updated manuscript.",
        ), ),
        uncertain_fragments=uncertain_fragments,
        signs=("KU ABZ075 ABZ207a\\u002F207b\\u0020X\nBA\nKU", ),
    )
    expect_find_and_update_chapter(
        bibliography,
        changelog,
        CHAPTER_WITHOUT_DOCUMENTS,
        updated_chapter,
        signs,
        sign_repository,
        text_repository,
        user,
        when,
    )

    manuscripts = (updated_chapter.manuscripts[0], )
    assert (corpus.update_manuscripts(CHAPTER.id_, manuscripts,
                                      uncertain_fragments,
                                      user) == updated_chapter)
class ManuscriptFactory(factory.Factory):
    class Meta:
        model = Manuscript

    id = factory.Sequence(lambda n: n + 1)
    siglum_disambiguator = factory.Faker("word")
    museum_number = factory.Sequence(
        lambda n: MuseumNumber("M", str(n)) if pydash.is_odd(n) else None
    )
    accession = factory.Sequence(lambda n: f"A.{n}" if pydash.is_even(n) else "")
    period_modifier = factory.fuzzy.FuzzyChoice(PeriodModifier)
    period = factory.fuzzy.FuzzyChoice(set(Period) - {Period.NONE})
    provenance = factory.fuzzy.FuzzyChoice(set(Provenance) - {Provenance.STANDARD_TEXT})
    type = factory.fuzzy.FuzzyChoice(set(ManuscriptType) - {ManuscriptType.NONE})
    notes = factory.Faker("sentence")
    colophon = Transliteration.of_iterable(
        [TextLine.of_iterable(LineNumber(1, True), (Word.of([Reading.of_name("ku")]),))]
    )
    unplaced_lines = Transliteration.of_iterable(
        [TextLine.of_iterable(LineNumber(1, True), (Word.of([Reading.of_name("nu")]),))]
    )
    references = factory.List(
        [factory.SubFactory(ReferenceFactory, with_document=True)], TupleFactory
    )
def test_parse_dividers() -> None:
    line, expected_tokens = (
        r'1. :? :#! :# ::? :.@v /@19* :"@20@c ;@v@19!',
        [
            TextLine.of_iterable(
                LineNumber(1),
                (
                    Divider.of(":", tuple(), (atf.Flag.UNCERTAIN, )),
                    Divider.of(":", tuple(),
                               (atf.Flag.DAMAGE, atf.Flag.CORRECTION)),
                    Divider.of(":", tuple(), (atf.Flag.DAMAGE, )),
                    Divider.of("::", tuple(), (atf.Flag.UNCERTAIN, )),
                    Divider.of(":.", ("@v", ), tuple()),
                    Divider.of("/", ("@19", ), (atf.Flag.COLLATION, )),
                    Divider.of(':"', ("@20", "@c"), tuple()),
                    Divider.of(";", ("@v", "@19"), (atf.Flag.CORRECTION, )),
                ),
            )
        ],
    )
    assert parse_atf_lark(line).lines == Text.of_iterable(
        expected_tokens).lines
示例#11
0
def test_combinations(
    qualification,
    extent,
    scope,
    state,
    status,
    expected_qualification,
    expected_extent,
    expected_scope,
    expected_state,
    expected_status,
):
    line = " ".join(["$", qualification, extent, scope, state, status])
    expected_line = StateDollarLine(
        expected_qualification,
        expected_extent,
        expected_scope,
        expected_state,
        expected_status,
    )
    assert parse_atf_lark(line).lines == Text.of_iterable([expected_line
                                                           ]).lines
示例#12
0
def test_parse_atf_at_line(line, expected_tokens):
    assert parse_atf_lark(line).lines == Text.of_iterable(
        expected_tokens).lines
def test_parse_image_dollar_line(line, expected_line):
    assert parse_atf_lark(line).lines == Text.of_iterable([expected_line
                                                           ]).lines
APPROXIMATE = True
CLASSIFICATION = Classification.ANCIENT
STAGE = Stage.NEO_BABYLONIAN
VERSION = "A"
CHAPTER_NAME = "IIc"
ORDER = 1
MANUSCRIPT_ID = 9001
SIGLUM_DISAMBIGUATOR = "1c"
MUSEUM_NUMBER = MuseumNumber("BM", "x")
ACCESSION = ""
PERIOD_MODIFIER = PeriodModifier.LATE
PERIOD = Period.OLD_BABYLONIAN
PROVENANCE = Provenance.NINEVEH
TYPE = ManuscriptType.LIBRARY
NOTES = "some notes"
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", )
示例#15
0
def test_translation_berofe_text() -> None:
    with pytest.raises(ValueError):
        Text.of_iterable([TranslationLine(tuple()), *LINES])
示例#16
0
def test_extent(extent, expected_extent):
    line = f"$ {extent}"
    expected_line = StateDollarLine(None, expected_extent, None, None, None)
    assert parse_atf_lark(line).lines == Text.of_iterable([expected_line
                                                           ]).lines
示例#17
0
def test_scope(scope, expected_scope):
    line = f"$ {scope}"
    expected_line = StateDollarLine(None, None, expected_scope, None, None)
    assert parse_atf_lark(line).lines == Text.of_iterable([expected_line
                                                           ]).lines
示例#18
0
def test_qualification(qualification, expected_qualification):
    line = f"$ {qualification}"
    expected_line = StateDollarLine(expected_qualification, None, None, None,
                                    None)
    assert parse_atf_lark(line).lines == Text.of_iterable([expected_line
                                                           ]).lines
示例#19
0
from ebl.transliteration.domain.text_line import TextLine
from ebl.transliteration.domain.tokens import Joiner, ValueToken, Variant
from ebl.transliteration.domain.word_tokens import Word


@pytest.mark.parametrize(  # pyre-ignore[56]
    "old,new,expected",
    [
        (
            Text.of_iterable([
                TextLine.of_iterable(
                    LineNumber(1),
                    [
                        Word.of([
                            Reading.of_name("ha"),
                            Joiner.hyphen(),
                            Reading.of_name("am"),
                        ])
                    ],
                ),
                ControlLine("#", " comment"),
            ]),
            Text.of_iterable([
                TextLine.of_iterable(
                    LineNumber(1),
                    [
                        Word.of([
                            Reading.of_name("ha"),
                            Joiner.hyphen(),
                            Reading.of_name("am"),
                        ])
def test_parse_state_dollar_line_surface_ambiguity(line, expected_line):
    assert parse_atf_lark(line).lines == Text.of_iterable([expected_line
                                                           ]).lines
示例#21
0
def test_of_iterable() -> None:
    assert Text.of_iterable(LINES) == Text(LINES, atf.ATF_PARSER_VERSION)
def test_parse_text_line(line: str, expected_tokens: List[Line]) -> None:
    assert parse_atf_lark(line).lines == Text.of_iterable(
        expected_tokens).lines
def test_parse_state_dollar_line(prefix, parenthesis, line, expected_line):
    atf_ = f"{prefix}({line})" if parenthesis else f"{prefix}{line}"
    assert parse_atf_lark(atf_).lines == Text.of_iterable([expected_line
                                                           ]).lines
示例#24
0
def test_status(status, expected_status):
    line = f"$ {status}"
    expected_line = StateDollarLine(None, None, None, None, expected_status)
    assert parse_atf_lark(line).lines == Text.of_iterable([expected_line
                                                           ]).lines
def test_parse_note_line() -> None:
    markup = "this is a note @i{italic text}@akk{kur}@sux{kur}"
    atf = f"#note: {markup}"
    expected_line = NoteLine(parse_markup(markup))
    assert parse_atf_lark(atf).lines == Text.of_iterable([expected_line]).lines
def test_egpytian_feet_metrical_feet_line(line: str,
                                          expected_tokens: List[Line]) -> None:
    assert parse_atf_lark(line).lines == Text.of_iterable(
        expected_tokens).lines