Skip to content

Commit

Permalink
Merge pull request #103 from musicEnfanthen/feature/commentary
Browse files Browse the repository at this point in the history
refactor(utils): use new commentary model
  • Loading branch information
musicEnfanthen authored Dec 23, 2024
2 parents 8684564 + 1047e89 commit d8cff36
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
7 changes: 5 additions & 2 deletions convert_source_description/default_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@
defaultTextcritics: TextCritics = {
"id": "",
"label": "",
"description": [],
"evaluations": [],
# "rowTable": False,
"comments": [],
"commentary": {
"preamble": "",
"comments": []
},
"linkBoxes": []
}

Expand Down
9 changes: 7 additions & 2 deletions convert_source_description/typed_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,19 @@ class TextcriticalCommentBlock(TypedDict):
blockHeader: str
blockComments: List[TextcriticalComment]

class TextcriticalCommentary(TypedDict):
"""A typed dictionary that represents a textcritical commentary."""
preamble: str
comments: List[TextcriticalCommentBlock]


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


Expand Down
14 changes: 7 additions & 7 deletions convert_source_description/utils_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ def process_table(
table_index (int): The index of the table in the list of tables.
"""
textcritics = copy.deepcopy(defaultTextcritics)
textcritics['comments'] = []
textcritics['commentary']['comments'] = []

rows_in_table = table.find_all('tr')
block_index = -1

# Create a default comment block with an empty blockHeader
default_comment_block = copy.deepcopy(defaultTextcriticalCommentBlock)
default_comment_block['blockHeader'] = ""
textcritics['comments'].append(default_comment_block)
textcritics['commentary']['comments'].append(default_comment_block)
block_index += 1

textcritics = self._process_table_rows(textcritics, rows_in_table, block_index)
Expand Down Expand Up @@ -807,7 +807,7 @@ def _process_corrections(self, textcritics_list: TextcriticsList,
textcritics.pop("linkBoxes", None) # Remove linkBoxes property if it exists

# Remove svgGroupId property from textcritical comments
for comment_block in textcritics['comments']:
for comment_block in textcritics['commentary']['comments']:
for comment in comment_block['blockComments']:
comment.pop("svgGroupId", None) # Remove svgGroupId property if it exists

Expand All @@ -834,21 +834,21 @@ def _process_table_rows(self, textcritics, rows_in_table, block_index):
# Check if the first td has a colspan attribute
if 'colspan' in columns_in_row[0].attrs:
# If the default comment block is empty, remove it
if not textcritics['comments'][0]['blockComments']:
textcritics['comments'].pop(0)
if not textcritics['commentary']['comments'][0]['blockComments']:
textcritics['commentary']['comments'].pop(0)
block_index -= 1

comment_block = copy.deepcopy(defaultTextcriticalCommentBlock)
comment_block['blockHeader'] = self._strip_tag_and_clean(
columns_in_row[0], 'td')
textcritics['comments'].append(comment_block)
textcritics['commentary']['comments'].append(comment_block)
block_index += 1

continue

if block_index >= 0:
comment = self._get_comment(columns_in_row)
textcritics['comments'][block_index]['blockComments'].append(comment)
textcritics['commentary']['comments'][block_index]['blockComments'].append(comment)

return textcritics

Expand Down

0 comments on commit d8cff36

Please sign in to comment.