1- from typing import Dict , Optional
1+ from typing import Dict , List , Optional
22
33from testutils .memory_paratext_project_quote_convention_detector import MemoryParatextProjectQuoteConventionDetector
44
55from machine .corpora import ParatextProjectSettings , UsfmStylesheet
66from machine .punctuation_analysis import ParatextProjectQuoteConventionDetector , QuoteConventionAnalysis
7+ from machine .punctuation_analysis .quote_convention import QuoteConvention
8+ from machine .punctuation_analysis .standard_quote_conventions import STANDARD_QUOTE_CONVENTIONS
79from machine .scripture import ORIGINAL_VERSIFICATION , Versification
10+ from machine .scripture .parse import parse_selection
11+
12+ standard_english_quote_convention : Optional [QuoteConvention ] = STANDARD_QUOTE_CONVENTIONS .get_quote_convention_by_name (
13+ "standard_english"
14+ )
15+ standard_french_quote_convention : Optional [QuoteConvention ] = STANDARD_QUOTE_CONVENTIONS .get_quote_convention_by_name (
16+ "standard_french"
17+ )
818
919
1020def test_get_quote_convention () -> None :
1121 env = _TestEnvironment (
1222 files = {
13- "41MATTest.SFM" : r"""\id MAT
14- \c 1
15- \v 1 Someone said, “This is something I am saying!
16- \v 2 This is also something I am saying” (that is, “something I am speaking”).
17- \p
18- \v 3 Other text, and someone else said,
19- \q1
20- \v 4 “Things
21- \q2 someone else said!
22- \q3 and more things someone else said.”
23- \m That is why he said “things someone else said.”
24- \v 5 Then someone said, “More things someone said.”""" ,
23+ "41MATTest.SFM" : rf"""\id MAT
24+ { get_test_chapter (1 , standard_english_quote_convention )} """ ,
2525 }
2626 )
2727 analysis : Optional [QuoteConventionAnalysis ] = env .get_quote_convention ()
@@ -30,6 +30,40 @@ def test_get_quote_convention() -> None:
3030 assert analysis .best_quote_convention .name == "standard_english"
3131
3232
33+ def test_get_quote_convention_by_book () -> None :
34+ env = _TestEnvironment (
35+ files = {
36+ "41MATTest.SFM" : rf"""\id MAT
37+ { get_test_chapter (1 , standard_english_quote_convention )} """ ,
38+ "42MRKTest.SFM" : rf"""\id MRK
39+ { get_test_chapter (1 , standard_french_quote_convention )} """ ,
40+ }
41+ )
42+ analysis : Optional [QuoteConventionAnalysis ] = env .get_quote_convention ("MRK" )
43+ assert analysis is not None
44+ assert analysis .best_quote_convention_score > 0.8
45+ assert analysis .best_quote_convention .name == "standard_french"
46+
47+
48+ def test_get_quote_convention_by_chapter () -> None :
49+ env = _TestEnvironment (
50+ files = {
51+ "41MATTest.SFM" : rf"""\id MAT
52+ { get_test_chapter (1 , standard_english_quote_convention )} """ ,
53+ "42MRKTest.SFM" : rf"""\id MRK
54+ { get_test_chapter (1 , standard_english_quote_convention )}
55+ { get_test_chapter (2 , standard_french_quote_convention )}
56+ { get_test_chapter (3 , standard_english_quote_convention )}
57+ { get_test_chapter (4 , standard_english_quote_convention )}
58+ { get_test_chapter (5 , standard_french_quote_convention )} """ ,
59+ }
60+ )
61+ analysis : Optional [QuoteConventionAnalysis ] = env .get_quote_convention ("MRK2,4-5" )
62+ assert analysis is not None
63+ assert analysis .best_quote_convention_score > 0.66
64+ assert analysis .best_quote_convention .name == "standard_french"
65+
66+
3367class _TestEnvironment :
3468 def __init__ (
3569 self ,
@@ -44,8 +78,27 @@ def __init__(
4478 def detector (self ) -> ParatextProjectQuoteConventionDetector :
4579 return self ._detector
4680
47- def get_quote_convention (self ) -> Optional [QuoteConventionAnalysis ]:
48- return self .detector .get_quote_convention_analysis ()
81+ def get_quote_convention (self , scripture_range : Optional [str ] = None ) -> Optional [QuoteConventionAnalysis ]:
82+ chapters : Optional [Dict [int , List [int ]]] = None
83+ if scripture_range is not None :
84+ chapters = parse_selection (scripture_range , ORIGINAL_VERSIFICATION )
85+ return self .detector .get_quote_convention_analysis (include_chapters = chapters )
86+
87+
88+ def get_test_chapter (number : int , quote_convention : Optional [QuoteConvention ]) -> str :
89+ left_quote : str = quote_convention .get_opening_quotation_mark_at_depth (1 ) if quote_convention else ""
90+ right_quote : str = quote_convention .get_closing_quotation_mark_at_depth (1 ) if quote_convention else ""
91+ return rf"""\c { number }
92+ \v 1 Someone said, { left_quote } This is something I am saying!
93+ \v 2 This is also something I am saying{ right_quote } (that is, { left_quote } something I am speaking{ right_quote } ).
94+ \p
95+ \v 3 Other text, and someone else said,
96+ \q1
97+ \v 4 { left_quote } Things
98+ \q2 someone else said!
99+ \q3 and more things someone else said.{ right_quote }
100+ \m That is why he said { left_quote } things someone else said.{ right_quote }
101+ \v 5 Then someone said, { left_quote } More things someone said.{ right_quote } """
49102
50103
51104class _DefaultParatextProjectSettings (ParatextProjectSettings ):
0 commit comments