Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Nov 25, 2024
1 parent 9834bea commit a733a8e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 103 deletions.
2 changes: 1 addition & 1 deletion ebl/fragmentarium/application/fragment_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
106 changes: 6 additions & 100 deletions ebl/fragmentarium/domain/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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 = ""
Expand All @@ -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:
Expand Down Expand Up @@ -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")
104 changes: 104 additions & 0 deletions ebl/fragmentarium/domain/fragment_external_numbers.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion ebl/tests/factories/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
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,
Notes,
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
Expand Down
2 changes: 1 addition & 1 deletion ebl/tests/fragmentarium/test_fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ebl.fragmentarium.domain.folios import Folio, Folios
from ebl.fragmentarium.domain.fragment import (
ExternalNumbers,
Fragment,
Genre,
Measure,
Expand All @@ -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
Expand Down

0 comments on commit a733a8e

Please sign in to comment.