7b78649

Ametrine ยท ametrine.git

Branches > main > 7b78649 > files / src / dev / grahp / ametrine / utils.clj

initial commit

Grahp, 2026-01-10

Commit: 7b78649b9a2a47e951e7c42ee2a7c76f8051d2cc

10 changed files:

.gitignore added (view file)

@@ -0,0 +1,14 @@+/target+/classes+/checkouts+profiles.clj+.clj-kondo/+pom.xml+pom.xml.asc+*.jar+*.class+.lsp/*+/.lein-*+/.nrepl-port+.hgignore+.hg/

LICENSE added (view file)

@@ -0,0 +1,339 @@+                    GNU GENERAL PUBLIC LICENSE+                       Version 2, June 1991++ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++                            Preamble++  The licenses for most software are designed to take away your+freedom to share and change it.  By contrast, the GNU General Public+License is intended to guarantee your freedom to share and change free+software--to make sure the software is free for all its users.  This+General Public License applies to most of the Free Software+Foundation's software and to any other program whose authors commit to+using it.  (Some other Free Software Foundation software is covered by+the GNU Lesser General Public License instead.)  You can apply it to+your programs, too.++  When we speak of free software, we are referring to freedom, not+price.  Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+this service if you wish), that you receive source code or can get it+if you want it, that you can change the software or use pieces of it+in new free programs; and that you know you can do these things.++  To protect your rights, we need to make restrictions that forbid+anyone to deny you these rights or to ask you to surrender the rights.+These restrictions translate to certain responsibilities for you if you+distribute copies of the software, or if you modify it.++  For example, if you distribute copies of such a program, whether+gratis or for a fee, you must give the recipients all the rights that+you have.  You must make sure that they, too, receive or can get the+source code.  And you must show them these terms so they know their+rights.++  We protect your rights with two steps: (1) copyright the software, and+(2) offer you this license which gives you legal permission to copy,+distribute and/or modify the software.++  Also, for each author's protection and ours, we want to make certain+that everyone understands that there is no warranty for this free+software.  If the software is modified by someone else and passed on, we+want its recipients to know that what they have is not the original, so+that any problems introduced by others will not reflect on the original+authors' reputations.++  Finally, any free program is threatened constantly by software+patents.  We wish to avoid the danger that redistributors of a free+program will individually obtain patent licenses, in effect making the+program proprietary.  To prevent this, we have made it clear that any+patent must be licensed for everyone's free use or not licensed at all.++  The precise terms and conditions for copying, distribution and+modification follow.++                    GNU GENERAL PUBLIC LICENSE+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++  0. This License applies to any program or other work which contains+a notice placed by the copyright holder saying it may be distributed+under the terms of this General Public License.  The "Program", below,+refers to any such program or work, and a "work based on the Program"+means either the Program or any derivative work under copyright law:+that is to say, a work containing the Program or a portion of it,+either verbatim or with modifications and/or translated into another+language.  (Hereinafter, translation is included without limitation in+the term "modification".)  Each licensee is addressed as "you".++Activities other than copying, distribution and modification are not+covered by this License; they are outside its scope.  The act of+running the Program is not restricted, and the output from the Program+is covered only if its contents constitute a work based on the+Program (independent of having been made by running the Program).+Whether that is true depends on what the Program does.++  1. You may copy and distribute verbatim copies of the Program's+source code as you receive it, in any medium, provided that you+conspicuously and appropriately publish on each copy an appropriate+copyright notice and disclaimer of warranty; keep intact all the+notices that refer to this License and to the absence of any warranty;+and give any other recipients of the Program a copy of this License+along with the Program.++You may charge a fee for the physical act of transferring a copy, and+you may at your option offer warranty protection in exchange for a fee.++  2. You may modify your copy or copies of the Program or any portion+of it, thus forming a work based on the Program, and copy and+distribute such modifications or work under the terms of Section 1+above, provided that you also meet all of these conditions:++    a) You must cause the modified files to carry prominent notices+    stating that you changed the files and the date of any change.++    b) You must cause any work that you distribute or publish, that in+    whole or in part contains or is derived from the Program or any

Show all 340 lines

README.md added (view file)

@@ -0,0 +1,5 @@+# Ametrine++Non-modal Orthospelling Dictionary with no dedicated key.++See https://grahp.dev/ametrine

project.clj added (view file)

@@ -0,0 +1,6 @@+(defproject ametrine "1"+  :dependencies [[org.clojure/clojure "1.12.0"]+                 [org.clojure/data.json "2.5.0"]]+  :main ^:skip-aot dev.grahp.ametrine.core+  :target-path "target/%s"+  :profiles {:uberjar {:aot :all}})

resources/ametrine.json added (view file)

Binary file, or too large to diff.

resources/config.edn added (view file)

@@ -0,0 +1,294 @@+;; Ametrine config file+;; Don't edit this file edit the user.edn file++;; TODO Organize so harri doesn't block me again++{:settings+ {:output-file "ametrine.json"}++ :starters {+            "" ""+            "S" "s"+            "FRS" "sl"+            "FRGS" "shr"+            "PS" "sp"+            "RPS" "spr"+            "GS" "sk"+            "FS" "sh"+            "RS" "v"+            "LS" "st"+            "RLS" "str"++            "PBLGS" "z"+            "BS" "sw"+            "^PBS" "bt"+            "^RPBS" "btr"++            "L" "t"+            "RL" "tr"+            "BL" "tw"+            "FL" "th"+            "FRL" "thr"+            "^FRL" "tl" ;; Because of throw++            "RBGS" "j"++            "PL" "f"+              "FRPL" "fl"+              "RPL" "fr"+              "^PL" "ph"+              "^RPL" "phr"+              "^FRPL" "phl"+            "B" "w"+            "^B" "ww"+            "RB" "wr"+            "FB" "wh"++            "FPS" "sm"++            "R" "r"+            "BG" "qu"+            "^BG" "q"++            "FPL" "n"+            "^FPL" "nn"+            "RBG" "y"++            "G" "k"+            "RG" "kr"+            "FRG" "chr"++            "PBG" "c"+            "^PBG" "cc"+            "RPBG" "cr"+            "FPBG" "ch"+              "^FRPBG" "chr"+            "FRPBG" "cl"+            "PBGS" "sc"++            "FP" "m"+              "^FP" "mm"+            "P" "p"+            "^P" "pp"+            "^RP" "ppr"+            "^FRP" "ppl"+            "RP" "pr"+            "FRP" "pl"++            "RPB" "br"++            "PG" "x"+            "*GS" "ex"+            "*LGS" "ext"+            "PGS" "exp"+            "FRPGS" "expl"++            "F" "h"+            "FR" "l"+            "*FR" "hr" ;; Pretty rare I would think.+            "^FR" "ll"+            "PB" "b"+            "FRPB" "bl"+            "*FRPB" "bel" ;; TODO hmm+            "LG" "d"+            "RLG" "dr"+            "*RLG" "der"+            "PBLG" "g"+            "^PBLG" "gg"+            "RPBLG" "gr"+            "FPBLG" "gh"+            "FRPBLG" "gl"++            "FPLG" "kn"+            }+ :enders {++          "*LG" "lk"++          "" ""+          "*D" "y"+          ; "PL" "m"+          ; "*PL" "pl"+          "PL" "pl"+            "PL*D" "ply"+          "*FT" "st"+          "RT" "rt"+          "RL" "rl"+          "RL*D" "rly"+          "RLD" "rld"++          "*F" "lf"+          "*FB" "lv"+          "F" "f"+          "^F" "ff"+          ; "*F" "ph"+          "FP" "ch"+          "FR" "m"+            "FRT" "mt"+            "FRD" "md" ;; TODO+            "FR*D" "my"++          "FRPB" "nch"+          "*FRPB" "rch"++          "FPB" "fen"+          "*FPB" "ven"++          "FPL" "pp"+          "*FPL" "ff"++          "FRP" "mp"+          "FRPT" "mpt"+          "FRPL" "mpl"+          "FRPL*D" "mply"+          "FRP*D" "mpy"+          "*FRPL" "mm"+          "FRB" "mb"+          "FRBL" "mbl"+          "^FRB" "rv"+          "^*FRB" "rf"+          "FRL" "ml"+          "FRPBG" "nk"+            "*FRPBG" "nc"+            "*FRPBLG" "ncl"+          "FRPBGS" "nction"+          "*FR" "ver"+          "FB" "v"+          "FT" "ft"++          "R" "r"+            "RD" "rd"+            "R*T" "rth"+            "^R*T" "rth"+            "R*TD" "rthy"+            "RS" "rs"+            "RP" "rp"+          "R*D" "ry"+          "RPB" "rn"+          "RPL" "rm"+          "RB" "sh"+          "RBG" "rk"+          "RG" "rg"+          "RB*D" "shy"+          "*RB" "rb"++          "PBLG" "j"+          "*PBLG" "ngl"+          "*PBGT" "ngth"++          "*B" "w"+          "B" "b"+          "*BLG" "ckl"+          "BL" "bl"+            "BLT" "blet"+            "BLTD" "bleted"+            "BL*D" "bly"+          "BGS" "x"++          "PB" "n"+            "*PB" "nn"+            "PB*S" "nst"+            "PBS" "ns"+            "PB*SZ" "nc"+          "PBL" "nl"+          "PBL*D" "nly"+          "PB*D" "ny"+          "PBG" "ng"+          "PBG*D" "ngy" ;; TODO+          "PBT" "nt"+            "PBT*D" "nty"+            "*PBT" "nth"+            "PBTD" "nted"+            "PBTS" "nts"+          "PBD" "nd"+          "P" "p"+            "PD" "ped" ;; TODO is pd used anywhere?+            "PT" "pt"+            "P*D" "py"+          "*P" "lp"++          "L" "l"+            "LS" "ls"+          "L*D" "ly"+          "*L" "ll"+          "^*LD" "lly"+++          "*FPT" "tch"++          "LT" "lt"+          "LD" "ld"++          "PBLGS" "qu"+          "*PBLGS" "q"+          "BGT" "cket"+          "RBGT" "xt"++          "GS" "tion"+          "*BGS" "ction"++          "*S" "ss"+          "S" "s"+          "*SZ" "c"+          "*TSDZ" "ct"+          "*FRT" "rst"+          "*RS" "ster"+          "*RSZ" "rc"+          "RPBLG" "rj"+          ; "*RS" "str"+          "BG" "k"+          "BGDZ" "king"+          ;; TODO ned+          "*BG" "ck"++          "T" "t"+          "*T" "th"+          "TS" "ts"+          "TD" "ted"++          "GT" "ght"+          "*GT" "gth"+          "G" "g"+          "D" "d"++          "RPBD" "nder"+          "*TD" "ty"+          "^*TD" "tty"+          ;; TODO mn dy+          "PS" "h"+          "*FBG" "sk"+          }+ :vowels {+          "-" ""+          "*" ""+          "AOEU" "ie"+          "AO*EU" "ua" ;; Yeah I got nothing+          "AEU" "ai"+          "AOE" "ee"+          "AO*E" "ia" ;; FUCK+          "AOU" "ew"+          "AE" "ea"+          "A*E" "ae"+          "OU" "ou"+          "O*U" "ow"+          "EU" "i"+          "AO" "oo"+          "OEU" "oi"+          "O*EU" "io" ;; Conflicts+          "AO*" "oa"+          "AU" "au"+          "A*U" "aw"+          "OE" "oe"+          "A" "a"+          "O" "o"+          "E" "e"+          "U" "u"+          }+ :overrides {+             ; "WHRAO*SZ" "{>}soon"+             ; "SWHRAO*SZ" "{^}{>}soon"+             ; "#WHRAO*SZ" "{>}{-|}soon"+             ; "#SWHRAO*SZ" "{^}{-|}soon"++             }+ :version 5}

resources/user.edn added (view file)

@@ -0,0 +1,31 @@+;; User config file++{:settings+ ;; You can output straight to your plover config dir+ {:output-file "/home/grahp/.config/plover/ametrine.json"}+ :starters {++            }+ :enders {++          }+ :vowels {++          }++ :overrides {+             ;; My stuff+             "WHRAO*SZ" "{>}soon"+             "SWHRAO*SZ" "{^}{>}soon"+             "#WHRAO*SZ" "{>}{-|}soon"+             "#SWHRAO*SZ" "{^}{-|}soon"++             "WHRAO*FRL" "{>}throa"+             "SWHRAO*FRL" "{^}{>}throa"+             "#WHRAO*FRL" "Throa"+             "#SWHRAO*FRL" "{^}Throa"+             "KWHR*EFBL" "vel"+             "SKWHR*EFBL" "{^}{>}vel"+             "#KWHR*EFBL" "{-|}vel"+             "#SKWHR*EFBL" "{^}{-|}vel"+             }}

src/dev/grahp/ametrine/core.clj added (view file)

@@ -0,0 +1,22 @@+(ns dev.grahp.ametrine.core+  (:require [dev.grahp.ametrine.utils :as utils]+            [dev.grahp.ametrine.dict :as dict])+  (:gen-class))++(defn -main+  [& args]+  (println "Started building...")+  (let [config (utils/load-resource "config")+        user-config (utils/load-resource "user")+        output-file (if-let [user-file ((user-config :settings) :output-file)]+                      user-file+                      ((config :settings) :output-file))]++    ;; TODO paralellize+    (-> (merge (dict/generate (config :starters) (config :vowels) (config :enders))+               (config :overrides)+               (dict/generate (user-config :starters) (user-config :vowels) (user-config :enders))+               (user-config :overrides))+        utils/transform-json+        (->> (utils/spit-resource output-file)))+    (println "Finished!")))

src/dev/grahp/ametrine/dict.clj added (view file)

@@ -0,0 +1,245 @@+(ns dev.grahp.ametrine.dict+  (:require [clojure.string :as str]+            [dev.grahp.ametrine.utils :as utils]))++(defn apply-dict-fixes+  "Oops I broke some stuff"+  [entries]+  (merge+   (into {}+         (map (fn [[k v]]+                {(if (some #(= \^  %) k)+                   (->> (str/replace k #"\^" "")+                        (str "^"))+                   k)+                 v})+              entries))+   (into {}+         (map (fn [[k v]]+                {(if (some #(= \* %) k)+                   (-> (str/replace k #"\*\*" "-")+                       (str/replace #"\*" "")+                       utils/starred)+                   k)+                 v})+              entries))))++(defn capitalize-entries+  "Capitalizes entries that have a #"+  [entries]+  (into {}+        (map (fn [[k v]]+               (if (= \# (first k))+                 (cond+                   (re-find #"\{>\}\{\^\}" v) {k (str/replace v #"\{>\}\{\^\}" "{^}{-|}")}+                   (re-find #"\{>\}" v) {k (str/replace v #"\{>\}" "{-|}")}+                   (re-find #"\{\^\}" v) {k (str/replace v #"\{\^\}." "{^}{-|}")}+                   :else {k (str "{-|}" v)})+                 {k v}))+             (utils/add-capitalized-entries entries))))++(defn- generate-starter-entries+  [opts]+  (let [prepend (or (:prepend opts) "")+        append (or (:append opts) "")+        vowel-stroke (:vowel-stroke opts)+        vowel (:vowel opts)+        starter-stroke (:starter-stroke opts)+        starter (:starter opts)]+    (merge+     {(str prepend "WHR" vowel-stroke starter-stroke)    (str "{>}" starter vowel append)}+     {(str prepend "TWHR" vowel-stroke starter-stroke)   (str "{>}" starter vowel append "e")}+     {(str prepend "SWHR" vowel-stroke starter-stroke)   (str "{>}" "{^}" starter vowel append)}+     {(str prepend "STWHR" vowel-stroke starter-stroke)  (str "{>}" "{^}" starter vowel append "e")})))++(defn generate-starters+  [starters vowels]+  (into {}+        (map (fn [[starter-stroke starter]]+               (reduce (fn [acc [vowel-stroke vowel]]+                         (conj acc+                               (merge+                                (if (re-find #"S" starter-stroke)+                                  (merge+                                     ;; TODO make this all one map and just one function call so it's less code.+                                   (generate-starter-entries {:append "t" :starter-stroke (str/replace starter-stroke #"S" "TS")+                                                              :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                   (generate-starter-entries {:append "ted" :starter-stroke (str/replace starter-stroke #"S" "TSDZ")+                                                              :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                   (generate-starter-entries {:append "rt" :starter-stroke (str/replace starter-stroke #"S" "TS")+                                                              :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                   (generate-starter-entries {:prepend "+" :append "rted" :starter-stroke (str/replace starter-stroke #"S" "TSDZ")+                                                              :starter starter :vowel-stroke vowel-stroke :vowel vowel}))+                                  (merge+                                   (generate-starter-entries {:append "t" :starter-stroke (str starter-stroke "T")+                                                              :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                   (generate-starter-entries {:prepend "+" :append "rt" :starter-stroke (str starter-stroke "T")+                                                              :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                   (generate-starter-entries {:prepend "+" :append "rted" :starter-stroke (str starter-stroke "TD")+                                                              :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                   (generate-starter-entries {:append "ted" :starter-stroke (str starter-stroke "TD")+                                                              :starter starter :vowel-stroke vowel-stroke :vowel vowel})))+                                (generate-starter-entries {:append "s" :starter-stroke (str starter-stroke "Z")+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                (generate-starter-entries {:prepend "+" :append "rs" :starter-stroke (str starter-stroke "Z")+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                (generate-starter-entries {:prepend "+" :append "r"+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                (generate-starter-entries {:append "n" :starter-stroke (str starter-stroke "*Z")+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                (generate-starter-entries {:prepend "+" :append "rn" :starter-stroke (str starter-stroke "*Z")+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                (generate-starter-entries {:prepend "^" :append "m" :starter-stroke (str starter-stroke "*Z")+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                (generate-starter-entries {:prepend "^+" :append "rm" :starter-stroke (str starter-stroke "*Z")+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                (generate-starter-entries {:append "y" :starter-stroke (str starter-stroke "*D")+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})+                                (generate-starter-entries {:prepend "+" :append "ry" :starter-stroke (str starter-stroke "*D")+                                                           :starter starter :vowel-stroke vowel-stroke :vowel vowel})

Show all 246 lines

src/dev/grahp/ametrine/utils.clj added (view file)

@@ -0,0 +1,94 @@+(ns dev.grahp.ametrine.utils+  (:require [clojure.string :as str]+            [clojure.edn :as edn]+            [clojure.data.json :as json]+            [clojure.java.io :as io])+  (:import [java.nio.file Paths]))++(defn stroke->str+  [stroke]+  (let [groups ["#^+" "STKPWHR" "AO*-EU" "FRPBLGTSDZ"]]+    (apply str (mapcat+                #(filter (get stroke %1) %2)+                (range) groups))))++(defn str->stroke+  [str]+  (when-let [match (re-matches #"^([\^]?[+]?[#]?)(.*?)([AOEU\-*]+)(.*)$" str)]+    (mapv set (rest match))))++(defn add-capitalized-entries+  "returns the entries passed in, including entries with #"+  [entries]+  (into {}+        (map (fn [[k v]]+               {k v+                (str "#" k) v}))+        entries))++(defn starred+  "Returns the starred version of the given stroke"+  [stroke]+  (if (some #(= \* %) stroke)+    stroke+    (or+      (some (fn [[regex replacement]]+              (when (re-find regex stroke)+                (str/replace stroke regex replacement)))+            [[#"AOEU" "AO*EU"]+             [#"AOU" "AO*U"]+             [#"AEU" "A*EU"]+             [#"AOE" "AO*E"]+             [#"OEU" "O*EU"]+             [#"AO" "AO*"]+             [#"EU" "*EU"]+             [#"AE" "A*E"]+             [#"AU" "A*U"]+             [#"OE" "O*E"]+             [#"OU" "O*U"]+             [#"A" "A*"]+             [#"O" "O*"]+             [#"E" "*E"]+             [#"U" "*U"]+             [#"-" "*"]])+      stroke)))++(defn absolute-path?+  "Returns whether the given path (string) is absolute"+  [path]+  ;; Some crazy java nonsense+  (-> (Paths/get path (into-array String []))+      .isAbsolute))++(defn spit-resource+  "Spits a file to the resource dir, or to an absolute path"+  [path contents]+  (try+    (if (absolute-path? path)+      (spit path contents)+      (spit (io/file "resources" path) contents))++    (catch Exception e+      (println (.getMessage e))+      (println "Failed to spit resource:" path)+      nil)))++(defn load-resource+  "Loads a file from the resource dir.+  Returns nil if the file is not present."+  [file]+  (try+    (edn/read-string+     (slurp (io/resource (str file ".edn"))))++    (catch Exception e+      (println (.getMessage e))+      (println "Failed to load resource:" file)+      nil)))++(defn transform-json+  "Transforms an edn dict into json"+  [dict]+  (-> dict+      (json/write-str :escape-slash false)+      (str/replace #"," ",\n")))