-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port remaining changes from Machine PR #163, clean up code
- Loading branch information
1 parent
46f5e4d
commit 3e97c10
Showing
8 changed files
with
169 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,45 @@ | ||
from abc import ABC | ||
from dataclasses import dataclass | ||
|
||
from ..scripture.canon import book_id_to_number | ||
from ..scripture.verse_ref import Versification | ||
from .usfm_stylesheet import UsfmStylesheet | ||
|
||
|
||
@dataclass | ||
class ParatextProjectSettings(ABC): | ||
def __init__( | ||
self, | ||
name: str, | ||
full_name: str, | ||
encoding: str, | ||
versification: Versification, | ||
stylesheet: UsfmStylesheet, | ||
file_name_prefix: str, | ||
file_name_form: str, | ||
file_name_suffix: str, | ||
biblical_terms_list_type: str, | ||
biblical_terms_project_name: str, | ||
biblical_terms_file_name: str, | ||
) -> None: | ||
self._name = name | ||
self._full_name = full_name | ||
self._encoding = encoding | ||
self._versification = versification | ||
self._stylesheet = stylesheet | ||
self._file_name_prefix = file_name_prefix | ||
self._file_name_form = file_name_form | ||
self._file_name_suffix = file_name_suffix | ||
self._biblical_terms_list_type = biblical_terms_list_type | ||
self._biblical_terms_project_name = biblical_terms_project_name | ||
self._biblical_terms_file_name = biblical_terms_file_name | ||
|
||
@property | ||
def name(self) -> str: | ||
return self._name | ||
|
||
@property | ||
def full_name(self) -> str: | ||
return self._full_name | ||
|
||
@property | ||
def encoding(self) -> str: | ||
return self._encoding | ||
|
||
@property | ||
def versification(self) -> Versification: | ||
return self._versification | ||
|
||
@property | ||
def stylesheet(self) -> UsfmStylesheet: | ||
return self._stylesheet | ||
|
||
@property | ||
def file_name_prefix(self) -> str: | ||
return self._file_name_prefix | ||
|
||
@property | ||
def file_name_form(self) -> str: | ||
return self._file_name_form | ||
|
||
@property | ||
def file_name_suffix(self) -> str: | ||
return self._file_name_suffix | ||
|
||
@property | ||
def biblical_terms_list_type(self) -> str: | ||
return self._biblical_terms_list_type | ||
|
||
@property | ||
def biblical_terms_project_name(self) -> str: | ||
return self._biblical_terms_project_name | ||
|
||
@property | ||
def biblical_terms_file_name(self) -> str: | ||
return self._biblical_terms_file_name | ||
name: str | ||
full_name: str | ||
encoding: str | ||
versification: Versification | ||
stylesheet: UsfmStylesheet | ||
file_name_prefix: str | ||
file_name_form: str | ||
file_name_suffix: str | ||
biblical_terms_list_type: str | ||
biblical_terms_project_name: str | ||
biblical_terms_file_name: str | ||
|
||
def get_book_file_name(self, book_id: str) -> str: | ||
if self.file_name_form == "MAT": | ||
book_part = book_id | ||
elif self.file_name_form in ("40", "41"): | ||
book_part = _get_book_file_name_digits(book_id) | ||
else: | ||
book_part = _get_book_file_name_digits(book_id) + book_id | ||
return self.file_name_prefix + book_part + self.file_name_suffix | ||
|
||
|
||
def _get_book_file_name_digits(book_id: str) -> str: | ||
book_num = book_id_to_number(book_id) | ||
if book_num < 10: | ||
return f"0{book_num}" | ||
if book_num < 40: | ||
return str(book_num) | ||
if book_num < 100: | ||
return str(book_num + 1) | ||
if book_num < 110: | ||
return f"A{book_num - 100}" | ||
if book_num < 120: | ||
return f"B{book_num - 110}" | ||
return f"C{book_num - 120}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from machine.corpora import UsfmStylesheet | ||
from machine.corpora.paratext_project_settings import ParatextProjectSettings | ||
from machine.scripture import ENGLISH_VERSIFICATION | ||
|
||
|
||
def test_get_book_file_name_book_num() -> None: | ||
settings = _create_settings("41") | ||
assert settings.get_book_file_name("MRK") == "PROJ42.SFM" | ||
|
||
|
||
def test_get_book_file_name_book_num_book_id() -> None: | ||
settings = _create_settings("41MAT") | ||
assert settings.get_book_file_name("MRK") == "PROJ42MRK.SFM" | ||
|
||
|
||
def test_get_book_file_name_book_id() -> None: | ||
settings = _create_settings("MAT") | ||
assert settings.get_book_file_name("MRK") == "PROJMRK.SFM" | ||
|
||
|
||
def test_get_book_file_name_book_num_double_digit() -> None: | ||
settings = _create_settings("41") | ||
assert settings.get_book_file_name("GEN") == "PROJ01.SFM" | ||
|
||
|
||
def test_get_book_file_name_book_num_xxg() -> None: | ||
settings = _create_settings("41") | ||
assert settings.get_book_file_name("XXG") == "PROJ100.SFM" | ||
|
||
|
||
def test_get_book_file_name_book_num_prefix_a() -> None: | ||
settings = _create_settings("41") | ||
assert settings.get_book_file_name("FRT") == "PROJA0.SFM" | ||
|
||
|
||
def test_get_book_file_name_book_num_prefix_b() -> None: | ||
settings = _create_settings("41") | ||
assert settings.get_book_file_name("TDX") == "PROJB0.SFM" | ||
|
||
|
||
def test_get_book_file_name_book_num_prefix_c() -> None: | ||
settings = _create_settings("41") | ||
assert settings.get_book_file_name("3MQ") == "PROJC0.SFM" | ||
|
||
|
||
def _create_settings(file_name_form: str) -> ParatextProjectSettings: | ||
return ParatextProjectSettings( | ||
"Name", | ||
"Name", | ||
"utf-8", | ||
ENGLISH_VERSIFICATION, | ||
UsfmStylesheet("usfm.sty"), | ||
"PROJ", | ||
file_name_form, | ||
".SFM", | ||
"Major", | ||
"", | ||
"BiblicalTerms.xml", | ||
) |
Oops, something went wrong.