generate-dictionary.clj
Pinchord · pinchord.git · Tickets · Changelog
Branches > main > 892cd13 > files / generate-dictionary.clj
#!/usr/bin/env bb
(ns org.pinchord.javelin.generate-dictionary
"Javelin dictionary generation script"
(:require [cheshire.core :as json]
[clj-yaml.core :as yaml]
[clojure.edn :as edn]))
(def sections [:pre-prefixes :prefixes :initials :vowels :finals :suffixes])
(def priority
"Priorities used for javelin orthospelling."
(zipmap sections
(rest (range))))
(comment
(def yaml-dict (yaml/parse-string (slurp "pinchord-javelin-dictionary.yaml")))
(->> (:letters yaml-dict)
(filter #(= (:order %) 2))
(map (fn [m] [(:stroke m) (:data m)]))
(into {})))
(defn finalize
"Puts dashes before all the keys of m"
[m]
(update-keys m (partial str \-)))
(let [chords (-> (edn/read-string (slurp "chords.edn"))
(update :finals finalize)
(update :suffix finalize))
dict {:name (str "Pinchord Base " (:version chords))
:maximumOutlineLength 1
:starters [{:stroke "" :definition "" :mask ""}]
:letters (->> (reduce (fn [acc [layout entries]]
(into acc (mapv (fn [[stroke translation]] {:stroke stroke :data translation :order (priority layout)})
entries)))
#{} (select-keys chords sections))
(sort-by (comp - count :stroke)))}
dict-path (str "pinchord-javelin-dictionary-" (:version chords) ".yaml")
json-chords-path (str "pinchord-chords-" (:version chords) ".json")]
(spit dict-path (yaml/generate-string dict))
(spit json-chords-path (json/generate-string chords)))