Skip to content

Commit

Permalink
convert book abbreviation in \id marker to uppercase (#60)
Browse files Browse the repository at this point in the history
* convert book id to uppercase

* add unit test, fix comment typo
  • Loading branch information
mshannon-sil authored Nov 17, 2023
1 parent daa1b8e commit d307a1b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions machine/corpora/usfm_file_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ def _get_id(filename: StrPath, encoding: str) -> str:
index = id.find(" ")
if index != -1:
id = id[:index]
return id.strip()
raise RuntimeError("The USFM does not contain and 'id' marker.")
return id.strip().upper()
raise RuntimeError("The USFM does not contain an 'id' marker.")
4 changes: 2 additions & 2 deletions machine/corpora/usfm_zip_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def _get_id(archive_filename: StrPath, path: str, encoding: str) -> str:
index = id.find(" ")
if index != -1:
id = id[:index]
return id.strip()
raise RuntimeError("The USFM does not contain and 'id' marker.")
return id.strip().upper()
raise RuntimeError("The USFM does not contain an 'id' marker.")
16 changes: 16 additions & 0 deletions tests/corpora/test_usfm_file_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,19 @@ def test_get_rows_include_markers() -> None:

assert verse_ref(rows[16]).exact_equals(VerseRef.from_string("MAT 2:10", corpus.versification))
assert rows[16].text == "\\tc3-4 Chapter 2 verse 10"


def test_usfm_file_text_corpus_lowercase_usfm_id() -> None:
corpus = UsfmFileTextCorpus(USFM_TEST_PROJECT_PATH)

text = corpus.get_text("LEV")
assert text is not None
rows = list(text)

assert len(rows) == 2

assert verse_ref(rows[0]).exact_equals(VerseRef.from_string("LEV 14:55", corpus.versification))
assert rows[0].text == "Chapter fourteen, verse fifty-five. Segment b."

assert verse_ref(rows[1]).exact_equals(VerseRef.from_string("LEV 14:56", corpus.versification))
assert rows[1].text == "Chapter fourteen, verse fifty-six."
2 changes: 1 addition & 1 deletion tests/testutils/data/usfm/Tes/04LEVTes.SFM
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\id LEV - Test
\id lev - Test
\h Leviticus
\mt Leviticus
\c 14
Expand Down

0 comments on commit d307a1b

Please sign in to comment.