class ChapterSchema(Schema):
    text_id = fields.Nested(TextIdSchema, required=True, data_key="textId")
    classification = ValueEnum(Classification, required=True)
    stage = ValueEnum(Stage, required=True)
    version = fields.String(required=True)
    name = fields.String(required=True, validate=validate.Length(min=1))
    order = fields.Integer(required=True)
    manuscripts = fields.Nested(ManuscriptSchema, many=True, required=True)
    uncertain_fragments: fields.Field = fields.Nested(
        MuseumNumberSchema,
        many=True,
        load_default=tuple(),
        data_key="uncertainFragments",
    )
    lines = fields.Nested(LineSchema, many=True, required=True)
    signs = fields.List(fields.String(), load_default=tuple())
    record = fields.Nested(RecordSchema, load_default=Record())
    parser_version = fields.String(load_default="", data_key="parserVersion")

    @post_load
    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"],
        )
class TextSchema(Schema):
    genre = ValueEnum(Genre, load_default=Genre.LITERATURE)
    category = fields.Integer(required=True, validate=validate.Range(min=0))
    index = fields.Integer(required=True, validate=validate.Range(min=0))
    name = fields.String(required=True, validate=validate.Length(min=1))
    has_doi = fields.Boolean(load_default=False, data_key="hasDoi")
    number_of_verses = fields.Integer(required=True,
                                      data_key="numberOfVerses",
                                      validate=validate.Range(min=0))
    approximate_verses = fields.Boolean(required=True,
                                        data_key="approximateVerses")
    intro = fields.String(load_default="")
    chapters = fields.Nested(ChapterListingSchema, many=True, required=True)
    references = fields.Nested(ReferenceSchema,
                               many=True,
                               load_default=tuple())

    @post_load
    def make_text(self, data: dict, **kwargs) -> Text:
        return Text(
            data["genre"],
            data["category"],
            data["index"],
            data["name"],
            data["has_doi"],
            data["number_of_verses"],
            data["approximate_verses"],
            data["intro"],
            tuple(data["chapters"]),
            tuple(data["references"]),
        )
Beispiel #3
0
class JoinerSchema(BaseTokenSchema):
    enum_value = ValueEnum(atf.Joiner, required=True, data_key="value", load_only=True)

    @post_load
    def make_token(self, data, **kwargs):
        return Joiner(
            frozenset(data["enclosure_type"]), data["erasure"], data["enum_value"]
        )
class TextIdSchema(Schema):
    genre = ValueEnum(Genre, load_default=Genre.LITERATURE)
    category = fields.Integer(required=True, validate=validate.Range(min=0))
    index = fields.Integer(required=True, validate=validate.Range(min=0))

    @post_load
    def make_id(self, data, **kwargs) -> TextId:
        return TextId(data["genre"], data["category"], data["index"])
Beispiel #5
0
class ChapterNameSchema(Schema):
    stage = ValueEnum(Stage, required=True)
    version = fields.String(required=True)
    name = fields.String(required=True, validate=validate.Length(min=1))

    @post_load
    def make_id(self, data, **kwargs) -> ChapterName:
        return ChapterName(data["stage"], data["version"], data["name"])
class ChapterIdSchema(Schema):
    text_id = fields.Nested(TextIdSchema, required=True, data_key="textId")
    stage = ValueEnum(Stage, required=True)
    name = fields.String(required=True, validate=validate.Length(min=1))

    @post_load
    def make_id(self, data, **kwargs) -> ChapterId:
        return ChapterId(data["text_id"], data["stage"], data["name"])
class RecordEntrySchema(Schema):
    user = fields.String(required=True)
    type = ValueEnum(RecordType, required=True)
    date = fields.String(required=True)

    @post_load
    def make_record_entry(self, data, **kwargs):
        return RecordEntry(**data)
Beispiel #8
0
class NamedSignSchema(BaseTokenSchema):
    name = fields.String(required=True)
    name_parts = fields.List(
        fields.Nested(lambda: OneOfTokenSchema()), required=True, data_key="nameParts"
    )
    sub_index = fields.Integer(data_key="subIndex", allow_none=True)
    modifiers = fields.List(fields.String(), required=True)
    flags = fields.List(ValueEnum(Flag), required=True)
    sign = fields.Nested(lambda: OneOfTokenSchema(), allow_none=True)
Beispiel #9
0
class UnclearSignSchema(BaseTokenSchema):
    flags = fields.List(ValueEnum(Flag), required=True)

    @post_load
    def make_token(self, data, **kwargs):
        return (
            UnclearSign.of(tuple(data["flags"]))
            .set_enclosure_type(frozenset(data["enclosure_type"]))
            .set_erasure(data["erasure"])
        )
Beispiel #10
0
class EgyptianMetricalFeetSeparatorSchema(BaseTokenSchema):
    flags = fields.List(ValueEnum(Flag), required=True)

    @post_load
    def make_token(self, data, **kwargs):
        return (
            EgyptianMetricalFeetSeparator.of(tuple(data["flags"]))
            .set_enclosure_type(frozenset(data["enclosure_type"]))
            .set_erasure(data["erasure"])
        )
Beispiel #11
0
class AnnotationDataSchema(Schema):
    id = fields.String(required=True)
    type = ValueEnum(AnnotationValueType,
                     load_default=AnnotationValueType.HAS_SIGN)
    sign_name = fields.String(load_default="", data_key="signName")
    value = fields.String(required=True)
    path = fields.List(fields.Int, required=True)

    @post_load
    def make_data(self, data, **kwargs):
        return AnnotationData(**data)
Beispiel #12
0
class GreekLetterSchema(BaseTokenSchema):
    letter = fields.String(required=True, validate=validate.Length(1, 1))
    flags = fields.List(ValueEnum(Flag), required=True)

    @post_load
    def make_token(self, data, **kwargs):
        return GreekLetter(
            frozenset(data["enclosure_type"]),
            data["erasure"],
            data["letter"],
            data["flags"],
        )
Beispiel #13
0
class AkkadianWordSchema(BaseWordSchema):
    modifiers = fields.List(ValueEnum(Flag), required=True)

    @post_load
    def make_token(self, data, **kwargs):
        return AkkadianWord.of(
            tuple(data["parts"]),
            tuple(data["modifiers"]),
            tuple(data["unique_lemma"]),
            data["alignment"],
            data["variant"],
        ).set_enclosure_type(frozenset(data["enclosure_type"]))
Beispiel #14
0
class GraphemeSchema(BaseTokenSchema):
    name = fields.String(required=True)
    modifiers = fields.List(fields.String(), required=True)
    flags = fields.List(ValueEnum(Flag), required=True)

    @post_load
    def make_token(self, data, **kwargs):
        return (
            Grapheme.of(data["name"], data["modifiers"], data["flags"])
            .set_enclosure_type(frozenset(data["enclosure_type"]))
            .set_erasure(data["erasure"])
        )
Beispiel #15
0
class DividerSchema(BaseTokenSchema):
    divider = fields.String(required=True)
    modifiers = fields.List(fields.String(), required=True)
    flags = fields.List(ValueEnum(Flag), required=True)

    @post_load
    def make_token(self, data, **kwargs):
        return (
            Divider.of(data["divider"], tuple(data["modifiers"]), tuple(data["flags"]))
            .set_enclosure_type(frozenset(data["enclosure_type"]))
            .set_erasure(data["erasure"])
        )
class FragmentSchema(Schema):
    number = fields.Nested(MuseumNumberSchema,
                           required=True,
                           data_key="museumNumber")
    accession = fields.String(required=True)
    cdli_number = fields.String(required=True, data_key="cdliNumber")
    bm_id_number = fields.String(required=True, data_key="bmIdNumber")
    publication = fields.String(required=True)
    description = fields.String(required=True)
    collection = fields.String(required=True)
    script = fields.String(required=True)
    museum = fields.String(required=True)
    width = fields.Nested(MeasureSchema, required=True)
    length = fields.Nested(MeasureSchema, required=True)
    thickness = fields.Nested(MeasureSchema, required=True)
    joins = fields.Pluck(JoinsSchema, "fragments", load_default=Joins())
    record = fields.Pluck(RecordSchema, "entries")
    folios = fields.Pluck(FoliosSchema, "entries")
    text = fields.Nested(TextSchema)
    signs = fields.String(load_default="")
    notes = fields.String(required=True)
    references = fields.Nested(ReferenceSchema, many=True, required=True)
    uncurated_references = fields.Nested(
        UncuratedReferenceSchema,
        many=True,
        data_key="uncuratedReferences",
        load_default=None,
    )
    genres = fields.Nested(GenreSchema, many=True, load_default=tuple())
    line_to_vec = fields.List(
        fields.List(ValueEnum(LineToVecEncoding)),
        load_default=tuple(),
        data_key="lineToVec",
    )

    @post_load
    def make_fragment(self, data, **kwargs):
        data["references"] = tuple(data["references"])
        data["genres"] = tuple(data["genres"])
        data["line_to_vec"] = tuple(map(tuple, data["line_to_vec"]))
        if data["uncurated_references"] is not None:
            data["uncurated_references"] = tuple(data["uncurated_references"])
        return Fragment(**data)

    @post_dump
    def filter_none(self, data, **kwargs):
        return pydash.omit_by(data, pydash.is_none)
class ChapterListingSchema(Schema):
    stage = ValueEnum(Stage, required=True)
    name = fields.String(required=True, validate=validate.Length(min=1))
    translation = fields.Nested(TranslationLineSchema,
                                many=True,
                                load_default=tuple())
    uncertain_fragments = fields.Nested(
        UncertainFragmentSchema,
        many=True,
        load_default=tuple(),
        data_key="uncertainFragments",
    )

    @post_load
    def make_chapter_listing(self, data: dict, **kwargs) -> ChapterListing:
        return ChapterListing(
            Stage(data["stage"]),
            data["name"],
            tuple(data["translation"]),
            tuple(data["uncertain_fragments"]),
        )
Beispiel #18
0
class _TestSchemaStr(Schema):
    value = ValueEnum(_TestEnumStr, required=True, allow_none=True)
    name = NameEnum(_TestEnumStr, required=True, allow_none=True)
class ManuscriptSchema(Schema):
    id = fields.Integer(required=True)
    siglum_disambiguator = fields.String(required=True,
                                         data_key="siglumDisambiguator")
    museum_number: fields.Field = fields.Nested(MuseumNumberSchema,
                                                required=True,
                                                allow_none=True,
                                                data_key="museumNumber")
    accession = fields.String(required=True)
    period_modifier = ValueEnum(PeriodModifier,
                                required=True,
                                data_key="periodModifier")
    period = fields.Function(
        lambda manuscript: manuscript.period.long_name,
        lambda value: Period.from_name(value),
        required=True,
    )
    provenance = fields.Function(
        lambda manuscript: manuscript.provenance.long_name,
        lambda value: Provenance.from_name(value),
        required=True,
    )
    type = fields.Function(
        lambda manuscript: manuscript.type.long_name,
        lambda value: ManuscriptType.from_name(value),
        required=True,
    )
    notes = fields.String(required=True)
    colophon: fields.Field = fields.Nested(TransliterationSchema,
                                           load_default=Transliteration())
    unplaced_lines: fields.Field = fields.Nested(
        TransliterationSchema,
        load_default=Transliteration(),
        data_key="unplacedLines")
    references = fields.Nested(ReferenceSchema, many=True, required=True)
    joins = fields.Pluck(JoinsSchema,
                         "fragments",
                         load_default=Joins(),
                         load_only=True)
    is_in_fragmentarium = fields.Boolean(load_default=False,
                                         data_key="isInFragmentarium",
                                         load_only=True)

    @validates_schema
    def validate_provenance(self, data, **kwargs):
        provenace = data["provenance"]
        period = data["period"]
        type_ = data["type"]
        if is_invalid_standard_text(provenace, period, type_):
            raise ValidationError(
                "period and type must be None if provenance is Standard Text")
        elif is_invalid_non_standard_text(provenace, period, type_):
            raise ValidationError(
                "period and type must not be None if provenance is not Standard Text"
            )

    @post_load
    def make_manuscript(self, data: dict, **kwargs) -> Manuscript:
        return Manuscript(
            data["id"],
            data["siglum_disambiguator"],
            data["museum_number"],
            data["accession"],
            data["period_modifier"],
            data["period"],
            data["provenance"],
            data["type"],
            data["notes"],
            data["colophon"],
            data["unplaced_lines"],
            tuple(data["references"]),
            data["joins"],
            data["is_in_fragmentarium"],
        )
Beispiel #20
0
class _TestSchemaInt(Schema):
    value = ValueEnum(_TestEnumInt, required=True, allow_none=True)
    name = NameEnum(_TestEnumInt, required=True, allow_none=True)