SamiKoen commited on
Commit
2695a95
·
verified ·
1 Parent(s): 4fa4ebe

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +25 -13
  2. test_context_aware.py +41 -0
app.py CHANGED
@@ -92,12 +92,16 @@ def get_warehouse_stock(product_name):
92
  variant_matches = []
93
  candidates = []
94
 
95
- # Check if this is a size/color specific query (like "M Turuncu")
96
- is_size_color_query = (len(search_words) <= 3 and
97
- any(word in ['s', 'm', 'l', 'xl', 'xs', 'small', 'medium', 'large',
98
- 'turuncu', 'siyah', 'beyaz', 'mavi', 'kirmizi', 'yesil',
99
- 'orange', 'black', 'white', 'blue', 'red', 'green']
100
- for word in search_words))
 
 
 
 
101
 
102
  # İlk geçiş: Variant alanında beden/renk araması
103
  if is_size_color_query:
@@ -107,14 +111,22 @@ def get_warehouse_stock(product_name):
107
 
108
  if product_name_elem is not None and product_name_elem.text:
109
  xml_product_name = product_name_elem.text.strip()
 
110
 
111
- # Variant field check
112
- if variant_elem is not None and variant_elem.text:
113
- variant_text = normalize_turkish(variant_elem.text.lower().replace('-', ' '))
114
-
115
- # Check if all search words are in variant field
116
- if all(word in variant_text for word in search_words):
117
- variant_matches.append((product, xml_product_name, variant_text))
 
 
 
 
 
 
 
118
 
119
  if variant_matches:
120
  candidates = variant_matches
 
92
  variant_matches = []
93
  candidates = []
94
 
95
+ # Separate size/color words from product words
96
+ size_color_words = ['s', 'm', 'l', 'xl', 'xs', 'small', 'medium', 'large',
97
+ 'turuncu', 'siyah', 'beyaz', 'mavi', 'kirmizi', 'yesil',
98
+ 'orange', 'black', 'white', 'blue', 'red', 'green']
99
+
100
+ variant_words = [word for word in search_words if word in size_color_words]
101
+ product_words = [word for word in search_words if word not in size_color_words]
102
+
103
+ # Check if this is a size/color specific query
104
+ is_size_color_query = len(variant_words) > 0 and len(search_words) <= 4
105
 
106
  # İlk geçiş: Variant alanında beden/renk araması
107
  if is_size_color_query:
 
111
 
112
  if product_name_elem is not None and product_name_elem.text:
113
  xml_product_name = product_name_elem.text.strip()
114
+ normalized_product_name = normalize_turkish(xml_product_name.lower())
115
 
116
+ # If there are product words, check if they match the product name
117
+ product_name_matches = True
118
+ if product_words:
119
+ product_name_matches = all(word in normalized_product_name for word in product_words)
120
+
121
+ # Only proceed if product name matches (or no product context)
122
+ if product_name_matches:
123
+ # Variant field check
124
+ if variant_elem is not None and variant_elem.text:
125
+ variant_text = normalize_turkish(variant_elem.text.lower().replace('-', ' '))
126
+
127
+ # Check if all variant words are in variant field
128
+ if all(word in variant_text for word in variant_words):
129
+ variant_matches.append((product, xml_product_name, variant_text))
130
 
131
  if variant_matches:
132
  candidates = variant_matches
test_context_aware.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # Test context-aware variant search
3
+
4
+ import sys
5
+ import os
6
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
7
+
8
+ # Import the updated function from app.py
9
+ from app import get_warehouse_stock
10
+
11
+ if __name__ == "__main__":
12
+ test_cases = [
13
+ "M Turuncu", # Should find all M Turuncu variants
14
+ "Marlin 6 M Turuncu", # Should find only Marlin 6 M Turuncu variants
15
+ "Marlin M Turuncu", # Should find only Marlin M Turuncu variants
16
+ "L Siyah", # Should find all L Siyah variants
17
+ "Marlin 6 L Siyah" # Should find only Marlin 6 L Siyah variants
18
+ ]
19
+
20
+ for test_case in test_cases:
21
+ print(f"\n=== Testing: {test_case} ===")
22
+ try:
23
+ result = get_warehouse_stock(test_case)
24
+ if result:
25
+ print("Sonuç:")
26
+ total_stock = 0
27
+ for item in result:
28
+ print(f" • {item}")
29
+ # Extract stock count for total
30
+ if ": " in item and " adet" in item:
31
+ stock_part = item.split(": ")[1].replace(" adet", "")
32
+ try:
33
+ total_stock += int(stock_part)
34
+ except:
35
+ pass
36
+ print(f"TOPLAM: {total_stock} adet")
37
+ else:
38
+ print("Sonuç bulunamadı")
39
+ except Exception as e:
40
+ print(f"Hata: {e}")
41
+ print("-" * 50)