j-s-v's picture
2025-07-28
d4bade4
from preprocess.utils.common.utils import find_full_word, remove_full_words
from constants.constants import *
'''def find_color_and_sour(row, col_name='type_wine', types=['Белое', 'Розовое', 'Красное', 'крас.', 'бел.', 'роз.']):
if col_name in row.keys():
for t in types:
if t.lower() in row[col_name].lower():
return 'Вино'
return None'''
'''def is_type_exist(row, types):
for t in TYPES_VARIATIONS_DICT.keys():
if find_full_word(row['type'], TYPES_VARIATIONS_DICT[t]):
return t
for t in types:
if t in row['type']: # Сравнение без учета регистра
return t
return None'''
def extract_type(text, remove=False):
special_name = find_full_word(text, SPECIFIC_NAMES)
if special_name:
text = text.replace(special_name, '##SPECIAL_NAME##')
for t in TYPES_VARIATIONS_DICT.keys():
type_str = find_full_word(text, TYPES_VARIATIONS_DICT[t])
if type_str:
if remove:
text = text.replace(type_str, ' ')
if special_name:
text = text.replace('##SPECIAL_NAME##', special_name)
return t, text
type_str = find_full_word(text, LONG_TYPES_LIST)
if type_str:
if remove:
text = text.replace(type_str, ' ')
if special_name:
text = text.replace('##SPECIAL_NAME##', special_name)
return type_str.lower(), text
if special_name:
text = text.replace('##SPECIAL_NAME##', special_name)
return None, text
'''def get_type(row, types):
if 'type' not in row.keys():
return check_type(row, types)
elif 'type' in row.keys():
semi_res=is_type_exist(row, types)
if semi_res!=None:
return semi_res
else:
return check_type(row, types)
return None'''