Spaces:
Sleeping
Sleeping
File size: 3,287 Bytes
8e27da5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | #!/usr/bin/env python3
"""
Test the new professional multi-filter NLP engine
Run: python test_nlp_engine.py
"""
import sys
sys.path.insert(0, '/c/Users/barat/OneDrive/Desktop/model/plate-detector')
from database import FilterExtractor, ask_llm
def test_filter_extraction():
"""Test filter extraction from various queries"""
extractor = FilterExtractor()
test_cases = [
{
"query": "show TN buses in adyar on monday",
"expected": {
"state": "TN",
"vehicle_type": "bus",
"location": "adyar",
"day": "Monday"
}
},
{
"query": "track TN63MB3157 in guindy",
"expected": {
"plate": "TN63MB3157",
"location": "guindy"
}
},
{
"query": "show bikes on weekend",
"expected": {
"vehicle_type": "bike",
"day": ["Saturday", "Sunday"]
}
},
{
"query": "count TN trucks in velachery on 2026-05-04",
"expected": {
"state": "TN",
"vehicle_type": "truck",
"location": "velachery",
"date": "2026-05-04"
}
},
{
"query": "buses on friday",
"expected": {
"vehicle_type": "bus",
"day": "Friday"
}
}
]
print("\n" + "="*60)
print("FILTER EXTRACTION TESTS")
print("="*60)
for i, test in enumerate(test_cases, 1):
query = test["query"]
expected = test["expected"]
filters = extractor.extract_filters(query)
print(f"\nβ Test {i}: {query}")
print(f" Extracted: {filters}")
# Check key filters
for key, value in expected.items():
if filters.get(key) == value:
print(f" β
{key}: {value}")
else:
print(f" β {key}: expected {value}, got {filters.get(key)}")
def test_sql_generation():
"""Test SQL generation from various queries"""
print("\n" + "="*60)
print("SQL GENERATION TESTS")
print("="*60)
test_queries = [
"show TN buses in adyar on monday",
"track TN63MB3157 in adyar",
"count bikes in velachery",
"show trucks in guindy on 2026-05-04",
"buses on friday",
"show vehicles on weekend",
"top vehicles",
"hourly traffic",
]
for query in test_queries:
print(f"\nπ Query: {query}")
sql = ask_llm(query)
print(f"π SQL:\n{sql}")
# Validate
if "SELECT" in sql and "vehicle_logs" in sql:
print("β
Valid SQL generated")
else:
print("β Invalid SQL!")
if __name__ == "__main__":
try:
print("\nπ§ͺ TESTING PROFESSIONAL MULTI-FILTER NLP ENGINE\n")
test_filter_extraction()
test_sql_generation()
print("\n" + "="*60)
print("β
ALL TESTS COMPLETED")
print("="*60 + "\n")
except Exception as e:
print(f"\nβ Test failed: {e}")
import traceback
traceback.print_exc()
|