Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(utils): use new commentary model #103

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading