RJ3vans commited on
Commit
489c5e0
·
verified ·
1 Parent(s): d339273

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -2692,6 +2692,45 @@ def build_single_sign_bracketed(tagged_list, mode="ccv", skip_indices=None):
2692
  return text
2693
  ###############################################################################
2694
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2695
  ###############################################################################
2696
  @spaces.GPU(duration=120)
2697
  def process_text(input_text):
 
2692
  return text
2693
  ###############################################################################
2694
 
2695
+ ###############################################################################
2696
+ _PAREN = re.compile(r"\(([^()]*)\)")
2697
+ ###############################################################################
2698
+
2699
+ ###############################################################################
2700
+ def split_coord_list(inner: str) -> list[str]:
2701
+ inner = re.sub(r",?\s+(?:and|or)\s+", ", ", inner, flags=re.I)
2702
+ return [p.strip(" ,") for p in inner.split(",") if p.strip(" ,")]
2703
+ ###############################################################################
2704
+
2705
+ ###############################################################################
2706
+ def hide_paren_lists(sent: str):
2707
+ lists = []
2708
+ def repl(m):
2709
+ parts = split_coord_list(m.group(1))
2710
+ if len(parts) < 2:
2711
+ return m.group(0)
2712
+ lists.append(parts)
2713
+ return f" LIST{len(lists)} "
2714
+ text = _PAREN.sub(repl, sent)
2715
+ text = re.sub(r"\s+", " ", text).strip()
2716
+ return text, lists
2717
+ ###############################################################################
2718
+
2719
+ ###############################################################################
2720
+ def expand_paren_lists(sent: str, lists: list[list[str]]) -> list[str]:
2721
+ outs = [sent]
2722
+ for i, parts in enumerate(lists, 1):
2723
+ key = f"LIST{i}"
2724
+ nxt = []
2725
+ for s in outs:
2726
+ if key not in s:
2727
+ nxt.append(s)
2728
+ continue
2729
+ nxt.extend(s.replace(key, f"({p})") for p in parts)
2730
+ outs = nxt
2731
+ return outs
2732
+ ###############################################################################
2733
+
2734
  ###############################################################################
2735
  @spaces.GPU(duration=120)
2736
  def process_text(input_text):