@@ -160,6 +160,7 @@ def __init__(self, from_lang: Language, to_lang: Language, pkg: Package):
160
160
self .to_lang = to_lang
161
161
self .pkg = pkg
162
162
self .translator = None
163
+ self .sentencizer = SpacySentencizerSmall ()
163
164
164
165
def hypotheses (self , input_text : str , num_hypotheses : int = 4 ) -> list [Hypothesis ]:
165
166
if self .translator is None :
@@ -171,7 +172,7 @@ def hypotheses(self, input_text: str, num_hypotheses: int = 4) -> list[Hypothesi
171
172
for paragraph in paragraphs :
172
173
translated_paragraphs .append (
173
174
apply_packaged_translation (
174
- self .pkg , paragraph , self .translator , num_hypotheses
175
+ self .pkg , paragraph , self .translator , num_hypotheses , self . sentencizer
175
176
)
176
177
)
177
178
info ("translated_paragraphs:" , translated_paragraphs )
@@ -394,7 +395,7 @@ def hypotheses(self, input_text: str, num_hypotheses: int = 1) -> list[Hypothesi
394
395
395
396
396
397
def apply_packaged_translation (
397
- pkg : Package , input_text : str , translator : Translator , num_hypotheses : int = 4
398
+ pkg : Package , input_text : str , translator : Translator , num_hypotheses : int = 4 , sentencizer : sbd . ISentenceBoundaryDetectionModel = SpacySentencizerSmall ()
398
399
) -> list [Hypothesis ]:
399
400
"""Applies the translation in pkg to translate input_text.
400
401
@@ -452,7 +453,6 @@ def apply_packaged_translation(
452
453
info(input_text[start_index:sbd_index])
453
454
start_index = sbd_index
454
455
"""
455
- sentencizer = SpacySentencizerSmall ()
456
456
sentences = sentencizer .split_sentences (input_text )
457
457
458
458
info ("sentences" , sentences )
0 commit comments