From a733a8ed624c46a15f0b252a38366753a635c169 Mon Sep 17 00:00:00 2001 From: Ilya Khait Date: Mon, 25 Nov 2024 13:54:39 +0000 Subject: [PATCH] Refactor --- .../application/fragment_schema.py | 2 +- ebl/fragmentarium/domain/fragment.py | 106 +----------------- .../domain/fragment_external_numbers.py | 104 +++++++++++++++++ ebl/tests/factories/fragment.py | 2 +- ebl/tests/fragmentarium/test_fragment.py | 2 +- 5 files changed, 113 insertions(+), 103 deletions(-) create mode 100644 ebl/fragmentarium/domain/fragment_external_numbers.py diff --git a/ebl/fragmentarium/application/fragment_schema.py b/ebl/fragmentarium/application/fragment_schema.py index 1101873e4..57946d483 100644 --- a/ebl/fragmentarium/application/fragment_schema.py +++ b/ebl/fragmentarium/application/fragment_schema.py @@ -16,8 +16,8 @@ Measure, Script, UncuratedReference, - ExternalNumbers, ) +from ebl.fragmentarium.domain.fragment_external_numbers import ExternalNumbers from ebl.fragmentarium.domain.line_to_vec_encoding import LineToVecEncoding from ebl.fragmentarium.domain.record import Record, RecordEntry, RecordType from ebl.schemas import ResearchProjectField, ScopeField, ValueEnumField diff --git a/ebl/fragmentarium/domain/fragment.py b/ebl/fragmentarium/domain/fragment.py index 26f7675fa..6ff5dd440 100644 --- a/ebl/fragmentarium/domain/fragment.py +++ b/ebl/fragmentarium/domain/fragment.py @@ -28,6 +28,10 @@ from ebl.transliteration.domain.lark_parser import parse_markup_paragraphs from ebl.fragmentarium.domain.date import Date from ebl.fragmentarium.domain.colophon import Colophon +from ebl.fragmentarium.domain.fragment_external_numbers import ( + FragmentExternalNumbers, + ExternalNumbers, +) def parse_markup_with_paragraphs(text: str) -> Sequence[MarkupPart]: @@ -96,30 +100,7 @@ def abbreviation(self) -> str: @attr.s(auto_attribs=True, frozen=True) -class ExternalNumbers: - cdli_number: str = "" - bm_id_number: str = "" - archibab_number: str = "" - bdtns_number: str = "" - chicago_isac_number: str = "" - ur_online_number: str = "" - hilprecht_jena_number: str = "" - hilprecht_heidelberg_number: str = "" - metropolitan_number: str = "" - louvre_number: str = "" - dublin_tcd_number: str = "" - alalah_hpm_number: str = "" - australianinstituteofarchaeology_number: str = "" - philadelphia_number: str = "" - achemenet_number: str = "" - nabucco_number: str = "" - yale_peabody_number: str = "" - oracc_numbers: Sequence[str] = () - seal_numbers: Sequence[str] = () - - -@attr.s(auto_attribs=True, frozen=True) -class Fragment: +class Fragment(FragmentExternalNumbers): number: MuseumNumber accession: Optional[Accession] = None publication: str = "" @@ -145,11 +126,11 @@ class Fragment: script: Script = Script() date: Optional[Date] = None dates_in_text: Sequence[Date] = [] - external_numbers: ExternalNumbers = ExternalNumbers() projects: Sequence[str] = () traditional_references: Sequence[str] = [] archaeology: Optional[Archaeology] = None colophon: Optional[Colophon] = None + external_numbers: ExternalNumbers = ExternalNumbers() @property def is_lowest_join(self) -> bool: @@ -238,78 +219,3 @@ def get_matching_lines(self, query: TransliterationQuery) -> Text: for numbers, _ in groupby(line_numbers) ] return Text(lines=tuple(pydash.flatten(match))) - - def _get_external_number(self, number_type: str) -> str: - return getattr(self.external_numbers, f"{number_type}_number") - - @property - def cdli_number(self) -> str: - return self._get_external_number("cdli") - - @property - def bm_id_number(self) -> str: - return self._get_external_number("bm_id") - - @property - def archibab_number(self) -> str: - return self._get_external_number("archibab") - - @property - def bdtns_number(self) -> str: - return self._get_external_number("bdtns") - - @property - def chicago_isac_number(self) -> str: - return self._get_external_number("chicago_isac") - - @property - def ur_online_number(self) -> str: - return self._get_external_number("ur_online") - - @property - def hilprecht_jena_number(self) -> str: - return self._get_external_number("hilprecht_jena") - - @property - def hilprecht_heidelberg_number(self) -> str: - return self._get_external_number("hilprecht_heidelberg") - - @property - def yale_peabody_number(self) -> str: - return self._get_external_number("yale_peabody") - - @property - def metropolitan_number(self) -> str: - return self._get_external_number("metropolitan_number") - - @property - def louvre_number(self) -> str: - return self._get_external_number("louvre_number") - - @property - def dublin_tcd_number(self) -> str: - return self._get_external_number("dublin_tcd_number") - - @property - def alalah_hpm_number(self) -> str: - return self._get_external_number("alalah_hpm_number") - - @property - def australianinstituteofarchaeology_number(self) -> str: - return self._get_external_number("australianinstituteofarchaeology_number") - - @property - def achemenet_number(self) -> str: - return self._get_external_number("achemenet") - - @property - def nabucco_number(self) -> str: - return self._get_external_number("nabucco") - - @property - def philadelphia_number(self) -> str: - return self._get_external_number("philadelphia_number") - - @property - def seal_number(self) -> str: - return self._get_external_number("seal_number") diff --git a/ebl/fragmentarium/domain/fragment_external_numbers.py b/ebl/fragmentarium/domain/fragment_external_numbers.py new file mode 100644 index 000000000..b9edcd5e9 --- /dev/null +++ b/ebl/fragmentarium/domain/fragment_external_numbers.py @@ -0,0 +1,104 @@ +import attr +from typing import Sequence + + +@attr.s(auto_attribs=True, frozen=True) +class ExternalNumbers: + cdli_number: str = "" + bm_id_number: str = "" + archibab_number: str = "" + bdtns_number: str = "" + chicago_isac_number: str = "" + ur_online_number: str = "" + hilprecht_jena_number: str = "" + hilprecht_heidelberg_number: str = "" + metropolitan_number: str = "" + louvre_number: str = "" + dublin_tcd_number: str = "" + alalah_hpm_number: str = "" + australianinstituteofarchaeology_number: str = "" + philadelphia_number: str = "" + achemenet_number: str = "" + nabucco_number: str = "" + yale_peabody_number: str = "" + oracc_numbers: Sequence[str] = () + seal_numbers: Sequence[str] = () + + +class FragmentExternalNumbers: + external_numbers: ExternalNumbers = ExternalNumbers() + + def _get_external_number(self, number_type: str) -> str: + return getattr(self.external_numbers, f"{number_type}_number") + + @property + def cdli_number(self) -> str: + return self._get_external_number("cdli") + + @property + def bm_id_number(self) -> str: + return self._get_external_number("bm_id") + + @property + def archibab_number(self) -> str: + return self._get_external_number("archibab") + + @property + def bdtns_number(self) -> str: + return self._get_external_number("bdtns") + + @property + def chicago_isac_number(self) -> str: + return self._get_external_number("chicago_isac") + + @property + def ur_online_number(self) -> str: + return self._get_external_number("ur_online") + + @property + def hilprecht_jena_number(self) -> str: + return self._get_external_number("hilprecht_jena") + + @property + def hilprecht_heidelberg_number(self) -> str: + return self._get_external_number("hilprecht_heidelberg") + + @property + def yale_peabody_number(self) -> str: + return self._get_external_number("yale_peabody") + + @property + def metropolitan_number(self) -> str: + return self._get_external_number("metropolitan_number") + + @property + def louvre_number(self) -> str: + return self._get_external_number("louvre_number") + + @property + def dublin_tcd_number(self) -> str: + return self._get_external_number("dublin_tcd_number") + + @property + def alalah_hpm_number(self) -> str: + return self._get_external_number("alalah_hpm_number") + + @property + def australianinstituteofarchaeology_number(self) -> str: + return self._get_external_number("australianinstituteofarchaeology_number") + + @property + def achemenet_number(self) -> str: + return self._get_external_number("achemenet") + + @property + def nabucco_number(self) -> str: + return self._get_external_number("nabucco") + + @property + def philadelphia_number(self) -> str: + return self._get_external_number("philadelphia_number") + + @property + def seal_number(self) -> str: + return self._get_external_number("seal_number") diff --git a/ebl/tests/factories/fragment.py b/ebl/tests/factories/fragment.py index 6938adaf0..67c3c45a3 100644 --- a/ebl/tests/factories/fragment.py +++ b/ebl/tests/factories/fragment.py @@ -13,7 +13,6 @@ from ebl.dictionary.domain.word import WordId from ebl.fragmentarium.domain.folios import Folio, Folios from ebl.fragmentarium.domain.fragment import ( - ExternalNumbers, Fragment, Genre, Introduction, @@ -21,6 +20,7 @@ Script, UncuratedReference, ) +from ebl.fragmentarium.domain.fragment_external_numbers import ExternalNumbers from ebl.fragmentarium.domain.line_to_vec_encoding import LineToVecEncoding from ebl.transliteration.domain.museum_number import MuseumNumber from ebl.transliteration.domain import atf diff --git a/ebl/tests/fragmentarium/test_fragment.py b/ebl/tests/fragmentarium/test_fragment.py index b839ace25..b9fc5b9df 100644 --- a/ebl/tests/fragmentarium/test_fragment.py +++ b/ebl/tests/fragmentarium/test_fragment.py @@ -5,7 +5,6 @@ from ebl.fragmentarium.domain.folios import Folio, Folios from ebl.fragmentarium.domain.fragment import ( - ExternalNumbers, Fragment, Genre, Measure, @@ -14,6 +13,7 @@ UncuratedReference, Notes, ) +from ebl.fragmentarium.domain.fragment_external_numbers import ExternalNumbers from ebl.fragmentarium.domain.joins import Join, Joins from ebl.fragmentarium.domain.line_to_vec_encoding import LineToVecEncoding from ebl.tests.factories.parallel_line import ParallelCompositionFactory