Skip to content

Commit

Permalink
Initiated the parametrisation of the get_chapter method
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioNar committed Dec 23, 2024
1 parent 86e2ad6 commit 5017ad4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/parsers/test_akomantoso.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_get_body(self):
def test_get_chapters(self):
"""Test retrieval and content of chapter headings."""
self.parser.get_body(body_xpath='.//akn:body')
self.parser.get_chapters()
self.parser.get_chapters(chapter_xpath='.//akn:chapter')

expected_chapters = [
{'eId': 'chp_I', 'chapter_num': 'CHAPTER I', 'chapter_heading': 'SUBJECT MATTER, SCOPE AND DEFINITIONS'},
Expand Down
6 changes: 3 additions & 3 deletions tulit/parsers/akomantoso.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def get_act(self) -> None:
# Fallback: try without namespace
self.act = self.root.find('.//act')

def get_chapters(self) -> None:
def get_chapters(self, chapter_xpath) -> None:
"""
Extracts chapter information from the document.
Expand All @@ -345,7 +345,7 @@ def get_chapters(self) -> None:
self.chapters = [] # Reset chapters list

# Find all <chapter> elements in the body
for chapter in self.root.findall('.//akn:chapter', namespaces=self.namespaces):
for chapter in self.body.findall(chapter_xpath, namespaces=self.namespaces):
eId = chapter.get('eId')
chapter_num = chapter.find('akn:num', namespaces=self.namespaces)
chapter_heading = chapter.find('akn:heading', namespaces=self.namespaces)
Expand Down Expand Up @@ -543,7 +543,7 @@ def parse(self, file: str) -> list[dict]:
print(f"Error in get_body: {e}")

try:
self.get_chapters()
self.get_chapters(chapter_xpath='.//akn:chapter')
debug_info['chapters'] = len(self.chapters) if hasattr(self, 'chapters') else 0
print(f"Chapters parsed successfully. Number of chapters: {debug_info['chapters']}")
except Exception as e:
Expand Down

0 comments on commit 5017ad4

Please sign in to comment.