File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -179,9 +179,10 @@ def _infer(
179
179
self .logger .log (logging .WARNING , f'Invalid characters found! : { invalid_characters } ' )
180
180
text [i ] = apply_character_map (t )
181
181
if do_homophone_replacement and self .init_homophones_replacer ():
182
- text [i ] = self .homophones_replacer .replace (t )
183
- if t != text [i ]:
184
- self .logger .log (logging .INFO , f'Homophones replace: { t } -> { text [i ]} ' )
182
+ text [i ], replaced_words = self .homophones_replacer .replace (text [i ])
183
+ if replaced_words :
184
+ repl_res = ', ' .join ([f'{ _ [0 ]} ->{ _ [1 ]} ' for _ in replaced_words ])
185
+ self .logger .log (logging .INFO , f'Homophones replace: { repl_res } ' )
185
186
186
187
if not skip_refine_text :
187
188
text_tokens = refine_text (
Original file line number Diff line number Diff line change @@ -76,12 +76,15 @@ def load_homophones_map(self, map_file_path):
76
76
77
77
def replace (self , text ):
78
78
result = []
79
+ replaced_words = []
79
80
for char in text :
80
81
if char in self .homophones_map :
81
- result .append (self .homophones_map [char ])
82
+ repl_char = self .homophones_map [char ]
83
+ result .append (repl_char )
84
+ replaced_words .append ((char , repl_char ))
82
85
else :
83
86
result .append (char )
84
- return '' .join (result )
87
+ return '' .join (result ), replaced_words
85
88
86
89
def count_invalid_characters (s ):
87
90
You can’t perform that action at this time.
0 commit comments