LoloSemper commited on
Commit
fb1b4eb
·
verified ·
1 Parent(s): 3912806

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -164,12 +164,15 @@ def is_content_token(t) -> bool:
164
  if t.dep_ in ("discourse", "intj", "vocative", "dep"):
165
  return False
166
  low = t.lower_.strip("¿?¡!.,;:()[]{}\"'").lower()
167
- if t.tag_.startswith("W") or low in {
 
168
  "como","cómo","que","qué","quien","quién","donde","dónde","cuando","cuándo",
169
  "porqué","por","por qué","cuanto","cuánto",
170
  "which","what","who","where","when","why","how",
171
- "hola","hello","hi","hey","ey","eh","oye","adios","adiós","ciao"
172
- }:
 
 
173
  return False
174
  return True
175
 
@@ -298,16 +301,22 @@ def realize_minimax(doc, src_lang: str, drop_articles=True, zero_copula=True, se
298
  S = realize_np(subs)
299
  O = realize_np(objs) + realize_np(obls)
300
  ADV=[]
 
301
  for a in advs:
302
  if not USE_SPACY or is_content_token(a):
303
  lem = lemma_of(a, src_lang) if USE_SPACY else a.text
304
- ADV.append(code_es(lem, "Minimax-ASCII") if src_lang=="Español" else code_en(lem, "Minimax-ASCII"))
 
 
 
 
305
 
306
  if zero_copula and not semi_lossless and vlem in ("ser","estar","be") and tense=="Pres" and not is_neg and not is_q:
307
  parts = S + O + ADV
308
  else:
309
  parts = [vcode] + S + O + ADV
310
- return " ".join(p for p in parts if p)
 
311
 
312
  def realize_komin(doc, src_lang: str, drop_articles=True, zero_copula=True, semi_lossless=False, person_hint="2s"):
313
  root, subs, objs, obls, advs = extract_core(doc)
@@ -354,7 +363,7 @@ def realize_komin(doc, src_lang: str, drop_articles=True, zero_copula=True, semi
354
  return out
355
 
356
  # ------------ Lossless (Base85 comprimido) ------------
357
- SIDECAR_B85_RE = re.compile(r"\s?§$$ (?P<b85>[A-Za-z0-9!#$%&()*+\-;<=>?@^_`{|}~]+) $$$")
358
 
359
  def b85_enc_raw(s: str) -> str:
360
  comp = zlib.compress(s.encode("utf-8"), 9)
@@ -530,6 +539,11 @@ def decode_simple(text: str, source: str, tgt_lang: str) -> str:
530
  parts = [p for p in [S, v_conj] + O_ADV if p]
531
  out_text = " ".join(parts)
532
 
 
 
 
 
 
533
  # Pregunta
534
  if has_q:
535
  start_q = "¿" if tgt_lang == "Español" else ""
@@ -789,4 +803,3 @@ if __name__ == "__main__":
789
 
790
 
791
 
792
-
 
164
  if t.dep_ in ("discourse", "intj", "vocative", "dep"):
165
  return False
166
  low = t.lower_.strip("¿?¡!.,;:()[]{}\"'").lower()
167
+ # Permite wh en preguntas (advmod/obl)
168
+ is_wh = t.tag_.startswith("W") or low in {
169
  "como","cómo","que","qué","quien","quién","donde","dónde","cuando","cuándo",
170
  "porqué","por","por qué","cuanto","cuánto",
171
  "which","what","who","where","when","why","how",
172
+ }
173
+ if is_wh and t.dep_ not in ("advmod", "obl") and "?" not in t.doc.text:
174
+ return False
175
+ if low in {"hola","hello","hi","hey","adios","adiós","ciao"}:
176
  return False
177
  return True
178
 
 
301
  S = realize_np(subs)
302
  O = realize_np(objs) + realize_np(obls)
303
  ADV=[]
304
+ wh_adv = [] # Para wh en Q
305
  for a in advs:
306
  if not USE_SPACY or is_content_token(a):
307
  lem = lemma_of(a, src_lang) if USE_SPACY else a.text
308
+ code = code_es(lem, "Minimax-ASCII") if src_lang=="Español" else code_en(lem, "Minimax-ASCII")
309
+ if is_q and a.dep_ == "advmod" and a.tag_.startswith("W"):
310
+ wh_adv.append(code)
311
+ else:
312
+ ADV.append(code)
313
 
314
  if zero_copula and not semi_lossless and vlem in ("ser","estar","be") and tense=="Pres" and not is_neg and not is_q:
315
  parts = S + O + ADV
316
  else:
317
  parts = [vcode] + S + O + ADV
318
+ full_parts = wh_adv + parts # Wh al frente si Q
319
+ return " ".join(p for p in full_parts if p)
320
 
321
  def realize_komin(doc, src_lang: str, drop_articles=True, zero_copula=True, semi_lossless=False, person_hint="2s"):
322
  root, subs, objs, obls, advs = extract_core(doc)
 
363
  return out
364
 
365
  # ------------ Lossless (Base85 comprimido) ------------
366
+ SIDECAR_B85_RE = re.compile(r"\s?§\((?P<b85>[A-Za-z0-9!#$%&()*+\-;<=>?@^_`{|}~]+)\)$")
367
 
368
  def b85_enc_raw(s: str) -> str:
369
  comp = zlib.compress(s.encode("utf-8"), 9)
 
539
  parts = [p for p in [S, v_conj] + O_ADV if p]
540
  out_text = " ".join(parts)
541
 
542
+ # Wh en Q: si primer token es wh, muévelo al frente
543
+ if has_q and lemma_tokens and lemma_tokens[0].lower() in {"como", "cómo", "what", "how"}:
544
+ wh = lemma_tokens.pop(0)
545
+ out_text = f"{wh} {out_text}"
546
+
547
  # Pregunta
548
  if has_q:
549
  start_q = "¿" if tgt_lang == "Español" else ""
 
803
 
804
 
805