Spaces:
Sleeping
Sleeping
Upload Code_files/uslap.py with huggingface_hub
Browse files- Code_files/uslap.py +24 -23
Code_files/uslap.py
CHANGED
|
@@ -158,8 +158,11 @@ def query(text):
|
|
| 158 |
"""Run a single query through the AMR pipeline. Returns formatted string.
|
| 159 |
|
| 160 |
PRIORITY:
|
| 161 |
-
1. Search DB. If found, return DB data.
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
Fixed 2026-03-29: was going straight to think() and skipping
|
| 165 |
handler.search(), which meant indexed entries (scholars, peoples,
|
|
@@ -167,6 +170,9 @@ def query(text):
|
|
| 167 |
|
| 168 |
Fixed 2026-04-02: tasrif now routes through dhakaa pipeline
|
| 169 |
(perceive β reason β articulate) instead of bypass.
|
|
|
|
|
|
|
|
|
|
| 170 |
"""
|
| 171 |
from uslap_handler import search
|
| 172 |
|
|
@@ -174,12 +180,8 @@ def query(text):
|
|
| 174 |
search_result = search(text)
|
| 175 |
|
| 176 |
if search_result['found'] and search_result['nodes']:
|
| 177 |
-
# Found in DB β
|
| 178 |
-
# But ALSO run through think() for root computation
|
| 179 |
-
# The DB data takes priority in the output
|
| 180 |
lines = []
|
| 181 |
-
|
| 182 |
-
# Group by source table
|
| 183 |
by_table = {}
|
| 184 |
for node in search_result['nodes']:
|
| 185 |
tbl = node['source_table']
|
|
@@ -193,31 +195,30 @@ def query(text):
|
|
| 193 |
|
| 194 |
for tbl, nodes in by_table.items():
|
| 195 |
lines.append(f"β [{tbl}]:")
|
| 196 |
-
for n in nodes[:10]:
|
| 197 |
term = n['term'] if isinstance(n, dict) else n[1]
|
| 198 |
score = n['score'] if isinstance(n, dict) else n[7]
|
| 199 |
src_id = n['source_id'] if isinstance(n, dict) else n[5]
|
| 200 |
lines.append(f"β {term} (id={src_id}, score={score})")
|
| 201 |
|
| 202 |
lines.append("β" + "β" * 58 + "β")
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
# Step 2: Also run AMR computation for root analysis
|
| 207 |
-
from amr_dhakaa import think
|
| 208 |
-
result = think(text)
|
| 209 |
-
amr_output = result['output']
|
| 210 |
-
|
| 211 |
-
# Don't append "No entries found" if DB already returned results
|
| 212 |
-
if 'No entries found' in amr_output:
|
| 213 |
-
return db_output
|
| 214 |
-
else:
|
| 215 |
-
return db_output + '\n\n' + amr_output
|
| 216 |
-
|
| 217 |
-
# Not found in DB β fall through to AMR computation only
|
| 218 |
from amr_dhakaa import think
|
| 219 |
result = think(text)
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
|
| 223 |
def full_report(text):
|
|
|
|
| 158 |
"""Run a single query through the AMR pipeline. Returns formatted string.
|
| 159 |
|
| 160 |
PRIORITY:
|
| 161 |
+
1. Search DB (term_nodes index). If found, return DB data only.
|
| 162 |
+
Do NOT append hypothesis output to a DB hit.
|
| 163 |
+
2. If input is transliterated AA (Latin chars), attempt root lookup
|
| 164 |
+
via transliteration map before falling to hypothesis mode.
|
| 165 |
+
3. Not found β return NOT_FOUND string (no hypothesis generation).
|
| 166 |
|
| 167 |
Fixed 2026-03-29: was going straight to think() and skipping
|
| 168 |
handler.search(), which meant indexed entries (scholars, peoples,
|
|
|
|
| 170 |
|
| 171 |
Fixed 2026-04-02: tasrif now routes through dhakaa pipeline
|
| 172 |
(perceive β reason β articulate) instead of bypass.
|
| 173 |
+
|
| 174 |
+
Fixed 2026-04-15: DB hits no longer trigger hypothesis append.
|
| 175 |
+
Transliterated AA queries route to root lookup, not hypothesis.
|
| 176 |
"""
|
| 177 |
from uslap_handler import search
|
| 178 |
|
|
|
|
| 180 |
search_result = search(text)
|
| 181 |
|
| 182 |
if search_result['found'] and search_result['nodes']:
|
| 183 |
+
# Found in DB β return DB data ONLY. No hypothesis appended.
|
|
|
|
|
|
|
| 184 |
lines = []
|
|
|
|
|
|
|
| 185 |
by_table = {}
|
| 186 |
for node in search_result['nodes']:
|
| 187 |
tbl = node['source_table']
|
|
|
|
| 195 |
|
| 196 |
for tbl, nodes in by_table.items():
|
| 197 |
lines.append(f"β [{tbl}]:")
|
| 198 |
+
for n in nodes[:10]:
|
| 199 |
term = n['term'] if isinstance(n, dict) else n[1]
|
| 200 |
score = n['score'] if isinstance(n, dict) else n[7]
|
| 201 |
src_id = n['source_id'] if isinstance(n, dict) else n[5]
|
| 202 |
lines.append(f"β {term} (id={src_id}, score={score})")
|
| 203 |
|
| 204 |
lines.append("β" + "β" * 58 + "β")
|
| 205 |
+
return '\n'.join(lines)
|
| 206 |
|
| 207 |
+
# Step 2: transliterated AA? attempt root lookup via dhakaa perceive layer
|
| 208 |
+
# before allowing hypothesis generation. dhakaa handles intent routing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
from amr_dhakaa import think
|
| 210 |
result = think(text)
|
| 211 |
+
output = result.get('output', '')
|
| 212 |
+
|
| 213 |
+
# Step 3: if dhakaa produced only hypothesis output, suppress it.
|
| 214 |
+
# "Not found in DB" is the correct answer β hypothesis is unconfirmed.
|
| 215 |
+
# The hypothesis block can start on line 1 or line 2 (after a βββ border).
|
| 216 |
+
output_lines = output.splitlines()
|
| 217 |
+
for line in output_lines[:4]:
|
| 218 |
+
if 'HYPOTHESIS:' in line:
|
| 219 |
+
return f"Not found in DB: '{text}'"
|
| 220 |
+
|
| 221 |
+
return output
|
| 222 |
|
| 223 |
|
| 224 |
def full_report(text):
|