Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

fix(linux): Revert and the heard-as chips name an added word whole (in → in now), not "→ now" with nothing before the arrow

wqugurudb02021f94f7
diff --git a/linux/cicada/app/notes_window.py b/linux/cicada/app/notes_window.py
index cf679b8..a177c59 100644
--- a/linux/cicada/app/notes_window.py
+++ b/linux/cicada/app/notes_window.py
@@ -616,8 +616,8 @@ class NotesWindow(Gtk.Window):
c.show_all()
def _fix_card(self, sid, line, fix, _position, of) -> Gtk.Widget:
- from ..core.correction import core
- cf, ct = core(fix.from_, fix.to)
+ from ..core.correction import label
+ cf, ct = label(fix)
fx = self.app.fixes
head = ui.hbox(8)
head.pack_start(ui.text(L("这样改对吗?"), 13, "ink", bold=True, wrap=False, ellipsize=False), False, False, 0)
diff --git a/linux/cicada/app/records_window.py b/linux/cicada/app/records_window.py
index 334affb..7a5ed1e 100644
--- a/linux/cicada/app/records_window.py
+++ b/linux/cicada/app/records_window.py
@@ -1456,9 +1456,9 @@ class RecordsWindow(Gtk.Window):
self._banner_key = key
ui.clear(box)
if waiting:
- from ..core.correction import core
+ from ..core.correction import label
line, fix = waiting[0]
- cf, ct = core(fix.from_, fix.to)
+ cf, ct = label(fix)
left = ui.vbox(2)
left.pack_start(ui.text(LF("改了 %lld 处听错的词,%lld 处等你确认", fixed, len(waiting)), 13, "ink", bold=True, width_chars=40),
False, False, 0)
diff --git a/linux/cicada/app/ui.py b/linux/cicada/app/ui.py
index f728c94..22f3962 100644
--- a/linux/cicada/app/ui.py
+++ b/linux/cicada/app/ui.py
@@ -550,10 +550,10 @@ def fixed(line, size: int = 13, cls: str = "ink", terms: list = (), current: boo
def fixed_words(items, on_revert) -> Gtk.Widget:
"""Under a line: each fixed word, what it was heard as, and 改回. `items`: [(line id, fix)]."""
- from ..core.correction import core
+ from ..core.correction import label
w = Wrap(6)
for line_id, f in items:
- cf, ct = core(f.from_, f.to)
+ cf, ct = label(f)
row = hbox(6)
lab = Gtk.Label()
lab.set_markup('<span size="%d"><span foreground="#6B7080">%s</span> %s <span foreground="#6B7080">→</span> %s</span>'
diff --git a/linux/cicada/core/correction.py b/linux/cicada/core/correction.py
index cb5573a..2eeb7a3 100644
--- a/linux/cicada/core/correction.py
+++ b/linux/cicada/core/correction.py
@@ -46,6 +46,13 @@ def core(frm: str, to: str) -> tuple:
return a[i:len(a) - j], b[i:len(b) - j]
+
+def label(f) -> tuple:
+ """A fix as the UI names it (听成 X → Y, 已改回 X): the changed words, or the whole fix when it
+ only adds or drops words ("in" → "in now", whose changed part alone would be "" → "now")."""
+ cf, ct = core(f.from_, f.to)
+ return (f.from_, f.to) if not cf or not ct else (cf, ct)
+
def apply(fixes: list, src: str) -> tuple:
"""The line as shown: each applied fix replaces its words where they still are. The marks are the
replaced words as (start, end) character offsets into the text, for the underline."""
diff --git a/linux/cicada/core/live_fixes.py b/linux/cicada/core/live_fixes.py
index a46d644..ab4e698 100644
--- a/linux/cicada/core/live_fixes.py
+++ b/linux/cicada/core/live_fixes.py
@@ -221,7 +221,7 @@ class LiveFixes:
if n >= 2:
self.vocabulary.forget(c[0], c[1])
Log.d("fix reverted line=%s" % line_id)
- self._say(LF("已改回 %@,这场不再改", c[0]))
+ self._say(LF("已改回 %@,这场不再改", correction.label(fix)[0]))
# 改这句…
@@ -314,7 +314,7 @@ def fixed_words(lines: list) -> list:
for l in lines:
for f in l.fixes or []:
if f.applied:
- cf, ct = correction.core(f.from_, f.to)
+ cf, ct = correction.label(f)
word = ct.strip()
heard, n = out.get(word, ([], 0))
if cf not in heard:
diff --git a/linux/tests/test_fixes.py b/linux/tests/test_fixes.py
index 26fb71f..dc3c547 100644
--- a/linux/tests/test_fixes.py
+++ b/linux/tests/test_fixes.py
@@ -187,6 +187,11 @@ class Correction(unittest.TestCase):
self.assertEqual(correction.user_edit("我木娜找了一个", "我在 Monad 找了一个", "我木娜找了一个", [])[1], "木娜")
self.assertIsNone(correction.user_edit("a", " a ", "a", []))
+ def test_label_names_an_added_word_whole(self):
+ self.assertEqual(correction.label(LineFix("in", "in now", user=True)), ("in", "in now"))
+ self.assertEqual(correction.label(LineFix("Great", "OK Great", user=True)), ("Great", "OK Great"))
+ self.assertEqual(correction.label(LineFix("解除质压", "解除质押")), ("质压", "质押"))
+
def test_added_word_stays_on_its_line_and_never_matches_punctuation(self):
# "now" added before the full stop: the fix is the last word, unique in the line, not ".".
line = "Great, let's lock that in."
@@ -353,6 +358,8 @@ class Live(Base):
self.assertEqual(store.line(sid, "l2").shown, "Fine.")
self.assertEqual(fx.vocabulary.terms, [])
self.assertEqual(fx.toast_text(), "已改 1 处:in → in now")
+ fx.revert(store.line(sid, "l0").fixes[-1], "l0", sid)
+ self.assertEqual(fx.toast_text(), "已改回 in,这场不再改")
def test_one_off_edit_does_not_teach_the_list(self):
fx, store, sid = self.setup(["我木娜找了一个", "木娜那边也有"])