Skip to content

Commit c4d0b8b

Browse files
committed
Port 'Expose chapter numbers' sillsdev/machine#369
1 parent c86a344 commit c4d0b8b

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

machine/punctuation_analysis/chapter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
@dataclass(frozen=True)
77
class Chapter:
88
verses: list[Verse]
9+
chatper_num: int = 0

machine/punctuation_analysis/quotation_mark_update_first_pass.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List, Set
1+
from typing import Dict, List, Set, Tuple
22

33
from .chapter import Chapter
44
from .depth_based_quotation_mark_resolver import DepthBasedQuotationMarkResolver
@@ -54,11 +54,11 @@ def _check_whether_fallback_mode_will_work(
5454

5555
return True
5656

57-
def find_best_chapter_strategies(self) -> List[QuotationMarkUpdateStrategy]:
58-
best_actions_by_chapter: List[QuotationMarkUpdateStrategy] = []
57+
def find_best_chapter_strategies(self) -> List[Tuple[int, QuotationMarkUpdateStrategy]]:
58+
best_actions_by_chapter: List[Tuple[int, QuotationMarkUpdateStrategy]] = []
5959

6060
for chapter in self.get_chapters():
61-
best_actions_by_chapter.append(self._find_best_strategy_for_chapter(chapter))
61+
best_actions_by_chapter.append((chapter.chatper_num, self._find_best_strategy_for_chapter(chapter)))
6262

6363
return best_actions_by_chapter
6464

machine/punctuation_analysis/usfm_structure_extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ def get_chapters(self, include_chapters: Optional[Dict[int, List[int]]] = None)
110110
current_verse_segments = []
111111
if text_segment.marker_is_in_preceding_context(UsfmMarkerType.CHAPTER):
112112
if len(current_chapter_verses) > 0:
113-
chapters.append(Chapter(current_chapter_verses))
113+
chapters.append(Chapter(current_chapter_verses, current_chapter))
114114
current_chapter_verses = []
115115
current_verse_segments.append(text_segment)
116116
if len(current_verse_segments) > 0:
117117
current_chapter_verses.append(Verse(current_verse_segments))
118118
if len(current_chapter_verses) > 0:
119-
chapters.append(Chapter(current_chapter_verses))
119+
chapters.append(Chapter(current_chapter_verses, current_chapter))
120120
return chapters

tests/punctuation_analysis/test_quotation_denormalization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ def test_full_quotation_denormalization_pipeline() -> None:
3838
parse_usfm(normalized_usfm, quotation_mark_denormalization_first_pass)
3939
best_chapter_strategies = quotation_mark_denormalization_first_pass.find_best_chapter_strategies()
4040

41+
assert [chapter for chapter, _ in best_chapter_strategies] == [1]
42+
4143
quotation_mark_denormalizer = QuotationMarkDenormalizationUsfmUpdateBlockHandler(
4244
standard_english_quote_convention,
43-
QuotationMarkUpdateSettings(chapter_strategies=best_chapter_strategies),
45+
QuotationMarkUpdateSettings(chapter_strategies=[strategy for _, strategy in best_chapter_strategies]),
4446
)
4547

4648
updater = UpdateUsfmParserHandler(update_block_handlers=[quotation_mark_denormalizer])

tests/punctuation_analysis/test_quotation_mark_update_first_pass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def run_first_pass(
678678
first_pass_analyzer = QuotationMarkUpdateFirstPass(source_quote_convention, target_quote_convention)
679679
parse_usfm(normalized_usfm, first_pass_analyzer)
680680

681-
return first_pass_analyzer.find_best_chapter_strategies()
681+
return [strategy for _, strategy in first_pass_analyzer.find_best_chapter_strategies()]
682682

683683

684684
def run_first_pass_on_chapter(

0 commit comments

Comments
 (0)