bep40 commited on
Commit
bd7fab4
·
verified ·
1 Parent(s): 54e7394

Fixed technical_specs extraction and updated dataset schema with technical_specs column

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -288,27 +288,27 @@ def extract_technical_specs_from_text(text):
288
  if not text:
289
  return ""
290
  tech_patterns = [
291
- r'Kích thước[^::]*[::]?\s*(.+?)(?:\n|Kích thước|Chất liệu|Trọng|lượng|Bảo hành|màu sắc|Điện|ánh sáng|Nguồn|dòng sản phẩm|Dòng SP|Dòng|$)',
292
- r'Chất liệu[^::]*[::]?\s*(.+?)(?:\n|Kích thước|Chất liệu|Trọng|lượng|Bảo hành|màu sắc|$)',
293
- r'Trọng lượng[^::]*[::]?\s*(.+?)(?:\n|Kích thước|Chất liệu|Trọng|lượng|Bảo hành|màu sắc|$)',
294
- r'Chiều rộng[^::]*[::]?\s*(.+?)(?:\n|$)',
295
- r'Chiều dài[^::]*[::]?\s*(.+?)(?:\n|$)',
296
- r'Chiều cao[^::]*[::]?\s*(.+?)(?:\n|$)',
297
- r'Khoảng cách[^::]*[::]?\s*(.+?)(?:\n|$)',
298
- r'Bảo hành[^::]*[::]?\s*(.+?)(?:\n|$)',
299
- r'Màu sắc[^::]*[::]?\s*(.+?)(?:\n|$)',
300
- r'Trong lượng[^::]*[::]?\s*(.+?)(?:\n|$)',
301
  ]
302
  specs = []
303
- for pattern in tech_patterns:
304
- matches = re.findall(pattern, text, re.IGNORECASE | re.DOTALL)
305
- for m in matches:
306
- spec = m.strip() if isinstance(m, str) else m[0].strip() if m else ""
307
- if spec and not _is_nan_value(spec):
308
- specs.append(spec)
 
 
 
309
  return "\n".join(specs)[:500] if specs else ""
310
 
311
-
312
  def _save_text_message_to_dataset(text, description, price, category, sender_id, sender_name, chat_id):
313
  """Save a text-only message to the main Zalo products dataset."""
314
  try:
 
288
  if not text:
289
  return ""
290
  tech_patterns = [
291
+ (r'Kích thước[^::]*[::]?\s*(.+?)(?:;|Chất liệu|Dòng sản phẩm|Bảo hành|Màu sắc|Khoang tủ|Chiều|$)', "Kích thước"),
292
+ (r'Chất liệu[^::]*[::]?\s*(.+?)(?:;|Kích thưỏi|Dòng sản phẩm|Bảo hành|Màu sắc|$)', "Chất liệu"),
293
+ (r'Dòng sản phẩm[^::]*[::]?\s*(.+?)(?:;|Kích thưỏi|Chất liệu|$)', "Dòng sản phẩm"),
294
+ (r'Chiều rộng tủ[^::]*[::]?\s*(.+?)(?:\n|$)', "Chiều rộng tủ"),
295
+ (r'Khoang tủ[^::]*[::]?\s*(.+?)(?:;|Kích thưỏi|Chất liệu|Chiều|$)', "Khoang tủ"),
296
+ (r'Bảo hành[^::]*[::]?\s*(.+?)(?:\n|$)', "Bảo hành"),
297
+ (r'Trọng lượng[^::]*[::]?\s*(.+?)(?:\n|$)', "Trọng lượng"),
298
+ (r'Màu sắc[^::]*[::]?\s*(.+?)(?:\n|$)', "Màu sắc"),
 
 
299
  ]
300
  specs = []
301
+ seen = set()
302
+ for pattern, label in tech_patterns:
303
+ match = re.search(pattern, text, re.IGNORECASE | re.DOTALL)
304
+ if match:
305
+ value = match.group(1).strip()
306
+ if value and label.lower() not in seen:
307
+ value = value.rstrip(';').strip()
308
+ specs.append(f"{label}: {value}")
309
+ seen.add(label.lower())
310
  return "\n".join(specs)[:500] if specs else ""
311
 
 
312
  def _save_text_message_to_dataset(text, description, price, category, sender_id, sender_name, chat_id):
313
  """Save a text-only message to the main Zalo products dataset."""
314
  try: