RJ3vans commited on
Commit
8518e23
·
verified ·
1 Parent(s): fd604bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -24
app.py CHANGED
@@ -741,9 +741,27 @@ def _has_ssccv_sign(tagged_list):
741
  return any("M:Y_SSCCV" in str(item) for item in tagged_list)
742
  ###############################################################################
743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
744
  ###############################################################################
745
  def highlight_tokens_html(tokens, labels):
746
- """Theme-safe marking for Hugging Face Spaces: underline/bold, not background fill."""
747
  parts = []
748
  i = 0
749
  n = len(tokens)
@@ -753,34 +771,23 @@ def highlight_tokens_html(tokens, labels):
753
  j = i + 1
754
  while j < n and (labels[j] if j < len(labels) else "") == lab:
755
  j += 1
756
- chunk = " ".join(tokens[i:j])
757
- chunk = re.sub(r"\s+([.,!?;:])", r"\1", chunk)
758
- chunk = fix_apostrophe_spacing(chunk)
759
  esc = html.escape(chunk)
760
- title = html.escape(lab)
761
-
762
  if lab == "IN_COGNITIVE_COMMUNICATIVE_VP":
763
- # core VP: bold + solid underline
764
- parts.append(
765
- f'<u title="{title}" '
766
- f'style="font-weight:700;text-decoration:underline;text-underline-offset:3px">'
767
- f"{esc}</u>"
768
- )
769
  else:
770
- # before/after sign: italic + dotted underline
771
- parts.append(
772
- f'<em title="{title}" '
773
- f'style="font-style:italic;text-decoration:underline dotted;text-underline-offset:3px">'
774
- f"{esc}</em>"
775
- )
776
  i = j
777
  else:
778
- tok = tokens[i]
779
- if tok in ".,!?;:" and parts:
780
- parts[-1] = parts[-1] + html.escape(tok)
781
- else:
782
- parts.append(html.escape(tok))
783
- i += 1
 
 
 
784
  return " ".join(parts)
785
  ###############################################################################
786
 
 
741
  return any("M:Y_SSCCV" in str(item) for item in tagged_list)
742
  ###############################################################################
743
 
744
+ ###############################################################################
745
+ def _glue_tokens(toks):
746
+ """Join tokens without spaces around ' or punctuation."""
747
+ buf = []
748
+ for tok in toks:
749
+ if not tok:
750
+ continue
751
+ if not buf:
752
+ buf.append(tok)
753
+ continue
754
+ if tok in ".,!?;:" or tok == "'" or tok.startswith("'"):
755
+ buf[-1] = buf[-1] + tok
756
+ elif buf[-1].endswith("'"):
757
+ buf[-1] = buf[-1] + tok
758
+ else:
759
+ buf.append(tok)
760
+ return " ".join(buf)
761
+ ###############################################################################
762
+
763
  ###############################################################################
764
  def highlight_tokens_html(tokens, labels):
 
765
  parts = []
766
  i = 0
767
  n = len(tokens)
 
771
  j = i + 1
772
  while j < n and (labels[j] if j < len(labels) else "") == lab:
773
  j += 1
774
+ chunk = _glue_tokens(tokens[i:j])
 
 
775
  esc = html.escape(chunk)
 
 
776
  if lab == "IN_COGNITIVE_COMMUNICATIVE_VP":
777
+ parts.append(f"<strong><u>{esc}</u></strong>")
 
 
 
 
 
778
  else:
779
+ parts.append(f"<u>{esc}</u>")
 
 
 
 
 
780
  i = j
781
  else:
782
+ j = i + 1
783
+ while j < n:
784
+ lab_j = labels[j] if j < len(labels) else ""
785
+ if lab_j in HIGHLIGHT_CCV:
786
+ break
787
+ j += 1
788
+ chunk = _glue_tokens(tokens[i:j])
789
+ parts.append(html.escape(chunk))
790
+ i = j
791
  return " ".join(parts)
792
  ###############################################################################
793