generate-dictionary.clj

Pinchord · pinchord.git · Tickets · Changelog

Branches > build-process > 742ba42 > files / generate-dictionary.clj

#!/usr/bin/env bb
;; Dictionay generation script

(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"))
      chords (-> chords
                 (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")]
  (spit dict-path (yaml/generate-string dict)))