generate-dictionary.clj
Pinchord · pinchord.git · Tickets · Changelog
Branches > v26.0 > a29c18b > files / generate-dictionary.clj
#!/usr/bin/env bb
;; Dictionay generation script
(def priority
"Priorities used for javelin orthospelling."
(zipmap [::pre-prefixes ::prefixes ::initials ::vowels ::finals ::suffixes]
(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 \-)))
(defn generate-dict! []
(let [chords (edn/read-string (slurp "chords.edn"))
{:keys [version pre-prefixes prefixes initials vowels finals suffixes]} chords
layout {::pre-prefixes pre-prefixes
::prefixes prefixes
::initials initials
::vowels vowels
::finals (finalize finals)
::suffixes (finalize suffixes)}
dict {:name "Pinchord"
: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)))
#{} layout)
(sort-by (comp - count :stroke)))}]
(->> (yaml/generate-string dict)
(spit (str "pinchord-javelin-dictionary-" version ".yaml")))))
(generate-dict!)