-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Move get_books to parse.py and add get_chapters #61
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #61 +/- ##
==========================================
+ Coverage 86.62% 86.74% +0.11%
==========================================
Files 223 225 +2
Lines 13376 13526 +150
==========================================
+ Hits 11587 11733 +146
- Misses 1789 1793 +4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 5 files at r1, 2 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @isaac091 and @johnml1135)
machine/scripture/parse.py
line 44 at r2 (raw file):
# Output format: { book_num: [chapters] } # An empty list, i.e. book_num: [] signifies the inclusion of all chapters, while the absence of an entry means the book is not included def get_chapters(chapter_selections: str) -> dict:
The return type should be more explicit.
machine/scripture/parse.py
line 45 at r2 (raw file):
# An empty list, i.e. book_num: [] signifies the inclusion of all chapters, while the absence of an entry means the book is not included def get_chapters(chapter_selections: str) -> dict: versification = Versification.create("Original")
You should pass in the versification as an argument.
machine/scripture/parse.py
line 51 at r2 (raw file):
# Normalize books written as "MAT01.usfm" to "MAT" chapter_selections = re.sub(USFM_FILE_PATTERN, "", chapter_selections)
This seems specific to silnlp. You should do this in silnlp.
machine/scripture/parse.py
line 72 at r2 (raw file):
if book == 0: raise RuntimeError(f"{section[:3]} is an invalid book ID.")
I would use ValueError
for all exceptions.
machine/scripture/parse.py
line 77 at r2 (raw file):
chapters[book] = set() last_chapter = versification.get_last_chapter(book) for chapter_num in chapter_nums:
We should raise an exception if the chapter is not valid, i.e. out of range.
machine/scripture/parse.py
line 87 at r2 (raw file):
# Delete entry if no chapter numbers were valid if len(chapters[book]) == 0: del chapters[book]
It would probably be clearer to only add the set if it is not empty.
machine/scripture/parse.py
line 89 at r2 (raw file):
del chapters[book] elif "-" in section: # Spans of books spans.append(section)
Is there some reason why you don't just process the span here?
I don't process the spans right away to prioritize getting specific chapters from a book, so for example if someone wanted "MAT-ROM;ACT1-3", they wouldn't have to worry about putting the Acts chapters first to avoid getting the selections overwritten with the span. But I guess that's not consistent all the way through because if "NT" or "OT" are passed first, all of those books are added right away. I can change it so that there's no "order of operations", or if we want to keep it this way, I'll change it so that "NT" and "OT" are added last as well. |
The order shouldn't matter - I would keep it as original versification order. Are you accounting for removals as well? |
Books can include numbers - such as 1CO. |
Books include numbers. |
Book chapter lists can have multiple parts, such as MAT1-3, 5, 7, 10-12. Because of this, we need to use a ";" for splitting sections. |
Previously, johnml1135 (John Lambert) wrote…
Nevermind - this is the simple selection, not the advanced. Ignore my comment. |
I want to make sure I'm understanding - you're saying to add whole books last? I'm currently doing the removals after everything is added, but not allowing removals of spans of books. I can also change that to allow span removals.
What do you mean by simple vs advanced selection? You were right originally, I need to consider books with numbers in the title. |
Let me try it again: for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @isaac091)
I see. For my current code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just apply them in the order that they appear. That way the precedence is explicit.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @isaac091)
machine/scripture/parse.py
line 77 at r2 (raw file):
Previously, ddaspit (Damien Daspit) wrote…
We should raise an exception if the chapter is not valid, i.e. out of range.
I would also strip spaces from the chapter numbers.
I agree with Damein. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 5 files at r1, 1 of 2 files at r2, 1 of 1 files at r3.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @isaac091)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @isaac091 and @johnml1135)
machine/scripture/parse.py
line 45 at r2 (raw file):
Previously, ddaspit (Damien Daspit) wrote…
You should pass in the versification as an argument.
You should use the ORIGINAL_VERSIFICATION
constant rather than creating a new instance.
The updated tests look like they cover the cases that I was concerned about. If they pass, it looks good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @isaac091)
…e modules and use constant in get_chapters signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 3 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @isaac091)
machine/scripture/__init__.py
line 39 at r5 (raw file):
def __getattr__(name: str) -> Any:
You can remove this function. It is no longer needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r6, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @isaac091)
Created new module for get_books and get_chapters due to circular import conflict.
This change is