bab2981
Pinchord · pinchord.git · Tickets · Changelog
Branches > build-process > bab2981 > files / chords.edn
Move generate-dictionary.clj into a project
Commit: bab2981a40965356bf93eeb27c10274a289a18a5
Parent: 6e29ed3
3 changed files:
bb.edn view file
@@ -0,0 +1,2 @@+{:paths ["src"]+ :tasks {generate {:task (exec 'org.pinchord.generate/-main)}}}generate-dictionary.clj view file
@@ -1,86 +0,0 @@-#!/usr/bin/env bb-(def sections [: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 [m]- (update-keys m (partial str "-")))--(defn mask [s1 s2]- (apply str (remove (set s1) s2)))-- (defn abbreviate- "Javelin entries can only be 6 characters long!"- [s]- (if (> (count s) 6)- (let [new-s (-> s- (str/replace #"TSPW" "G")- (str/replace #"PKS" "C")- (str/replace #"PKFS" "G")- (str/replace #"KFS" "SH")- (str/replace #"LR" "N"))]- (if (> (count new-s) 6)- (throw (ex-info "Too long!" {:s s :new-s new-s}))- new-s))- s))-- (defn all-chords [s]- (if (empty? s)- #{""}- (let [rest-combos (all-chords (rest s))]- (set (concat- rest-combos- (map #(str (first s) %) rest-combos))))))-- (defn abbreviate-long-chords [s]- (update-vals s abbreviate))-- (defn with-gaps-filled [bank chords]- (let [s (remove (bank chords) (all-chords (bank (:banks chords))))]- (merge (bank chords) (abbreviate-long-chords (zipmap s s)))))--(defn ^:private new-value [chords]- (assoc chords- :initials (with-gaps-filled :initials chords)- :vowels (with-gaps-filled :vowels chords)- :finals (with-gaps-filled :finals chords)))--; TODO make this make all chords that aren't in chords.edn map to themself :D-(let [chords (-> (edn/read-string (slurp "chords.edn"))- new-value- (update :finals finalize)- (update :suffixes finalize))- banks (:banks chords)- dict {:name (str "Pinchord Base " (:version chords))- :maximumOutlineLength 1- :starters [{:stroke "#+" :definition "{^}{-|}" :mask "#+"}- {:stroke "" :definition "{}" :mask ""}]- :letters (->> (reduce (fn [acc [bank entries]]- ; TODO if the bank has no keys, map it to itself?- (if-let [bank-keys (banks bank)]- (into acc (mapv (fn [[stroke translation]]- {:stroke stroke :data translation :order (priority bank)- :avoidMask (str (when (= bank :finals)- "-")- (mask stroke bank-keys))})- entries))- (into acc (mapv (fn [[stroke translation]]- {:stroke stroke :data translation :order (priority bank)})- entries))))- #{} (select-keys chords sections))- (sort-by (comp - count :stroke))- ; Use this if you want finals to suppress space by default :)- #_(cons {:stroke "-" :data "{^}" :order (priority :finals)}))}- dict-path (str "pinchord-javelin-dictionary-" (:version chords) ".yaml")]- (spit dict-path (yaml/generate-string dict)))src/org/pinchord/generate.clj view file
@@ -0,0 +1,91 @@+(ns org.pinchord.generate+ (:require [clj-yaml.core :as yaml]+ [clojure.string :as str]+ [clojure.edn :as edn]))++(def sections [: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 [m]+ (update-keys m (partial str "-")))++(defn mask [s1 s2]+ (apply str (remove (set s1) s2)))++ (defn abbreviate+ "Javelin entries can only be 6 characters long!"+ [s]+ (if (> (count s) 6)+ (let [new-s (-> s+ (str/replace #"TSPW" "G")+ (str/replace #"PKS" "C")+ (str/replace #"PKFS" "G")+ (str/replace #"KFS" "SH")+ (str/replace #"LR" "N"))]+ (if (> (count new-s) 6)+ (throw (ex-info "Too long!" {:s s :new-s new-s}))+ new-s))+ s))++ (defn all-chords [s]+ (if (empty? s)+ #{""}+ (let [rest-combos (all-chords (rest s))]+ (set (concat+ rest-combos+ (map #(str (first s) %) rest-combos))))))++ (defn abbreviate-long-chords [s]+ (update-vals s abbreviate))++ (defn with-gaps-filled [bank chords]+ (let [s (remove (bank chords) (all-chords (bank (:banks chords))))]+ (merge (bank chords) (abbreviate-long-chords (zipmap s s)))))++(defn ^:private new-value [chords]+ (assoc chords+ :initials (with-gaps-filled :initials chords)+ :vowels (with-gaps-filled :vowels chords)+ :finals (with-gaps-filled :finals chords)))++; TODO make this make all chords that aren't in chords.edn map to themself :D+(defn -main [& _args]+ (let [chords (-> (edn/read-string (slurp "chords.edn"))+ new-value+ (update :finals finalize)+ (update :suffixes finalize))+ banks (:banks chords)+ dict {:name (str "Pinchord Base " (:version chords))+ :maximumOutlineLength 1+ :starters [{:stroke "#+" :definition "{^}{-|}" :mask "#+"}+ {:stroke "" :definition "{}" :mask ""}]+ :letters (->> (reduce (fn [acc [bank entries]]+ ; TODO if the bank has no keys, map it to itself?+ (if-let [bank-keys (banks bank)]+ (into acc (mapv (fn [[stroke translation]]+ {:stroke stroke :data translation :order (priority bank)+ :avoidMask (str (when (= bank :finals)+ "-")+ (mask stroke bank-keys))})+ entries))+ (into acc (mapv (fn [[stroke translation]]+ {:stroke stroke :data translation :order (priority bank)})+ entries))))+ #{} (select-keys chords sections))+ (sort-by (comp - count :stroke))+ ; Use this if you want finals to suppress space by default :)+ #_(cons {:stroke "-" :data "{^}" :order (priority :finals)}))}+ dict-path (str "pinchord-javelin-dictionary-" (:version chords) ".yaml")]+ (spit dict-path (yaml/generate-string dict))))