feat(tazjin/russian): Exclude known words from random display

Adds a set of words that I consider "known" (but that should be in the
most frequent word list anyways). This set can be populated by
invoking `mark-last-russian-word-as-known` after display, and is
automatically persisted.

Right now there's nothing automatically loading it back in, just as
there is nothing loading any of this automatically, that's for the
future.

Change-Id: I51ee4f37114c6b95925e8ad5bdc5dc9b8657bdad
This commit is contained in:
Vincent Ambo 2021-11-29 12:44:56 +03:00
parent 7843363225
commit e4c82c2a34

View file

@ -82,11 +82,39 @@
(defun display-random-russian-word ()
(interactive)
(let ((word (seq-random-elt (ht-values russian-words))))
(let* ((word (seq-random-elt (ht-values russian-words))))
(while (ht-contains? russian--known-words (russian-word-word word))
(setq word (seq-random-elt (ht-values russian-words))))
(setq russian--last-word word)
(message (russian--format-word word))))
(defvar russian--display-timer
(run-with-idle-timer 5 t #'display-random-russian-word))
;; Ability to filter out known words
(defvar russian--known-words (make-hash-table)
"Table of words that are already known.")
(defun persist-known-russian-words ()
"Persist all known Russian words."
(let ((file "/persist/tazjin/known-russian-words.el"))
(with-temp-file file
(insert (prin1-to-string russian--known-words)))))
(defun load-known-russian-words ()
"Load all known Russian words."
(let ((file "/persist/tazjin/known-russian-words.el"))
(with-temp-buffer
(insert-file-contents file)
(setq russian--known-words (read (current-buffer))))))
(defun mark-last-russian-word-known ()
"Mark the last Russian word that appeared as known."
(interactive)
(let ((word (russian-word-word russian--last-word)))
(ht-set russian--known-words word t)
(persist-known-russian-words)
(message "Marked '%s' as known" word)))
(provide 'russian)