Skip to content

Commit d307a1b

Browse files
authored
convert book abbreviation in \id marker to uppercase (#60)
* convert book id to uppercase * add unit test, fix comment typo
1 parent daa1b8e commit d307a1b

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

machine/corpora/usfm_file_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ def _get_id(filename: StrPath, encoding: str) -> str:
3535
index = id.find(" ")
3636
if index != -1:
3737
id = id[:index]
38-
return id.strip()
39-
raise RuntimeError("The USFM does not contain and 'id' marker.")
38+
return id.strip().upper()
39+
raise RuntimeError("The USFM does not contain an 'id' marker.")

machine/corpora/usfm_zip_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ def _get_id(archive_filename: StrPath, path: str, encoding: str) -> str:
4242
index = id.find(" ")
4343
if index != -1:
4444
id = id[:index]
45-
return id.strip()
46-
raise RuntimeError("The USFM does not contain and 'id' marker.")
45+
return id.strip().upper()
46+
raise RuntimeError("The USFM does not contain an 'id' marker.")

tests/corpora/test_usfm_file_text.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,19 @@ def test_get_rows_include_markers() -> None:
136136

137137
assert verse_ref(rows[16]).exact_equals(VerseRef.from_string("MAT 2:10", corpus.versification))
138138
assert rows[16].text == "\\tc3-4 Chapter 2 verse 10"
139+
140+
141+
def test_usfm_file_text_corpus_lowercase_usfm_id() -> None:
142+
corpus = UsfmFileTextCorpus(USFM_TEST_PROJECT_PATH)
143+
144+
text = corpus.get_text("LEV")
145+
assert text is not None
146+
rows = list(text)
147+
148+
assert len(rows) == 2
149+
150+
assert verse_ref(rows[0]).exact_equals(VerseRef.from_string("LEV 14:55", corpus.versification))
151+
assert rows[0].text == "Chapter fourteen, verse fifty-five. Segment b."
152+
153+
assert verse_ref(rows[1]).exact_equals(VerseRef.from_string("LEV 14:56", corpus.versification))
154+
assert rows[1].text == "Chapter fourteen, verse fifty-six."

tests/testutils/data/usfm/Tes/04LEVTes.SFM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\id LEV - Test
1+
\id lev - Test
22
\h Leviticus
33
\mt Leviticus
44
\c 14

0 commit comments

Comments
 (0)