uslap commited on
Commit
6676227
Β·
verified Β·
1 Parent(s): 5e1cd08

Upload Code_files/uslap.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. Code_files/uslap.py +34 -6
Code_files/uslap.py CHANGED
@@ -204,19 +204,47 @@ def query(text):
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
 
 
204
  lines.append("β•š" + "═" * 58 + "╝")
205
  return '\n'.join(lines)
206
 
207
+ # Step 2: check if the intent is a structural query (tasrif, intel, explain,
208
+ # compare, state, quf) β€” these route through think() regardless of DB hit.
209
+ stripped = text.strip().lower()
210
+ structural_prefixes = (
211
+ 'tasrif', 'intel ', 'explain ', 'compare ', '--state',
212
+ '--quf', '--batch', 'bitig tasrif',
213
+ )
214
+ is_structural = any(stripped.startswith(p) for p in structural_prefixes)
215
+
216
+ if is_structural:
217
+ from amr_dhakaa import think
218
+ result = think(text)
219
+ return result.get('output', '')
220
+
221
+ # Step 3: plain word lookup β€” check entries table directly before running
222
+ # the full hypothesis engine. If the word has no confirmed entry, stop here.
223
+ # Hypothesis mode is for local development only, not public output.
224
+ import sqlite3
225
+ db_path = os.path.join(os.path.dirname(__file__), 'uslap_database_v3.db')
226
+ word = stripped.replace('trace ', '').strip()
227
+ try:
228
+ conn = sqlite3.connect(db_path)
229
+ hit = conn.execute(
230
+ "SELECT entry_id FROM entries WHERE LOWER(en_term) = ? LIMIT 1",
231
+ (word,)
232
+ ).fetchone()
233
+ conn.close()
234
+ if not hit:
235
+ return f"Not found in DB: '{word}'"
236
+ except Exception:
237
+ pass
238
+
239
  from amr_dhakaa import think
240
  result = think(text)
241
  output = result.get('output', '')
242
 
243
+ # Final safety: block any hypothesis that slipped through.
 
 
244
  output_lines = output.splitlines()
245
  for line in output_lines[:4]:
246
  if 'HYPOTHESIS:' in line:
247
+ return f"Not found in DB: '{word}'"
248
 
249
  return output
250