bhavika24 commited on
Commit
484dcc5
·
verified ·
1 Parent(s): 2c656c5

Upload engine.py

Browse files
Files changed (1) hide show
  1. engine.py +18 -25
engine.py CHANGED
@@ -329,51 +329,44 @@ def normalize_time_question(q):#total-actual date
329
 
330
  def is_question_supported(question):
331
  q = question.lower()
332
- tokens = set(q.replace("?", "").replace(",", "").split())
333
 
334
- # 1️⃣ Allow analytical intent even without table names
335
- analytic_keywords = {
336
  "count", "total", "average", "avg", "sum",
337
- "how many", "number of", "trend",
338
- "increase", "decrease", "compare", "more than", "less than"
339
- }
 
 
340
 
341
  if any(k in q for k in analytic_keywords):
342
  return True
343
 
344
- # 2️⃣ Check schema relevance (table-by-table)
345
  schema = load_ai_schema()
346
 
347
  for table, meta in schema.items():
348
- score = 0
349
  table_l = table.lower()
350
 
351
- # Table name match
352
  if table_l in q:
353
- score += 3
354
 
355
- # Column name match
356
  for col, desc in meta["columns"].items():
357
- col_l = col.lower()
358
- if col_l in q:
359
- score += 2
360
- elif any(tok in col_l for tok in tokens):
361
- score += 1
362
-
363
- # Description match
364
- if meta.get("description"):
365
- desc_tokens = set(col_desc(meta["description"]).lower().split())
366
 
367
- score += len(tokens & desc_tokens)
368
-
369
- # ✅ If any table is relevant enough → supported
370
- if score >= 2:
371
- return True
372
 
373
  return False
374
 
375
 
376
 
 
377
  # =========================
378
  # SQL GENERATION
379
  # =========================
 
329
 
330
  def is_question_supported(question):
331
  q = question.lower()
 
332
 
333
+ # 1️⃣ Always allow analytical / time-based queries
334
+ analytic_keywords = [
335
  "count", "total", "average", "avg", "sum",
336
+ "how many", "number of",
337
+ "trend", "increase", "decrease", "compare",
338
+ "last", "latest", "recent", "past",
339
+ "day", "days", "month", "year"
340
+ ]
341
 
342
  if any(k in q for k in analytic_keywords):
343
  return True
344
 
345
+ # 2️⃣ Schema-based relevance check
346
  schema = load_ai_schema()
347
 
348
  for table, meta in schema.items():
 
349
  table_l = table.lower()
350
 
351
+ # Table name mentioned
352
  if table_l in q:
353
+ return True
354
 
355
+ # Column or description match
356
  for col, desc in meta["columns"].items():
357
+ if col.lower() in q:
358
+ return True
 
 
 
 
 
 
 
359
 
360
+ if isinstance(desc, str) and any(
361
+ word in desc.lower() for word in q.split()
362
+ ):
363
+ return True
 
364
 
365
  return False
366
 
367
 
368
 
369
+
370
  # =========================
371
  # SQL GENERATION
372
  # =========================