Structure: fuzzy CHAPTER keyword for OCR, cap run-on titles, prefer contents-page title when it has fewer unknown words; metadata: multi-resolution OCR of title pages, OCR name correction from repeated words; ingest: qpdf optional
This commit is contained in:
@@ -48,6 +48,30 @@ class HeadingTests(unittest.TestCase):
|
||||
self.assertTrue(got[0]["synthetic"])
|
||||
self.assertEqual((got[0]["unit"], got[0]["number"]), (2, 1))
|
||||
|
||||
def test_ocr_damaged_chapter_word_is_recognised(self):
|
||||
units = [unit("CHAPTER I.\nOne\n\n" + BODY), unit("OUAPTER II.\nTwo\n\n" + BODY),
|
||||
unit("CUAPTER TX.\nNine?\n\n" + BODY), unit("CIEAPTER NEL,\nTwelve?\n\n" + BODY)]
|
||||
got = structure.find_headings(units)
|
||||
self.assertEqual([h["number"] for h in got], [1, 2, 3, 4]) # unreadable numerals count up in sequence
|
||||
self.assertFalse(structure.is_chapter_word("CHAPTERS"))
|
||||
self.assertFalse(structure.is_chapter_word("CAPTAIN"))
|
||||
self.assertFalse(structure.is_chapter_word("SCIENCE"))
|
||||
|
||||
def test_long_title_without_blank_line_keeps_only_the_upper_case_lines(self):
|
||||
body = "the Yogis not only bring about desired mental qualities and properties by will-power coupled with rhythmic breathing, but they also develop"
|
||||
units = [unit("CHAPTER XVI.\nYOGI SPIRITUAL BREATHING.\n" + body + "\n" + body + "\n\n" + BODY)]
|
||||
h = structure.find_headings(units)[0]
|
||||
self.assertEqual(h["title"], "Yogi Spiritual Breathing.")
|
||||
self.assertEqual(h["title_end"], 2)
|
||||
|
||||
def test_contents_in_chapter_line_form(self):
|
||||
units = [unit("CONTENTS\nCHAPTER I.\nBreath Is Life........ 8\nCHAPTER II.\nThe Four Methods of Respiration ..... 27\n"), unit("CHAPTER I.\nX\n\n" + BODY)]
|
||||
toc = structure.toc_chapter_lines(units, 1)
|
||||
self.assertEqual(toc[2][0], "The Four Methods of Respiration")
|
||||
self.assertEqual(toc[1][0], "Breath Is Life")
|
||||
self.assertEqual(structure.unknown_words("The Four Metiiods of Respiration"), 1)
|
||||
self.assertEqual(structure.unknown_words("The Four Methods of Respiration"), 0)
|
||||
|
||||
def test_nothing_readable_gives_no_headings(self):
|
||||
self.assertEqual(structure.find_headings([unit(""), unit("x")]), [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user