about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-09-24T13·55+0300
committerVincent Ambo <mail@tazj.in>2021-11-28T14·14+0300
commit48290298ad04d5b794671340bd5bf3bd5383d4fa (patch)
tree2a50786b76c771c9088be6abc4020bf4fcfb8b08
parent104f002a07360dc9340d15dfb6b2d044fd043754 (diff)
feat(tazjin/russian): Add macro to populate word table r/3103
Adds a stupid macro that populates a 'russian-words' hash table in
which merged definitions of words are available.

Change-Id: Ide7825577ba26d63ff564e54601541f39ab5a1a6
-rw-r--r--users/tazjin/russian/russian.el65
-rw-r--r--users/tazjin/russian/words.el8
2 files changed, 72 insertions, 1 deletions
diff --git a/users/tazjin/russian/russian.el b/users/tazjin/russian/russian.el
new file mode 100644
index 000000000000..1ef911199f5d
--- /dev/null
+++ b/users/tazjin/russian/russian.el
@@ -0,0 +1,65 @@
+(require 'cl-macs)
+(require 'ht)
+(require 'seq)
+
+;; Type definitions for Russian structures
+
+(cl-defstruct russian-word
+  "Definition and metadata of a single Russian word."
+  (word nil :type string)
+  (translations :type list
+                :documentation "List of lists of strings, each a set of translations.")
+
+  (notes nil :type list ;; of string
+         :documentation "free-form notes about this word")
+
+  (roots nil :type list ;; of string
+         :documentation "list of strings that correspond with roots (exact string match)"))
+
+(defun russian--merge-words (previous new)
+  "Merge two Russian word definitions together. If no previous
+  definition exists, only the new one will be returned."
+  (if (not previous) new
+    (assert (equal (russian-word-word previous)
+                   (russian-word-word new))
+            "different words passed into merge function")
+    (make-russian-word :word (russian-word-word previous)
+                       :translations (-concat (russian-word-translations previous)
+                                              (russian-word-translations new))
+                       :notes (-concat (russian-word-notes previous)
+                                       (russian-word-notes new))
+                       :roots (-concat (russian-word-roots previous)
+                                       (russian-word-roots new)))))
+
+;; Definitions for creating a data structure of all Russian words.
+
+(defvar russian-words (make-hash-table)
+  "Table of all Russian words in the corpus.")
+
+(defun russian--define-word (word)
+  "Define a single word in the corpus, optionally merging it with
+  another entry."
+  (let ((key (russian-word-word word)))
+    (ht-set russian-words key (russian--merge-words
+                               (ht-get russian-words key)
+                               word))))
+
+(defmacro define-russian-words (&rest words)
+  "Define the list of all available words. There may be more than
+  one entry for a word in some cases."
+  (declare (indent defun))
+
+  ;; Clear the table before proceeding with insertion
+  (setq russian-words (make-hash-table))
+
+  (seq-map
+   (lambda (word)
+     (russian--define-word (make-russian-word :word (car word)
+                                              :translations (cadr word)
+                                              :notes (caddr word)
+                                              :roots (cadddr word))))
+   words)
+
+  '(message "Defined %s unique words." (ht-size russian-words)))
+
+(provide 'russian)
diff --git a/users/tazjin/russian/words.el b/users/tazjin/russian/words.el
index 46276cdd0a1d..f2b51ba71243 100644
--- a/users/tazjin/russian/words.el
+++ b/users/tazjin/russian/words.el
@@ -4,7 +4,10 @@
 ;; translations :: '(translation ...)
 ;; roots :: '(root ...)
 
-'( ;; 1-50
+(require 'russian-defs)
+
+(define-russian-words
+  ;; 1-50
   ("и" ("and" "though"))
   ("в" ("in" "at"))
   ("не" ("not"))
@@ -412,3 +415,6 @@
   ("оставить" ("to leave" "to abandon"))
   ("войти" ("to enter" "to come in") nil ("-й-"))
   ("длинный" ("long")))
+
+
+(provide 'russian-words)