Skip to content

Commit

Permalink
fix(utils): move typed classes into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
musicEnfanthen committed Apr 26, 2024
1 parent d9bd19e commit a5534c4
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 101 deletions.
102 changes: 102 additions & 0 deletions convert_source_description/typed_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""Typed dictionaries used for representing source descriptions."""

from typing import List, NotRequired, TypedDict


############################################
# Typed Classes
############################################
class Row(TypedDict):
"""A typed dictionary that represents a row of a system."""
rowType: str
rowBase: str
rowNumber: str


class System(TypedDict):
"""A typed dictionary that represents a system."""
system: str
measure: str
linkTo: str
row: NotRequired[Row]


class Folio(TypedDict):
"""A typed dictionary that represents a folio."""
folio: str
folioLinkTo: str
folioDescription: str
systemGroups: List[List[System]]


class ContentItem(TypedDict):
"""A typed dictionary that represents a content item."""
item: str
itemLinkTo: str
itemDescription: str
folios: List[Folio]


class WritingInstruments(TypedDict):
"""A typed dictionary that represents a set of writing instruments."""
main: str
secondary: List[str]


class Description(TypedDict):
"""A typed dictionary that represents a description of a source description."""
desc: List[str]
writingMaterialString: str
writingInstruments: WritingInstruments
title: str
date: str
pagination: str
measureNumbers: str
instrumentation: str
annotations: str
content: List[ContentItem]


class SourceDescription(TypedDict):
"""A typed dictionary that represents a source description."""
id: str
siglum: str
siglumAddendum: str
type: str
location: str
description: Description


class SourceList(TypedDict):
"""A typed dictionary that represents a list of source descriptions."""
sources: List[SourceDescription]


class LinkBox(TypedDict):
"""A typed dictionary that represents a link box."""
svgGroupId: str
linkTo: str


class TextcriticalComment(TypedDict):
"""A typed dictionary that represents a textcritical comment."""
svgGroupId: str
measure: str
system: str
position: str
comment: str


class TextCritics(TypedDict):
"""A typed dictionary that represents a textcritics object."""
id: str
label: str
description: List
rowTable: bool
comments: List[TextcriticalComment]
linkBoxes: List[LinkBox]


class TextcriticsList(TypedDict):
"""A typed dictionary that represents a list of textcritics objects."""
textcritics: List[TextCritics]
105 changes: 4 additions & 101 deletions convert_source_description/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,116 +7,19 @@
import json
import os
import re
from typing import Dict, List, NotRequired, Optional, Tuple, TypedDict
from typing import Dict, List, Optional, Tuple

import mammoth
from bs4 import BeautifulSoup, Tag

############################################
# Helper variables: Typed Classes
############################################


class Row(TypedDict):
"""A typed dictionary that represents a row of a system."""
rowType: str
rowBase: str
rowNumber: str


class System(TypedDict):
"""A typed dictionary that represents a system."""
system: str
measure: str
linkTo: str
row: NotRequired[Row]


class Folio(TypedDict):
"""A typed dictionary that represents a folio."""
folio: str
folioLinkTo: str
folioDescription: str
systemGroups: List[List[System]]


class ContentItem(TypedDict):
"""A typed dictionary that represents a content item."""
item: str
itemLinkTo: str
itemDescription: str
folios: List[Folio]


class WritingInstruments(TypedDict):
"""A typed dictionary that represents a set of writing instruments."""
main: str
secondary: List[str]


class Description(TypedDict):
"""A typed dictionary that represents a description of a source description."""
desc: List[str]
writingMaterialString: str
writingInstruments: WritingInstruments
title: str
date: str
pagination: str
measureNumbers: str
instrumentation: str
annotations: str
content: List[ContentItem]
from typed_classes import (Row, System, Folio, ContentItem, WritingInstruments,
Description, SourceDescription, SourceList, LinkBox,
TextcriticalComment, TextCritics, TextcriticsList)


class SourceDescription(TypedDict):
"""A typed dictionary that represents a source description."""
id: str
siglum: str
siglumAddendum: str
type: str
location: str
description: Description


class SourceList(TypedDict):
"""A typed dictionary that represents a list of source descriptions."""
sources: List[SourceDescription]


class LinkBox(TypedDict):
"""A typed dictionary that represents a link box."""
svgGroupId: str
linkTo: str


class TextcriticalComment(TypedDict):
"""A typed dictionary that represents a textcritical comment."""
svgGroupId: str
measure: str
system: str
position: str
comment: str


class TextCritics(TypedDict):
"""A typed dictionary that represents a textcritics object."""
id: str
label: str
description: List
rowTable: bool
comments: List[TextcriticalComment]
linkBoxes: List[LinkBox]


class TextcriticsList(TypedDict):
"""A typed dictionary that represents a list of textcritics objects."""
textcritics: List[TextCritics]

############################################
# Helper variables: Strings & Objects
############################################


SYSTEM_STR = 'System'
MEASURE_STR = 'T.'
FOLIO_STR = 'Bl.'
Expand Down

0 comments on commit a5534c4

Please sign in to comment.