Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -192,13 +192,27 @@ COLUMN_SYNONYMS = {
|
|
192 |
|
193 |
|
194 |
# Helper function to map user query terms to dataset columns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
def map_query_to_column(query):
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
return col
|
200 |
return None
|
201 |
|
|
|
202 |
# Visualization generator with synonym handling
|
203 |
def generate_visual_from_query(query, df):
|
204 |
try:
|
|
|
192 |
|
193 |
|
194 |
# Helper function to map user query terms to dataset columns
|
195 |
+
#def map_query_to_column(query):
|
196 |
+
# for col, synonyms in COLUMN_SYNONYMS.items():
|
197 |
+
# for term in synonyms:
|
198 |
+
# if term in query:
|
199 |
+
# return col
|
200 |
+
# return None
|
201 |
+
|
202 |
def map_query_to_column(query):
|
203 |
+
query = query.lower()
|
204 |
+
all_synonyms = {synonym: col for col, synonyms in COLUMN_SYNONYMS.items() for synonym in synonyms}
|
205 |
+
matches = get_close_matches(query, all_synonyms.keys(), n=1, cutoff=0.6)
|
206 |
+
|
207 |
+
if matches:
|
208 |
+
return all_synonyms[matches[0]]
|
209 |
+
else:
|
210 |
+
for col, synonyms in COLUMN_SYNONYMS.items():
|
211 |
+
if any(term in query for term in synonyms):
|
212 |
return col
|
213 |
return None
|
214 |
|
215 |
+
|
216 |
# Visualization generator with synonym handling
|
217 |
def generate_visual_from_query(query, df):
|
218 |
try:
|