File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change 11from app .root_logger import get_root_logger
22import math
33import traceback
4+ import string # to remove punctuation
45from typing import Optional , Callable
56
67from app .audio import Audio
@@ -60,13 +61,20 @@ def get_proportional_result(value: float,
6061 else :
6162 return f (upper_bound / value )
6263
63-
6464def get_fillers (fillers : list , audio : Audio ) -> list :
6565 found_fillers = []
66+ # пунктуация + пробелы для str.translate
67+ removable = string .punctuation + string .whitespace
68+ translation_table = str .maketrans ('' , '' , removable )
69+
6670 for audio_slide in audio .audio_slides :
6771 found_slide_fillers = []
72+ # добавлена предобработка слов - перевод в нижний регистр, очистка от пунктуации
6873 audio_slide_words = [
69- recognized_word .word .value for recognized_word in audio_slide .recognized_words ]
74+ recognized_word .word .value .lower ().translate (translation_table )
75+ for recognized_word in audio_slide .recognized_words
76+ ]
77+
7078 for i in range (len (audio_slide_words )):
7179 for filler in fillers :
7280 filler_split = filler .split ()
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ def __new__(cls):
2727 cls .init_done = True
2828 return cls .instance
2929
30- def __collect_filters (self , filters : dict ) -> ( dict , dict ) :
30+ def __collect_filters (self , filters : dict ) -> tuple [ dict , dict ] :
3131 simple_filters = {}
3232 complex_filters = {}
3333
@@ -64,8 +64,11 @@ def __create_simple_query(self, applicable_filters: dict) -> dict:
6464 logger .info ("ELSE ID: " + str (values [0 ]))
6565 mongodb_query [key ] = ObjectId (values [0 ])
6666 elif key == "username" or key == "full_name" :
67- # Частичное совпадение
68- mongodb_query [key ] = {"$regex" : regex .escape (values [0 ], literal_spaces = True )}
67+ # Частичное совпадение без учета регистра
68+ mongodb_query [key ] = {
69+ "$regex" : regex .escape (values [0 ], literal_spaces = True ),
70+ "$options" : 'i'
71+ }
6972 elif key == "presentation_record_duration" :
7073 # Range по длительности воспроизведения
7174 start_range_time = datetime .strptime (values [0 ], "%M:%S" ).time ()
You can’t perform that action at this time.
0 commit comments