LoloSemper commited on
Commit
01da41d
·
verified ·
1 Parent(s): d844149

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -86,11 +86,17 @@ def from_custom_b64(s: str, alphabet: str) -> bytes:
86
  trans = str.maketrans(alphabet, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
87
  std = s.translate(trans); pad = "=" * ((4 - len(std) % 4) % 4)
88
  return base64.b64decode(std + pad)
89
- def enc_oov_minimax(token: str) -> str: return "~" + to_custom_b64(token.encode("utf-8"), ALPHA_MINI64)
 
 
 
 
90
  def dec_oov_minimax(code: str) -> str:
91
  try: return from_custom_b64(code[1:], ALPHA_MINI64).decode("utf-8")
92
  except Exception: return code
93
- def enc_oov_komin(token: str) -> str: return "「" + to_custom_b64(token.encode("utf-8"), ALPHA_CJK64) + "」"
 
 
94
  def dec_oov_komin(code: str) -> str:
95
  try: return from_custom_b64(code[1:-1], ALPHA_CJK64).decode("utf-8")
96
  except Exception: return code
@@ -108,11 +114,18 @@ try:
108
  except Exception:
109
  nlp_es = nlp_en = None
110
 
 
111
  def lemma_of(tok, src_lang: str) -> str:
112
- if src_lang == "Español":
113
- return norm_es(tok.lemma_ if getattr(tok,"lemma_","") else tok.text)
114
- else:
115
- return norm_en(tok.lemma_ if getattr(tok,"lemma_","") else tok.text)
 
 
 
 
 
 
116
 
117
  # ------------ Detección simple y helpers ------------
118
  def detect_polarity(doc) -> bool: return "?" in getattr(doc,"text","")
@@ -194,6 +207,9 @@ def realize_minimax(doc, src_lang: str, drop_articles=True, zero_copula=True,
194
  root, subs, objs, obls, advs = extract_core(doc)
195
  tense = detect_tense(root); is_q, is_neg = detect_polarity(doc), detect_neg(doc)
196
  vlem = lemma_of(root, src_lang) if USE_SPACY else ("ser" if "?" in getattr(doc,"text","") else "estar")
 
 
 
197
  vcode = code_es(vlem, "Minimax-ASCII") if src_lang=="Español" else code_en(vlem, "Minimax-ASCII")
198
  tail = TAM_MINI.get(tense, "P")
199
  if semi_lossless: tail += (detect_person(root, src_lang) or person_hint)
@@ -225,6 +241,9 @@ def realize_komin(doc, src_lang: str, drop_articles=True, zero_copula=True,
225
  root, subs, objs, obls, advs = extract_core(doc)
226
  tense, is_q, is_neg = detect_tense(root), detect_polarity(doc), detect_neg(doc)
227
  vlem = lemma_of(root, src_lang) if USE_SPACY else ("ser" if "?" in getattr(doc,"text","") else "estar")
 
 
 
228
  vcode = code_es(vlem, "Kōmín-CJK") if src_lang=="Español" else code_en(vlem, "Kōmín-CJK")
229
  P_SUBJ, P_OBJ = "ᵖ", "ᵒ"; Q_FIN = "?"
230
  TAM = TAM_KOMI.get(tense,"Ⓟ")
@@ -517,7 +536,7 @@ Ambos son “**conlangs**” pensados para **ahorrar espacio** y permitir **deco
517
  # EN
518
  EXPLAIN_TAB_TRANSLATE_EN = "Converts **Text → Target** (ES/EN/Minimax/Kōmín). With **Max Exact**, adds `~...` to recover the **exact original**. Compaction checkboxes apply only when **Target is conlang**."
519
  EXPLAIN_TAB_BUILD_EN = "Forces **conlang output** (Minimax/Kōmín) from ES/EN, applying phrasing rules and compaction options."
520
- EXPLAIN_TAB_DECODE_EN = "Converts **Minimax/Kōmín → ES/EN**. If `~...` exists, returns the bit-perfect original; else semi-lossless."
521
  EXPLAIN_TAB_ROUNDTRIP_EN = "Runs **(ES/EN→Conlang)→(Conlang→ES/EN)** to verify reversibility; with exact, it’s bit-for-bit."
522
  EXPLAIN_CHECKBOX_EN = "Drop articles ~10–15%, Zero copula ~5–10% extra, Remove pronouns variable, Max Exact 40–60% for >100 chars."
523
  EXPLAIN_CONLANGS_EN = """
 
86
  trans = str.maketrans(alphabet, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
87
  std = s.translate(trans); pad = "=" * ((4 - len(std) % 4) % 4)
88
  return base64.b64decode(std + pad)
89
+
90
+ # --- PATCH: evitar OOV vacío ---
91
+ def enc_oov_minimax(token: str) -> str:
92
+ t = token if token else "_" # evita cadena vacía
93
+ return "~" + to_custom_b64(t.encode("utf-8"), ALPHA_MINI64)
94
  def dec_oov_minimax(code: str) -> str:
95
  try: return from_custom_b64(code[1:], ALPHA_MINI64).decode("utf-8")
96
  except Exception: return code
97
+ def enc_oov_komin(token: str) -> str:
98
+ t = token if token else "_" # evita cadena vacía
99
+ return "「" + to_custom_b64(t.encode("utf-8"), ALPHA_CJK64) + "」"
100
  def dec_oov_komin(code: str) -> str:
101
  try: return from_custom_b64(code[1:-1], ALPHA_CJK64).decode("utf-8")
102
  except Exception: return code
 
114
  except Exception:
115
  nlp_es = nlp_en = None
116
 
117
+ # --- PATCH: lemma_of siempre devuelve algo no vacío ---
118
  def lemma_of(tok, src_lang: str) -> str:
119
+ raw = (tok.lemma_ if getattr(tok, "lemma_", None) else getattr(tok, "text", "")) or ""
120
+ norm = norm_es(raw) if src_lang == "Español" else norm_en(raw)
121
+ if norm:
122
+ return norm
123
+ # Fallback 1: normalizar el texto original
124
+ txt = norm_es(getattr(tok, "text", "")) if src_lang == "Español" else norm_en(getattr(tok, "text", ""))
125
+ if txt:
126
+ return txt
127
+ # Fallback 2: verbo seguro para no dejar vacío
128
+ return "ser" if src_lang == "Español" else "be"
129
 
130
  # ------------ Detección simple y helpers ------------
131
  def detect_polarity(doc) -> bool: return "?" in getattr(doc,"text","")
 
207
  root, subs, objs, obls, advs = extract_core(doc)
208
  tense = detect_tense(root); is_q, is_neg = detect_polarity(doc), detect_neg(doc)
209
  vlem = lemma_of(root, src_lang) if USE_SPACY else ("ser" if "?" in getattr(doc,"text","") else "estar")
210
+ # --- PATCH: si vlem viene vacío, fallback a verbo seguro ---
211
+ if not vlem:
212
+ vlem = "ser" if src_lang == "Español" else "be"
213
  vcode = code_es(vlem, "Minimax-ASCII") if src_lang=="Español" else code_en(vlem, "Minimax-ASCII")
214
  tail = TAM_MINI.get(tense, "P")
215
  if semi_lossless: tail += (detect_person(root, src_lang) or person_hint)
 
241
  root, subs, objs, obls, advs = extract_core(doc)
242
  tense, is_q, is_neg = detect_tense(root), detect_polarity(doc), detect_neg(doc)
243
  vlem = lemma_of(root, src_lang) if USE_SPACY else ("ser" if "?" in getattr(doc,"text","") else "estar")
244
+ # --- PATCH: si vlem viene vacío, fallback a verbo seguro ---
245
+ if not vlem:
246
+ vlem = "ser" if src_lang == "Español" else "be"
247
  vcode = code_es(vlem, "Kōmín-CJK") if src_lang=="Español" else code_en(vlem, "Kōmín-CJK")
248
  P_SUBJ, P_OBJ = "ᵖ", "ᵒ"; Q_FIN = "?"
249
  TAM = TAM_KOMI.get(tense,"Ⓟ")
 
536
  # EN
537
  EXPLAIN_TAB_TRANSLATE_EN = "Converts **Text → Target** (ES/EN/Minimax/Kōmín). With **Max Exact**, adds `~...` to recover the **exact original**. Compaction checkboxes apply only when **Target is conlang**."
538
  EXPLAIN_TAB_BUILD_EN = "Forces **conlang output** (Minimax/Kōmín) from ES/EN, applying phrasing rules and compaction options."
539
+ EXPLAIN_TAB_DECODE_EN = "Converts **Minimax/Kōmín → ES/EN**. If `~...`, returns the bit-perfect original; else semi-lossless."
540
  EXPLAIN_TAB_ROUNDTRIP_EN = "Runs **(ES/EN→Conlang)→(Conlang→ES/EN)** to verify reversibility; with exact, it’s bit-for-bit."
541
  EXPLAIN_CHECKBOX_EN = "Drop articles ~10–15%, Zero copula ~5–10% extra, Remove pronouns variable, Max Exact 40–60% for >100 chars."
542
  EXPLAIN_CONLANGS_EN = """