Update app.py
Browse files
app.py
CHANGED
|
@@ -386,7 +386,7 @@ def extract_custom_sidecar(text: str) -> Optional[str]:
|
|
| 386 |
def strip_custom_sidecar(text: str) -> str:
|
| 387 |
return text.split('~')[0].rstrip() if '~' in text else text
|
| 388 |
|
| 389 |
-
# ------------ Codificar / Decodificar
|
| 390 |
def encode_simple(text: str, src_lang: str, target: str) -> str:
|
| 391 |
if not text.strip(): return ""
|
| 392 |
def repl_es(m):
|
|
@@ -499,46 +499,36 @@ def decode_simple(text: str, source: str, tgt_lang: str) -> str:
|
|
| 499 |
lemma_tokens.append(w)
|
| 500 |
pl_flags.append(had_pl)
|
| 501 |
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
O_ADV.append(O)
|
| 533 |
-
O_ADV.extend([pluralize(post_v[k], tgt_lang) if pl_post[k] else post_v[k] for k in range(1, len(post_v))])
|
| 534 |
-
|
| 535 |
-
parts = [p for p in [S, v_conj] + O_ADV if p]
|
| 536 |
-
out_text = " ".join(parts)
|
| 537 |
-
|
| 538 |
-
# Wh en Q: si primer token es wh, muévelo al frente
|
| 539 |
-
if has_q and lemma_tokens and lemma_tokens[0].lower() in {"como", "cómo", "what", "how"}:
|
| 540 |
-
wh = lemma_tokens.pop(0)
|
| 541 |
-
out_text = f"{wh} {out_text}"
|
| 542 |
|
| 543 |
# Pregunta
|
| 544 |
if has_q:
|
|
|
|
| 386 |
def strip_custom_sidecar(text: str) -> str:
|
| 387 |
return text.split('~')[0].rstrip() if '~' in text else text
|
| 388 |
|
| 389 |
+
# ------------ Codificar / Decodificar léxisco puro ------------
|
| 390 |
def encode_simple(text: str, src_lang: str, target: str) -> str:
|
| 391 |
if not text.strip(): return ""
|
| 392 |
def repl_es(m):
|
|
|
|
| 499 |
lemma_tokens.append(w)
|
| 500 |
pl_flags.append(had_pl)
|
| 501 |
|
| 502 |
+
out_parts = []
|
| 503 |
+
greeting = None
|
| 504 |
+
wh = None
|
| 505 |
+
for idx, lem in enumerate(lemma_tokens):
|
| 506 |
+
if idx == verb_idx:
|
| 507 |
+
conj_func = _es_conj if tgt_lang == "Español" else _en_conj
|
| 508 |
+
v_conj = conj_func(verb_lemma, verb_tense, verb_person)
|
| 509 |
+
if is_neg:
|
| 510 |
+
neg_prefix = "no " if tgt_lang == "Español" else "not "
|
| 511 |
+
v_conj = neg_prefix + v_conj
|
| 512 |
+
out_parts.append(v_conj)
|
| 513 |
+
continue
|
| 514 |
+
|
| 515 |
+
w = pluralize(lem, tgt_lang) if pl_flags[idx] else lem
|
| 516 |
+
if w.lower() in {"hola", "hello", "hi", "hey"}:
|
| 517 |
+
greeting = w
|
| 518 |
+
elif w.lower() in {"como", "cómo", "what", "how"} and has_q:
|
| 519 |
+
wh = w
|
| 520 |
+
else:
|
| 521 |
+
out_parts.append(w)
|
| 522 |
+
|
| 523 |
+
# Reorden: Greeting + wh + S V O ADV
|
| 524 |
+
final_out = []
|
| 525 |
+
if greeting:
|
| 526 |
+
final_out.append(greeting)
|
| 527 |
+
if wh:
|
| 528 |
+
final_out.append(wh)
|
| 529 |
+
final_out += out_parts
|
| 530 |
+
|
| 531 |
+
out_text = " ".join(final_out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
|
| 533 |
# Pregunta
|
| 534 |
if has_q:
|