SamiKoen commited on
Commit
1feb0e5
·
verified ·
1 Parent(s): 5c0f637

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -2
app.py CHANGED
@@ -77,8 +77,33 @@ def get_warehouse_stock(product_name):
77
  xml_product_name = product_name_elem.text.lower().strip()
78
  search_name = product_name.lower().strip()
79
 
80
- # Fuzzy matching
81
- if search_name in xml_product_name or xml_product_name in search_name:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  warehouses = product.find('Warehouses')
83
  if warehouses is not None:
84
  warehouse_info = []
 
77
  xml_product_name = product_name_elem.text.lower().strip()
78
  search_name = product_name.lower().strip()
79
 
80
+ # Fuzzy matching - normalize both names
81
+ # Turkish character normalization
82
+ turkish_map = {'ı': 'i', 'ğ': 'g', 'ü': 'u', 'ş': 's', 'ö': 'o', 'ç': 'c', 'İ': 'i', 'I': 'i'}
83
+
84
+ def normalize_turkish(text):
85
+ # First normalize Unicode (İ → i̇ → i)
86
+ import unicodedata
87
+ text = unicodedata.normalize('NFD', text)
88
+ text = ''.join(char for char in text if unicodedata.category(char) != 'Mn') # Remove diacritics
89
+
90
+ # Then Turkish character mapping
91
+ for tr_char, en_char in turkish_map.items():
92
+ text = text.replace(tr_char, en_char)
93
+ return text
94
+
95
+ # Remove common variations for better matching
96
+ normalized_search = normalize_turkish(search_name.replace('(2026)', '').replace('(2025)', '').replace(' - ', ' ').strip())
97
+ normalized_xml = normalize_turkish(xml_product_name.replace('(2026)', '').replace('(2025)', '').replace(' - ', ' ').strip())
98
+
99
+ # Extract core model name (e.g., "marlin 6 gen 3")
100
+ search_core = ' '.join(normalized_search.split()[:3]) # First 3 words
101
+ xml_core = ' '.join(normalized_xml.split()[:3]) # First 3 words
102
+
103
+ if (search_core in normalized_xml or
104
+ xml_core in normalized_search or
105
+ normalized_search in normalized_xml or
106
+ normalized_xml in normalized_search):
107
  warehouses = product.find('Warehouses')
108
  if warehouses is not None:
109
  warehouse_info = []