diff options
Diffstat (limited to 'keyboards/gboards/combos/_generator')
-rw-r--r-- | keyboards/gboards/combos/_generator/input.json | 99 | ||||
-rw-r--r-- | keyboards/gboards/combos/_generator/main.go | 60 |
2 files changed, 159 insertions, 0 deletions
diff --git a/keyboards/gboards/combos/_generator/input.json b/keyboards/gboards/combos/_generator/input.json new file mode 100644 index 000000000..022c4690e --- /dev/null +++ b/keyboards/gboards/combos/_generator/input.json @@ -0,0 +1,99 @@ +{ +"the ":"TH", +"of ":"OF", +"and ":"ND", +"to ":"TO", +"in ":"IN", +"for ":"FR", +"is ":"IS", +"on ":"ON", +"that ":"TA", +"by ":"BY", +"this ":"TS", +"with ":"WT", +"you ":"YU", +"it ":"IT", +"not ":"NT", +"or ":"OR", +"be ":"BE", +"are ":"AR", +"from ":"FE", +"at ":"AD", +"as ":"AS", +"your ":"UR", +"all ":"AL", +"have ":"HV", +"new ":"NU", +"more ":"MR", +"an ":"AN", +"was ":"WS", +"we ":"WI", +"will ":"WL", +"home ":"HM", +"can ":"CN", +"us ":"US", +"about ":"AB", +"if ":"IF", +"page ":"PG", +"my ":"MK", +"has ":"HS", +"search ":"SR", +"free ":"FH", +"but ":"BU", +"our ":"OU", +"one ":"WU", +"other ":"OH", +"do ":"DO", +"no ":"NK", +"information ":"IR", +"time ":"TM", +"they ":"TY", +"site ":"SY", +"he ":"HE", +"up ":"UP", +"may ":"MA", +"what ":"WA", +"which ":"WH", +"their ":"TR", +"news ":"NS", +"out ":"OG", +"use ":"UE", +"any ":"NE", +"there ":"TE", +"see ":"SE", +"only ":"LY", +"so ":"SO", +"his ":"HI", +"when ":"WN", +"contact ":"KT", +"here ":"HR", +"business ":"BS", +"who ":"WO", +"web ":"WB", +"also ":"LS", +"now ":"NQ", +"help ":"HL", +"get ":"GT", +"view ":"VU", +"online ":"LN", +"first ":"FS", +"been ":"BN", +"would ":"WD", +"how ":"HU", +"were ":"WR", +"me ":"ME", +"some ":"SM", +"these ":"TZ", +"click ":"CL", +"its ":"IZ", +"like ":"LK", +"service ":"SV", +"than ":"HN", +"find ":"FN", +"price ":"PR", +"date ":"DT", +"back ":"BK", +"top ":"TP", +"people ":"PE", +"had ":"HD" +} diff --git a/keyboards/gboards/combos/_generator/main.go b/keyboards/gboards/combos/_generator/main.go new file mode 100644 index 000000000..043c8b78c --- /dev/null +++ b/keyboards/gboards/combos/_generator/main.go @@ -0,0 +1,60 @@ +// Package for taking a mapping of words to keys and outputing a +// combo engine commpatible def + +package main + +import ( + "io/ioutil" + "fmt" + "encoding/json" + "os" + "sort" + "strings" + "hash/crc64" + //"encoding/base64" +) + +func main() { + // Show Usage + if len(os.Args) < 3 { + fmt.Println("Usage: ./keymap-gen inputfile outfile") + fmt.Println("Outputs dict in current dir") + return + } + + // Read the source + data, err := ioutil.ReadFile(os.Args[1]) + if err != nil { + panic(err) + } + + // Unbundle Data + var FullDict map[string]string + var output []string + json.Unmarshal(data, &FullDict) + + // Loop over entries and store + for i,v := range FullDict { + // This checks for colllisions, Generates hash + hash := crc64.Checksum([]byte(v), crc64.MakeTable(crc64.ECMA)) + hashStr := fmt.Sprintf("txt_%x", hash)[:10] + + // Format keys into combo + var keys string + for _, k := range(v) { + keys += fmt.Sprintf("KC_%v, ", string(k)) + + } + keys = keys[:len(keys)-2] + + // Append to output + spacer := strings.Repeat(" ", 15-len(i)) + output = append(output, fmt.Sprintf("SUBS(%v, %v\"%v\", %v)\n", hashStr, spacer, i, keys)) + } + + + sort.Slice(output, func (i,j int) bool { + return strings.Count(output[i], " ") > strings.Count(output[j], " ") + }) + ioutil.WriteFile(os.Args[2], []byte(strings.Join(output, "")), 0555) +} |