class RulingDollarLineSchema(DollarLineSchema): number = NameEnum(atf.Ruling, required=True) status = NameEnum(atf.DollarStatus, load_default=None) display_value = fields.String(data_key="displayValue") @post_load def make_line(self, data, **kwargs) -> RulingDollarLine: return RulingDollarLine(data["number"], data["status"])
class ObjectAtLineSchema(AtLineSchema): status = fields.List(NameEnum(atf.Status), load_only=True) object_label = NameEnum(atf.Object, load_only=True) text = fields.String(dump_default="", load_only=True) label = fields.Nested(ObjectLabelSchema) display_value = fields.String(data_key="displayValue") @post_load def make_line(self, data, **kwargs) -> ObjectAtLine: return ObjectAtLine(data["label"])
class BaseTokenSchema(Schema): class Meta: unknown = EXCLUDE value = fields.String(required=True) clean_value = fields.String(data_key="cleanValue") enclosure_type = fields.List( NameEnum(EnclosureType), load_default=list, data_key="enclosureType" ) erasure = NameEnum(ErasureState, load_default=ErasureState.NONE)
class ObjectLabelSchema(LabelSchema): object = NameEnum(atf.Object, required=True) text = fields.String(dump_default="") @post_load def make_label(self, data, **kwargs) -> ObjectLabel: return ObjectLabel(data["status"], data["object"], data["text"])
class SurfaceLabelSchema(LabelSchema): surface = NameEnum(atf.Surface, required=True) text = fields.String(dump_default="") @post_load def make_label(self, data, **kwargs) -> SurfaceLabel: return SurfaceLabel(data["status"], data["surface"], data["text"])
class ParallelTextSchema(ParallelLineSchema): genre = NameEnum(Genre, load_only=True) text = fields.Nested(TextIdSchema, required=True) chapter = fields.Nested(ChapterNameSchema, required=True, allow_none=True) line_number = fields.Nested( OneOfLineNumberSchema, required=True, data_key="lineNumber" ) exists = exists() implicit_chapter = fields.Nested( ChapterNameSchema, load_default=None, allow_none=True, data_key="implicitChapter", ) @post_load def make_line(self, data, **kwargs) -> ParallelText: return ParallelText( data["has_cf"], data["text"], data["chapter"], data["line_number"], data["exists"], data["implicit_chapter"], )
class DiscourseAtLineSchema(AtLineSchema): discourse_label = NameEnum(atf.Discourse, required=True) display_value = fields.String(data_key="displayValue") @post_load def make_line(self, data, **kwargs) -> DiscourseAtLine: return DiscourseAtLine(data["discourse_label"])
class EnclosureSchema(BaseTokenSchema): side = NameEnum(Side, required=True) @abstractmethod @post_load def make_token(self, data, **kwargs) -> Token: ...
class LanguagePartSchema(Schema): language = NameEnum(Language, required=True) tokens = fields.Nested(OneOfTokenSchema, many=True, load_default=None) @post_load def make_part(self, data, **kwargs) -> LanguagePart: return LanguagePart.of_transliteration(data["language"], data["tokens"])
class CompositeAtLineSchema(AtLineSchema): composite = NameEnum(atf.Composite, required=True) text = fields.String(required=True) number = fields.Int(required=False, allow_none=True, dump_default=None) display_value = fields.String(data_key="displayValue") @post_load def make_line(self, data, **kwargs) -> CompositeAtLine: return CompositeAtLine(data["composite"], data["text"], data["number"])
class LanguageShiftSchema(BaseTokenSchema): language = NameEnum(Language, required=True) normalized = fields.Boolean(required=True) @post_load def make_token(self, data, **kwargs): return LanguageShift( frozenset(data["enclosure_type"]), data["erasure"], data["value"] )
class AuthorSchema(Schema): name = fields.String(required=True) prefix = fields.String(required=True) role = NameEnum(AuthorRole, required=True) orcid_number = fields.String(required=True, data_key="orcidNumber") @post_load def make_author(self, data: dict, **kwargs) -> Author: return Author(data["name"], data["prefix"], data["role"], data["orcid_number"])
class BaseWordSchema(BaseTokenSchema): parts = fields.List(fields.Nested(lambda: OneOfTokenSchema()), required=True) language = NameEnum(Language, required=True) normalized = fields.Boolean(required=True) lemmatizable = fields.Boolean(required=True) alignable = fields.Boolean() unique_lemma = fields.List(fields.String(), data_key="uniqueLemma", required=True) alignment = fields.Integer(allow_none=True, load_default=None) variant = fields.Nested( lambda: OneOfWordSchema(), allow_none=True, load_default=None )
class StateDollarLineSchema(DollarLineSchema): qualification = NameEnum(atf.Qualification, required=True, allow_none=True) extent = fields.Function( lambda strict: StateDollarLineSchema.dump_extent(strict.extent), lambda value: value, required=True, allow_none=True, ) scope = fields.Nested(ScopeContainerSchema, required=True, allow_none=True) state = NameEnum(atf.State, required=True, allow_none=True) status = NameEnum(atf.DollarStatus, required=True, allow_none=True) display_value = fields.String(data_key="displayValue") @post_load def make_line(self, data, **kwargs) -> StateDollarLine: return StateDollarLine( data["qualification"], StateDollarLineSchema.load_extent(data["extent"]), data["scope"], data["state"], data["status"], ) @staticmethod def load_extent(extent): if isinstance(extent, str): return atf.Extent[extent] elif isinstance(extent, list): return tuple(extent) else: return extent @staticmethod def dump_extent(extent): if isinstance(extent, atf.Extent): return extent.name elif isinstance(extent, tuple): return list(extent) else: return extent
class ReferenceSchema(Schema): id = fields.String(required=True) type = NameEnum(ReferenceType, required=True) pages = fields.String(required=True) notes = fields.String(required=True) lines_cited = fields.List(fields.String(), required=True, data_key="linesCited") document = fields.Mapping(load_default=None, load_only=True) @post_load def make_reference(self, data, **kwargs) -> Reference: data["id"] = BibliographyId(data["id"]) data["lines_cited"] = tuple(data["lines_cited"]) data["document"] = data["document"] and create_object_entry( data["document"]) return Reference(**data)
class LabelSchema(Schema): status = fields.List(NameEnum(atf.Status), required=True) abbreviation = fields.String()
class _TestSchemaStr(Schema): value = ValueEnum(_TestEnumStr, required=True, allow_none=True) name = NameEnum(_TestEnumStr, required=True, allow_none=True)
class _TestSchemaInt(Schema): value = ValueEnum(_TestEnumInt, required=True, allow_none=True) name = NameEnum(_TestEnumInt, required=True, allow_none=True)