Paul720810 commited on
Commit
c874296
·
verified ·
1 Parent(s): eb6b709

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -487,7 +487,7 @@ class TextToSQLSystem:
487
  def _validate_and_fix_sql(self, question: str, raw_response: str) -> Tuple[Optional[str], str]:
488
  """
489
  (V23 / 统一实体识别版)
490
- 一个全面、多层次的 SQL 验证与生成引擎。
491
  引入了全新的、统一的实体识别引擎,能够准确解析 "买家 Gap", "c0761n",
492
  "买家ID c0761n" 等多种复杂的实体提问模式。
493
  """
@@ -528,12 +528,12 @@ class TextToSQLSystem:
528
  "column": p['column']
529
  }
530
  break
531
-
532
  # --- 预先检测其他意图 ---
533
  job_no_match = re.search(r"(?:工單|jobno)\s*'\"?([A-Z]{2,3}\d+)'\"?", question, re.IGNORECASE)
534
 
535
  # --- 判断逻辑: 依优先级进入对应的模板 ---
536
- if any(kw in q_lower for kw in ['報告號碼', '報告清單', '列出報告']):
537
  year_match = re.search(r'(\d{4})\s*年?', question)
538
  month_match = re.search(r'(\d{1,2})\s*月', question)
539
  from_clause = "FROM JobTimeline AS jt"
@@ -583,6 +583,12 @@ class TextToSQLSystem:
583
  fixed_sql = " " + parsed_sql.strip() + " "
584
  fixes_applied_fallback = []
585
 
 
 
 
 
 
 
586
  schema_corrections = {'TSR53Report':'TSR53SampleDescription', 'TSR53InvoiceReportNo':'JobNo', 'TSR53ReportNo':'JobNo', 'TSR53InvoiceNo':'JobNo', 'TSR53InvoiceCreditNoteNo':'InvoiceCreditNoteNo', 'TSR53InvoiceLocalAmount':'LocalAmount', 'Status':'OverallRating', 'ReportStatus':'OverallRating'}
587
  for wrong, correct in schema_corrections.items():
588
  pattern = r'\b' + re.escape(wrong) + r'\b'
 
487
  def _validate_and_fix_sql(self, question: str, raw_response: str) -> Tuple[Optional[str], str]:
488
  """
489
  (V23 / 统一实体识别版)
490
+ 一個全面、多層次的 SQL 驗證與生成引擎。
491
  引入了全新的、统一的实体识别引擎,能够准确解析 "买家 Gap", "c0761n",
492
  "买家ID c0761n" 等多种复杂的实体提问模式。
493
  """
 
528
  "column": p['column']
529
  }
530
  break
531
+
532
  # --- 预先检测其他意图 ---
533
  job_no_match = re.search(r"(?:工單|jobno)\s*'\"?([A-Z]{2,3}\d+)'\"?", question, re.IGNORECASE)
534
 
535
  # --- 判断逻辑: 依优先级进入对应的模板 ---
536
+ if any(kw in q_lower for kw in ['報告號碼', '報告清單', '列出報告', 'report number', 'list of reports']):
537
  year_match = re.search(r'(\d{4})\s*年?', question)
538
  month_match = re.search(r'(\d{1,2})\s*月', question)
539
  from_clause = "FROM JobTimeline AS jt"
 
583
  fixed_sql = " " + parsed_sql.strip() + " "
584
  fixes_applied_fallback = []
585
 
586
+ dialect_corrections = {r'YEAR\s*\(([^)]+)\)': r"strftime('%Y', \1)"}
587
+ for pattern, replacement in dialect_corrections.items():
588
+ if re.search(pattern, fixed_sql, re.IGNORECASE):
589
+ fixed_sql = re.sub(pattern, replacement, fixed_sql, flags=re.IGNORECASE)
590
+ fixes_applied_fallback.append(f"修正方言: {pattern}")
591
+
592
  schema_corrections = {'TSR53Report':'TSR53SampleDescription', 'TSR53InvoiceReportNo':'JobNo', 'TSR53ReportNo':'JobNo', 'TSR53InvoiceNo':'JobNo', 'TSR53InvoiceCreditNoteNo':'InvoiceCreditNoteNo', 'TSR53InvoiceLocalAmount':'LocalAmount', 'Status':'OverallRating', 'ReportStatus':'OverallRating'}
593
  for wrong, correct in schema_corrections.items():
594
  pattern = r'\b' + re.escape(wrong) + r'\b'