Rolls, metrics of other analyzers, and search from saved layouts

- Pair metrics of other analyzers (oxeylyzer, genkey, the Keyboard
  Layouts Doc): same-finger distance, lateral stretches, scissors and
  half scissors.
- Rolls: each window of three presses gets a class: a roll of two or
  three, inward or outward, a roll with the ring finger above the middle
  finger, alternation, a redirect or a bad redirect. A space ends a
  window and is on neither hand, so a word's first and last two presses
  also make a window. The search scores the word edges too.
- All the new numbers are 0 by default: the scores do not change. The
  report, the Layout tab and word.bjo show the shares of each class.
- optimize.bjo can start from a saved layout.
- The GUI test sets the window size before showing it, so the first
  screenshot is not narrow. New screenshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-11-17 22:47:34 +01:00
parent 50a9d43d14
commit e0d1bfdefb
14 changed files with 430 additions and 37 deletions

View file

@ -31,6 +31,17 @@ is better. A score is a cost per key press.
Each press past that share costs extra. Each press past that share costs extra.
- **Finger distance:** how far the fingers travel, in key widths per press. - **Finger distance:** how far the fingers travel, in key widths per press.
By default it is shown but not scored. By default it is shown but not scored.
- **Other analyzers:** metrics from oxeylyzer, genkey and the Keyboard
Layouts Doc: same-finger distance, lateral stretches, scissors and half
scissors.
- **Rolls:** each window of three presses gets a class: a roll of two, a
roll of three, alternation, a redirect or a bad redirect. A space ends a
window, and counts as neither hand, so a word's first and last two
presses can be a roll. A roll with the ring finger above the middle
finger is a broken roll.
The numbers of the last two groups are 0 by default: the report shows their
shares, but they do not change the scores.
`src/score.bjo` describes each rule. `src/board.bjo` describes the board `src/score.bjo` describes each rule. `src/board.bjo` describes the board
and the key costs. and the key costs.
@ -51,7 +62,7 @@ programs from this folder.
| --- | --- | | --- | --- |
| `bjo run .` | Prints the report: each layout's score on each text, the parts of the scores, and the pairs that cost each layout most. | | `bjo run .` | Prints the report: each layout's score on each text, the parts of the scores, and the pairs that cost each layout most. |
| `bjo run src/gui.bjo` | Opens the GUI. | | `bjo run src/gui.bjo` | Opens the GUI. |
| `bjo run src/optimize.bjo [runs] [steps] [layout] [t-start] [vowels-left] [fixed=CHARS]` | Searches for a better layout by simulated annealing. | | `bjo run src/optimize.bjo [runs] [steps] [layout] [t-start] [vowels-left] [fixed=CHARS]` | Searches for a better layout by simulated annealing. The layout can be a built-in or a saved one. |
| `bjo run src/swaps.bjo [char] [layout]` | Tries to swap one character with each other key. | | `bjo run src/swaps.bjo [char] [layout]` | Tries to swap one character with each other key. |
| `bjo run src/word.bjo word [layout]` | Shows what a word costs a layout, pair by pair. | | `bjo run src/word.bjo word [layout]` | Shows what a word costs a layout, pair by pair. |
| `bjo run tests/gui-shots.bjo [folder]` | Tests the GUI without a screen, and saves the screenshots in this file. | | `bjo run tests/gui-shots.bjo [folder]` | Tests the GUI without a screen, and saves the screenshots in this file. |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 KiB

After

Width:  |  Height:  |  Size: 348 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 KiB

After

Width:  |  Height:  |  Size: 201 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 KiB

After

Width:  |  Height:  |  Size: 340 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 KiB

After

Width:  |  Height:  |  Size: 366 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 KiB

After

Width:  |  Height:  |  Size: 285 KiB

Before After
Before After

View file

@ -33,7 +33,7 @@
(import (keyscore layouts)) (import (keyscore layouts))
(import (keyscore params)) (import (keyscore params))
(import (keyscore saved)) (import (keyscore saved))
(import (keyscore score)) (import (except (keyscore score) flow))
(import (keyscore search)) (import (keyscore search))
(import (keyscore texts)) (import (keyscore texts))
@ -693,7 +693,7 @@
(: (-> Model (View Msg))) (: (-> Model (View Msg)))
(defun (rules-view m) (defun (rules-view m)
(def groups ["Texts" "Keys" "Pairs" "Row motion" "Triples" "Pinky load" "Finger distance"]) (def groups ["Texts" "Keys" "Pairs" "Row motion" "Triples" "Pinky load" "Finger distance" "Other analyzers" "Rolls"])
(scroll (apply flow #:spacing 10.0 #:margin 8.0 (scroll (apply flow #:spacing 10.0 #:margin 8.0
(vec->array (vec-append [(presets-view m)] (vec-map (fun (g) (group-view m g)) groups)))))) (vec->array (vec-append [(presets-view m)] (vec-map (fun (g) (group-view m g)) groups))))))
@ -809,6 +809,7 @@
[(part "hand runs" (fun (s) (.runs s)) fixed) [(part "hand runs" (fun (s) (.runs s)) fixed)
(part "same-finger skips" (fun (s) (.skips s)) fixed) (part "same-finger skips" (fun (s) (.skips s)) fixed)
(part "two-finger runs" (fun (s) (.two-fingers s)) fixed) (part "two-finger runs" (fun (s) (.two-fingers s)) fixed)
(part "rolls, alternation, redirects" (fun (s) (.flows s)) fixed)
(part "pinky load" (fun (s) (.pinkies s)) fixed) (part "pinky load" (fun (s) (.pinkies s)) fixed)
(part "distance cost" (fun (s) (* (record-ref (.params m) distance) (.distance s))) fixed) (part "distance cost" (fun (s) (* (record-ref (.params m) distance) (.distance s))) fixed)
(part "total" (fun (s) (.total s)) fixed3) (part "total" (fun (s) (.total s)) fixed3)
@ -819,6 +820,17 @@
(part "triples in hand runs" (fun (s) (.run-share s)) pct) (part "triples in hand runs" (fun (s) (.run-share s)) pct)
(part "same-finger skip triples" (fun (s) (.skip-share s)) pct) (part "same-finger skip triples" (fun (s) (.skip-share s)) pct)
(part "two-finger run triples" (fun (s) (.two-finger-share s)) pct) (part "two-finger run triples" (fun (s) (.two-finger-share s)) pct)
(part "lateral stretches" (fun (s) (.lateral-share s)) pct)
(part "scissors" (fun (s) (.scissor-share s)) pct)
(part "half scissors" (fun (s) (.half-scissor-share s)) pct)
(part "inward rolls" (fun (s) (.inroll-share s)) pct)
(part "outward rolls" (fun (s) (.outroll-share s)) pct)
(part "alternation (triples)" (fun (s) (.alternate-share s)) pct)
(part "inward rolls of three" (fun (s) (.inroll3-share s)) pct)
(part "outward rolls of three" (fun (s) (.outroll3-share s)) pct)
(part "rolls with ring above middle" (fun (s) (.broken-share s)) pct)
(part "redirects" (fun (s) (.redirect-share s)) pct)
(part "bad redirects" (fun (s) (.bad-redirect-share s)) pct)
(part "left hand" (fun (s) (.left-hand s)) pct) (part "left hand" (fun (s) (.left-hand s)) pct)
(part "left pinky" (fun (s) (.left-pinky s)) pct) (part "left pinky" (fun (s) (.left-pinky s)) pct)
(part "right pinky" (fun (s) (.right-pinky s)) pct)])) (part "right pinky" (fun (s) (.right-pinky s)) pct)]))

View file

@ -85,6 +85,7 @@
[(row "hand runs" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x runs)) s)))) [(row "hand runs" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x runs)) s))))
(row "same-finger skips" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x skips)) s)))) (row "same-finger skips" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x skips)) s))))
(row "two-finger runs" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x two-fingers)) s)))) (row "two-finger runs" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x two-fingers)) s))))
(row "rolls, alternation, redirects" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x flows)) s))))
(row "pinky load" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x pinkies)) s)))) (row "pinky load" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x pinkies)) s))))
(row "finger distance" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x distance)) s)))) (row "finger distance" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x distance)) s))))
(row "total" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x total)) s)))) (row "total" scores (fun (s) (fixed (mean-of (fun (x) (record-ref x total)) s))))
@ -94,6 +95,17 @@
(row "triples in hand runs" scores (fun (s) (percent (mean-of (fun (x) (record-ref x run-share)) s)))) (row "triples in hand runs" scores (fun (s) (percent (mean-of (fun (x) (record-ref x run-share)) s))))
(row "same-finger skip triples" scores (fun (s) (percent (mean-of (fun (x) (record-ref x skip-share)) s)))) (row "same-finger skip triples" scores (fun (s) (percent (mean-of (fun (x) (record-ref x skip-share)) s))))
(row "two-finger run triples" scores (fun (s) (percent (mean-of (fun (x) (record-ref x two-finger-share)) s)))) (row "two-finger run triples" scores (fun (s) (percent (mean-of (fun (x) (record-ref x two-finger-share)) s))))
(row "lateral stretches" scores (fun (s) (percent (mean-of (fun (x) (record-ref x lateral-share)) s))))
(row "scissors" scores (fun (s) (percent (mean-of (fun (x) (record-ref x scissor-share)) s))))
(row "half scissors" scores (fun (s) (percent (mean-of (fun (x) (record-ref x half-scissor-share)) s))))
(row "inward rolls" scores (fun (s) (percent (mean-of (fun (x) (record-ref x inroll-share)) s))))
(row "outward rolls" scores (fun (s) (percent (mean-of (fun (x) (record-ref x outroll-share)) s))))
(row "alternation (triples)" scores (fun (s) (percent (mean-of (fun (x) (record-ref x alternate-share)) s))))
(row "inward rolls of three" scores (fun (s) (percent (mean-of (fun (x) (record-ref x inroll3-share)) s))))
(row "outward rolls of three" scores (fun (s) (percent (mean-of (fun (x) (record-ref x outroll3-share)) s))))
(row "rolls with ring above middle" scores (fun (s) (percent (mean-of (fun (x) (record-ref x broken-share)) s))))
(row "redirects" scores (fun (s) (percent (mean-of (fun (x) (record-ref x redirect-share)) s))))
(row "bad redirects" scores (fun (s) (percent (mean-of (fun (x) (record-ref x bad-redirect-share)) s))))
(row "left hand" scores (fun (s) (percent (mean-of (fun (x) (record-ref x left-hand)) s)))) (row "left hand" scores (fun (s) (percent (mean-of (fun (x) (record-ref x left-hand)) s))))
(row "left / right" scores (row "left / right" scores
(fun (s) (let ((l (mean-of (fun (x) (record-ref x left-hand)) s))) (fixed (/ l (- 1.0 l)))))) (fun (s) (let ((l (mean-of (fun (x) (record-ref x left-hand)) s))) (fixed (/ l (- 1.0 l))))))

View file

@ -4,8 +4,9 @@
;; ;;
;; - runs: independent searches, each with its own seed. 8 unless given. ;; - runs: independent searches, each with its own seed. 8 unless given.
;; - steps: swaps tried per run. 200000 unless given. ;; - steps: swaps tried per run. 200000 unless given.
;; - layout: the layout to start from, by name. The last in (keyscore layouts) ;; - layout: the layout to start from, by name: a built-in layout or a saved
;; unless given, or given as "-". ;; one (see (keyscore saved)). The last in (keyscore layouts) unless given,
;; or given as "-".
;; - t-start: the starting temperature. 0.02 unless given: a run refines the ;; - t-start: the starting temperature. 0.02 unless given: a run refines the
;; start layout rather than replacing it. ;; start layout rather than replacing it.
;; - options, after t-start, in any order: ;; - options, after t-start, in any order:
@ -23,6 +24,7 @@
(import (only (std fmt) numeric render->string)) (import (only (std fmt) numeric render->string))
(import (keyscore layouts)) (import (keyscore layouts))
(import (keyscore params)) (import (keyscore params))
(import (keyscore saved))
(import (keyscore score)) (import (keyscore score))
(import (keyscore search)) (import (keyscore search))
(import (keyscore texts)) (import (keyscore texts))
@ -35,7 +37,7 @@
(: named? (-> Layout bool)) (: named? (-> Layout bool))
(def named? (fun (l) (= (record-ref l name) (ref args 2)))) (def named? (fun (l) (= (record-ref l name) (ref args 2))))
(def start-layout (if (and (> (length args) 2) (not (= (ref args 2) "-"))) (def start-layout (if (and (> (length args) 2) (not (= (ref args 2) "-")))
(option-ref (find named? layouts)) (option-ref (find named? (vec-append layouts (read-saved-layouts))))
(vec-ref layouts (- (vec-length layouts) 1)))) (vec-ref layouts (- (vec-length layouts) 1))))
(def options (loop (:for i (range 4 (length args))) (:acc out (listing (ref args i))))) (def options (loop (:for i (range 4 (length args))) (:acc out (listing (ref args i)))))
(loop (:for o options) (loop (:for o options)

View file

@ -36,6 +36,11 @@
;; - hand-run, skip, two-finger: the triple rules. ;; - hand-run, skip, two-finger: the triple rules.
;; - pinky-limit, pinky-cost: the pinky load. ;; - pinky-limit, pinky-cost: the pinky load.
;; - distance: what a key width of finger travel costs. 0: only reported. ;; - distance: what a key width of finger travel costs. 0: only reported.
;; - sfb-distance, lateral-stretch, scissor, half-scissor: the pair rules of
;; other analyzers. 0: only reported.
;; - inroll, outroll, inroll3, outroll3, broken-roll, alternate, redirect,
;; bad-redirect: the window classes (rolls). 0: only reported. A negative
;; number is a bonus.
(type (: Params (Record (: corpora (Vec Corpus)) (type (: Params (Record (: corpora (Vec Corpus))
(: key-weight double) (: key-weight double)
(: key-costs (Vec double)) (: key-costs (Vec double))
@ -59,7 +64,19 @@
(: two-finger double) (: two-finger double)
(: pinky-limit double) (: pinky-limit double)
(: pinky-cost double) (: pinky-cost double)
(: distance double)))) (: distance double)
(: sfb-distance double)
(: lateral-stretch double)
(: scissor double)
(: half-scissor double)
(: inroll double)
(: outroll double)
(: inroll3 double)
(: outroll3 double)
(: broken-roll double)
(: alternate double)
(: redirect double)
(: bad-redirect double))))
(: Params) (: Params)
(def default-params (def default-params
@ -86,7 +103,19 @@
(two-finger 10.0) (two-finger 10.0)
(pinky-limit 0.08) (pinky-limit 0.08)
(pinky-cost 10.0) (pinky-cost 10.0)
(distance 0.0))) (distance 0.0)
(sfb-distance 0.0)
(lateral-stretch 0.0)
(scissor 0.0)
(half-scissor 0.0)
(inroll 0.0)
(outroll 0.0)
(inroll3 0.0)
(outroll3 0.0)
(broken-roll 0.0)
(alternate 0.0)
(redirect 0.0)
(bad-redirect 0.0)))
;; What a press of `k` costs: its cost times the key weight. ;; What a press of `k` costs: its cost times the key weight.
(: (-> Params Key double)) (: (-> Params Key double))
@ -239,7 +268,55 @@
(spec "distance" "Per key width of travel" "Finger distance" (spec "distance" "Per key width of travel" "Finger distance"
"The cost of each key width that a finger moves. A finger moves from its home key, or from the key it pressed just before. After a space it starts at home again. 0: the distance is shown but not scored." "The cost of each key width that a finger moves. A finger moves from its home key, or from the key it pressed just before. After a space it starts at home again. 0: the distance is shown but not scored."
(fun (p) (record-ref p distance)) (fun (p) (record-ref p distance))
(fun (p x) (record-set p (distance x))) 0.0 100.0 0.5)]) (fun (p x) (record-set p (distance x))) 0.0 100.0 0.5)
(cost-spec "sfb-distance" "Same finger, per key width" "Other analyzers"
"Added to a same-finger pair for each key width the finger moves, times a factor for the finger: index 1, middle 1.15, ring 1.53, pinky 3.67 (5.5 over genkey's finger speeds 5.5, 4.8, 3.6 and 1.5). Oxeylyzer and genkey score SFBs this way. It adds to Same finger."
(fun (p) (record-ref p sfb-distance))
(fun (p x) (record-set p (sfb-distance x))))
(cost-spec "lateral-stretch" "Lateral stretch" "Other analyzers"
"Added to a pair on one hand typed by two adjacent fingers 2 or more key widths apart: such as the index on the centre column and the middle finger, or the pinky past P and the ring finger. Genkey and the Keyboard Layouts Doc call it an LSB."
(fun (p) (record-ref p lateral-stretch))
(fun (p x) (record-set p (lateral-stretch x))))
(cost-spec "scissor" "Scissor (two rows)" "Other analyzers"
"Added to a pair on one hand typed by two adjacent fingers on the top and bottom rows, where the lower finger is the middle finger, or the ring finger below the pinky. The Keyboard Layouts Doc calls it an FSB. It adds to Jump."
(fun (p) (record-ref p scissor))
(fun (p x) (record-set p (scissor x))))
(cost-spec "half-scissor" "Half scissor (one row)" "Other analyzers"
"The same as Scissor, with the keys one row apart (HSB). Note that a ring finger on the top row with the middle finger on the home row is a half scissor, but costs only Outward or Inward in the row-motion table."
(fun (p) (record-ref p half-scissor))
(fun (p x) (record-set p (half-scissor x))))
(cost-spec "inroll" "Inward roll" "Rolls"
"Added for three presses where two in a row are on one hand by two fingers and move toward the index finger, and the third is on the other hand or a space. Use a negative number for a bonus. A roll with a bottom-row key off the index keys gets the bottom-row share. Oxeylyzer rewards inward rolls 2.5 and outward 2.4, against 0.4 for alternation."
(fun (p) (record-ref p inroll))
(fun (p x) (record-set p (inroll x))))
(cost-spec "outroll" "Outward roll" "Rolls"
"The same as Inward roll, with the two presses moving toward the pinky."
(fun (p) (record-ref p outroll))
(fun (p x) (record-set p (outroll x))))
(cost-spec "inroll3" "Inward roll of three" "Rolls"
"Added for three presses on one hand by three fingers that move toward the index finger, such as ring, middle, index. Use a negative number for a bonus. It adds to Hand run when the keys are on two rows."
(fun (p) (record-ref p inroll3))
(fun (p x) (record-set p (inroll3 x))))
(cost-spec "outroll3" "Outward roll of three" "Rolls"
"The same as Inward roll of three, with the presses moving toward the pinky."
(fun (p) (record-ref p outroll3))
(fun (p x) (record-set p (outroll3 x))))
(cost-spec "broken-roll" "Roll with ring above middle" "Rolls"
"Added instead of a roll bonus, for a roll of two or three where the ring finger is on a higher row than the middle finger, such as ring on the top row and middle on the home row. The middle finger can be higher."
(fun (p) (record-ref p broken-roll))
(fun (p x) (record-set p (broken-roll x))))
(cost-spec "alternate" "Alternation" "Rolls"
"Added for three presses on alternating hands: left, right, left or right, left, right. Use a negative number for a bonus."
(fun (p) (record-ref p alternate))
(fun (p x) (record-set p (alternate x))))
(cost-spec "redirect" "Redirect" "Rolls"
"Added for three presses on one hand by fingers that change direction, such as ring, index, middle, when one of them is the index finger. It adds to Hand run."
(fun (p) (record-ref p redirect))
(fun (p x) (record-set p (redirect x))))
(cost-spec "bad-redirect" "Bad redirect (no index)" "Rolls"
"Added instead of Redirect when no finger of the three is the index finger, such as ring, pinky, middle. Other analyzers weigh these more than redirects."
(fun (p) (record-ref p bad-redirect))
(fun (p x) (record-set p (bad-redirect x))))])
key-specs)) key-specs))
(: string) (: string)

View file

@ -73,6 +73,38 @@
;; - A space or a break between two presses lets the finger go home. ;; - A space or a break between two presses lets the finger go home.
;; - The way back is not counted. ;; - The way back is not counted.
;; - It costs 0 per key width (distance): it is reported, not scored. ;; - It costs 0 per key width (distance): it is reported, not scored.
;;
;; From other analyzers (oxeylyzer, genkey, cmini and the Keyboard Layouts
;; Doc). Each costs 0 by default: it is reported, not scored.
;; - sfb distance: a same-finger pair costs sfb-distance per key width the
;; finger moves, times 5.5 over the finger's speed in genkey: index 5.5,
;; middle 4.8, ring 3.6, pinky 1.5. It adds to the same-finger rule.
;; - lateral stretch: a pair on one hand by two adjacent fingers 2 or more key
;; widths apart, across (lateral-stretch). An LSB.
;; - scissors: a pair on one hand by two adjacent fingers on two rows, where
;; the lower finger is the middle finger, or the ring finger below the
;; pinky. Two rows apart is a scissor (scissor, an FSB), one row a half
;; scissor (half-scissor, an HSB).
;;
;; Rolls: each window of three presses with no space between gets a class,
;; by `flow`. A space or a break is on neither hand: a word's first two and
;; last two presses also make a window each, by `edge-flow`.
;; - roll: two presses in a row on one hand by two fingers, and the third on
;; the other hand or a space. Toward the index is inward (inroll), toward
;; the pinky outward (outroll).
;; - roll of three: all three on one hand by fingers that move one way
;; (inroll3, outroll3).
;; - broken roll: a roll, of two or three, with the ring finger on a higher
;; row than the middle finger of that hand (broken-roll). The middle finger
;; can be higher.
;; - alternation: the hands alternate (alternate).
;; - redirect: all three on one hand by fingers that change direction
;; (redirect). Without the index finger it is a bad redirect
;; (bad-redirect) instead.
;; - A window with one finger twice in a row is none of them.
;; - A roll with a `low?` key earns low-share of the roll bonus. A stretch key
;; does not lower it: the stretch rule charges the reach.
;; - Each costs 0 by default. A negative number is a bonus.
(import (std prelude)) (import (std prelude))
(import (std mutable map)) (import (std mutable map))
@ -82,7 +114,7 @@
(export Counts count-text count-files Rule rules pair-penalty triple-penalty hand-run (export Counts count-text count-files Rule rules pair-penalty triple-penalty hand-run
same-finger-skip two-finger-run pinky-penalty top-vowel home-travel pair-travel same-finger-skip two-finger-run pinky-penalty top-vowel home-travel pair-travel
Score score-layout pair-costs) Score score-layout pair-costs Flow flow flow-cost edge-flow edge-cost)
;; --- counting -------------------------------------------------------------- ;; --- counting --------------------------------------------------------------
@ -93,11 +125,15 @@
;; - spaced: how often each pair is typed with spaces between them. ;; - spaced: how often each pair is typed with spaces between them.
;; - triples: how often each three characters are typed one after the other, ;; - triples: how often each three characters are typed one after the other,
;; with no space between. ;; with no space between.
;; - edges: how often each pair is the first two or the last two presses of
;; a word. A word is a run of presses between spaces and breaks. A word of
;; two presses counts twice.
;; - chars: every character of the text, counted or not. ;; - chars: every character of the text, counted or not.
(type (: Counts (Record (: presses (MutableMap char int)) (type (: Counts (Record (: presses (MutableMap char int))
(: pairs (MutableMap (Tuple char char) int)) (: pairs (MutableMap (Tuple char char) int))
(: spaced (MutableMap (Tuple char char) int)) (: spaced (MutableMap (Tuple char char) int))
(: triples (MutableMap (Tuple char char char) int)) (: triples (MutableMap (Tuple char char char) int))
(: edges (MutableMap (Tuple char char) int))
(: chars int)))) (: chars int))))
(: (-> (MutableMap %k int) %k void)) (: (-> (MutableMap %k int) %k void))
@ -109,6 +145,15 @@
;; space or break between them. ;; space or break between them.
(type (: Prev (Record (: char (Option char)) (: before (Option char)) (: spaced? bool)))) (type (: Prev (Record (: char (Option char)) (: before (Option char)) (: spaced? bool))))
;; Counts the last two presses of the word that ends after `prev`, if it has
;; two or more.
(: (-> Counts Prev void))
(defun (end-word! counts prev)
(when (not (record-ref prev spaced?))
(when-let (p (record-ref prev char))
(when-let (b (record-ref prev before))
(count! (record-ref counts edges) (Tuple b p))))))
;; One character of the text: counted, a space, or a break. ;; One character of the text: counted, a space, or a break.
(: (-> Counts (-> char bool) Prev char Prev)) (: (-> Counts (-> char bool) Prev char Prev))
(defun (step counts counted? prev raw) (defun (step counts counted? prev raw)
@ -119,22 +164,29 @@
(def spaced? (record-ref prev spaced?)) (def spaced? (record-ref prev spaced?))
(when-let (p (record-ref prev char)) (when-let (p (record-ref prev char))
(count! (if spaced? (record-ref counts spaced) (record-ref counts pairs)) (Tuple p c)) (count! (if spaced? (record-ref counts spaced) (record-ref counts pairs)) (Tuple p c))
(when-let (b (record-ref prev before)) (when (not spaced?)
(when (not spaced?) (count! (record-ref counts triples) (Tuple b p c))))) (match (record-ref prev before)
((Some b) (count! (record-ref counts triples) (Tuple b p c)))
;; `p` started the word.
(None (count! (record-ref counts edges) (Tuple p c))))))
(Prev (char (Some c)) (before (if spaced? None (record-ref prev char))) (spaced? #f))) (Prev (char (Some c)) (before (if spaced? None (record-ref prev char))) (spaced? #f)))
((or (char=? c #\space) (char=? c (int->char 0xA0))) ((or (char=? c #\space) (char=? c (int->char 0xA0)))
(end-word! counts prev)
(Prev (char (record-ref prev char)) (before None) (spaced? #t))) (Prev (char (record-ref prev char)) (before None) (spaced? #t)))
(else (Prev (char None) (before None) (spaced? #f))))) (else
(end-word! counts prev)
(Prev (char None) (before None) (spaced? #f)))))
;; The counts of `text`, for the characters `counted?` holds for. The ;; The counts of `text`, for the characters `counted?` holds for. The
;; characters are normalized first: see `normalize`. ;; characters are normalized first: see `normalize`.
(: (-> string (-> char bool) Counts)) (: (-> string (-> char bool) Counts))
(defun (count-text text counted?) (defun (count-text text counted?)
(def counts (Counts (presses (mutablemap)) (pairs (mutablemap)) (spaced (mutablemap)) (def counts (Counts (presses (mutablemap)) (pairs (mutablemap)) (spaced (mutablemap))
(triples (mutablemap)) (chars (string-length text)))) (triples (mutablemap)) (edges (mutablemap)) (chars (string-length text))))
(ignore (loop (:for c text) (def last (loop (:for c text)
(:acc prev (folding (Prev (char None) (before None) (spaced? #f)) (:acc prev (folding (Prev (char None) (before None) (spaced? #f))
(step counts counted? prev c))))) (step counts counted? prev c)))))
(end-word! counts last)
counts) counts)
;; The counts of each file in `paths`, for the characters every layout in ;; The counts of each file in `paths`, for the characters every layout in
@ -216,6 +268,42 @@
(defun (roll-share p a b) (defun (roll-share p a b)
(if (or (low? a) (low? b)) (record-ref p low-share) 1.0)) (if (or (low? a) (low? b)) (record-ref p low-share) 1.0))
;; Whether `a` and `b` are typed by two neighbouring fingers.
(: (-> Key Key bool))
(defun (adjacent-fingers? a b) (= (abs (- (record-ref a finger) (record-ref b finger))) 1))
;; What a key width of same-finger travel costs `k`'s finger, against the
;; index finger's 1: 5.5 over the finger's speed in genkey.
(: (-> Key double))
(defun (finger-factor k)
(match (record-ref k finger)
(0 (/ 5.5 1.5))
(1 (/ 5.5 3.6))
(2 (/ 5.5 4.8))
(_ 1.0)))
;; Whether `a` and `b` make a lateral stretch: adjacent fingers 2 or more key
;; widths apart, across.
(: (-> Key Key bool))
(defun (lateral? a b)
(def (Tuple xa _) (key-position a))
(def (Tuple xb _) (key-position b))
(and (adjacent-fingers? a b) (>= (abs (- xa xb)) 1.999)))
;; How many rows apart `a` and `b` are, if they make a scissor, else 0. See
;; the header.
(: (-> Key Key int))
(defun (scissor-rows a b)
(def ra (record-ref a row))
(def rb (record-ref b row))
(def lower (if (> ra rb) a b))
(def higher (if (> ra rb) b a))
(def lf (record-ref lower finger))
(if (and (adjacent-fingers? a b) (not (= ra rb))
(or (= lf 2) (and (= lf 1) (= (record-ref higher finger) 0))))
(abs (- ra rb))
0))
;; The rules' penalties, for a pair on one hand. ;; The rules' penalties, for a pair on one hand.
(: (-> Params Key Key double)) (: (-> Params Key Key double))
@ -267,6 +355,21 @@
(= (record-ref a row) (record-ref b row)) (= (record-ref a row) (record-ref b row))
(= (abs (- (record-ref a column) (record-ref b column))) 1))))) (= (abs (- (record-ref a column) (record-ref b column))) 1)))))
(: (-> Params Key Key double))
(defun (sfb-distance p a b)
(if (two-fingers? a b)
0.0
(* (record-ref p sfb-distance) (key-distance a b) (finger-factor a))))
(: (-> Params Key Key double))
(defun (lateral-stretch p a b) (* (record-ref p lateral-stretch) (one-if (lateral? a b))))
(: (-> Params Key Key double))
(defun (scissor p a b) (* (record-ref p scissor) (one-if (= (scissor-rows a b) 2))))
(: (-> Params Key Key double))
(defun (half-scissor p a b) (* (record-ref p half-scissor) (one-if (= (scissor-rows a b) 1))))
(: (Vec Rule)) (: (Vec Rule))
(def rules (def rules
[(Rule (name "stretch") (penalty stretch)) [(Rule (name "stretch") (penalty stretch))
@ -275,7 +378,11 @@
(Rule (name "jump") (penalty jump)) (Rule (name "jump") (penalty jump))
(Rule (name "easy jump") (penalty easy-jump)) (Rule (name "easy jump") (penalty easy-jump))
(Rule (name "close keys") (penalty close-keys)) (Rule (name "close keys") (penalty close-keys))
(Rule (name "adjacent keys") (penalty adjacent-keys))]) (Rule (name "adjacent keys") (penalty adjacent-keys))
(Rule (name "sfb distance") (penalty sfb-distance))
(Rule (name "lateral stretch") (penalty lateral-stretch))
(Rule (name "scissor") (penalty scissor))
(Rule (name "half scissor") (penalty half-scissor))])
;; Whether the rules score the pair at all: one hand, two keys. ;; Whether the rules score the pair at all: one hand, two keys.
(: (-> Key Key bool)) (: (-> Key Key bool))
@ -330,10 +437,93 @@
(record-ref p two-finger) (record-ref p two-finger)
0.0)) 0.0))
;; The class of a window of presses. See the header.
(type (: Flow (Union InRoll OutRoll InRoll3 OutRoll3 BrokenRoll Alternation Redirect BadRedirect
NoFlow)))
;; Whether `x` and `y` are the ring and the middle finger of one hand, with
;; the ring finger on a higher row.
(: (-> Key Key bool))
(defun (ring-above? x y)
(: above? (-> Key Key bool))
(def above? (fun (r m) (and (= (record-ref r finger) 1) (= (record-ref m finger) 2)
(< (record-ref r row) (record-ref m row)))))
(and (= (record-ref x left?) (record-ref y left?)) (or (above? x y) (above? y x))))
;; The roll of `x` then `y` on one hand: inward toward the index, outward
;; toward the pinky, broken with the ring finger above the middle finger, or
;; none for one finger.
(: (-> Key Key Flow))
(defun (roll-of x y)
(def fx (record-ref x finger))
(def fy (record-ref y finger))
(cond ((= fx fy) NoFlow)
((ring-above? x y) BrokenRoll)
((> fy fx) InRoll)
(else OutRoll)))
;; The class of `a`, `b` and then `c`.
(: (-> Key Key Key Flow))
(defun (flow a b c)
(def ha (record-ref a left?))
(def hb (record-ref b left?))
(def hc (record-ref c left?))
(def fa (record-ref a finger))
(def fb (record-ref b finger))
(def fc (record-ref c finger))
(cond ((and (not (= ha hb)) (not (= hb hc))) Alternation)
((not (= hb hc)) (roll-of a b))
((not (= ha hb)) (roll-of b c))
((or (= fa fb) (= fb fc)) NoFlow)
((= (> fb fa) (> fc fb))
(cond ((or (ring-above? a b) (ring-above? b c) (ring-above? a c)) BrokenRoll)
((> fb fa) InRoll3)
(else OutRoll3)))
((or (index? a) (index? b) (index? c)) Redirect)
(else BadRedirect)))
;; The class of `a` then `b` at the start or the end of a word: the space or
;; break is on neither hand.
(: (-> Key Key Flow))
(defun (edge-flow a b)
(if (= (record-ref a left?) (record-ref b left?)) (roll-of a b) Alternation))
;; The share of a roll bonus that a roll on `ks` earns: low-share with a
;; `low?` key, else all.
(: (-> Params (List Key) double))
(defun (roll-factor p ks)
(if (any? low? ks) (record-ref p low-share) 1.0))
;; What class `f` costs, for a window whose keys on the hand of the roll are
;; `ks`.
(: (-> Params Flow (List Key) double))
(defun (class-cost p f ks)
(match f
(InRoll (* (record-ref p inroll) (roll-factor p ks)))
(OutRoll (* (record-ref p outroll) (roll-factor p ks)))
(InRoll3 (* (record-ref p inroll3) (roll-factor p ks)))
(OutRoll3 (* (record-ref p outroll3) (roll-factor p ks)))
(BrokenRoll (record-ref p broken-roll))
(Alternation (record-ref p alternate))
(Redirect (record-ref p redirect))
(BadRedirect (record-ref p bad-redirect))
(NoFlow 0.0)))
;; What the class of `a`, `b` and then `c` costs.
(: (-> Params Key Key Key double))
(defun (flow-cost p a b c)
(: on-b-hand? (-> Key bool))
(def on-b-hand? (fun (k) (= (record-ref k left?) (record-ref b left?))))
(class-cost p (flow a b c) (->list (filter on-b-hand? (list a b c)))))
;; What the class of `a` then `b` at the start or the end of a word costs.
(: (-> Params Key Key double))
(defun (edge-cost p a b) (class-cost p (edge-flow a b) (list a b)))
;; What the triple rules charge for `a`, `b` and then `c`. ;; What the triple rules charge for `a`, `b` and then `c`.
(: (-> Params Key Key Key double)) (: (-> Params Key Key Key double))
(defun (triple-penalty p a b c) (defun (triple-penalty p a b c)
(+ (hand-run p a b c) (same-finger-skip p a b c) (two-finger-run p a b c))) (+ (hand-run p a b c) (same-finger-skip p a b c) (two-finger-run p a b c) (flow-cost p a b c)))
;; --- scoring ------------------------------------------------------------------- ;; --- scoring -------------------------------------------------------------------
@ -344,6 +534,7 @@
;; - rules: each rule's share, in the order of `rules`. ;; - rules: each rule's share, in the order of `rules`.
;; - runs: the hand-run rule's share. skips: the same-finger-skip rule's. ;; - runs: the hand-run rule's share. skips: the same-finger-skip rule's.
;; two-fingers: the two-finger-run rule's. ;; two-fingers: the two-finger-run rule's.
;; - flows: the cost of the window classes: rolls, alternation and redirects.
;; - pinkies: the pinky load's penalty, both pinkies together. ;; - pinkies: the pinky load's penalty, both pinkies together.
;; - distance: the finger distance, in key widths. Its cost is distance times ;; - distance: the finger distance, in key widths. Its cost is distance times
;; the distance parameter. ;; the distance parameter.
@ -354,6 +545,11 @@
;; - same-finger: the share of pairs typed by one finger on two keys. ;; - same-finger: the share of pairs typed by one finger on two keys.
;; - run-share, skip-share, two-finger-share: the share of triples each triple ;; - run-share, skip-share, two-finger-share: the share of triples each triple
;; rule charges. ;; rule charges.
;; - lateral-share, scissor-share, half-scissor-share: the share of pairs (with
;; no space between) that are each.
;; - inroll-share, outroll-share, inroll3-share, outroll3-share,
;; broken-share, alternate-share, redirect-share, bad-redirect-share: the
;; share of windows of each class, word edges included.
;; - left-hand: the left hand's share of the presses. ;; - left-hand: the left hand's share of the presses.
;; - left-pinky, right-pinky: each pinky's share of the presses. ;; - left-pinky, right-pinky: each pinky's share of the presses.
(type (: Score (Record (: presses int) (type (: Score (Record (: presses int)
@ -363,6 +559,7 @@
(: runs double) (: runs double)
(: skips double) (: skips double)
(: two-fingers double) (: two-fingers double)
(: flows double)
(: pinkies double) (: pinkies double)
(: distance double) (: distance double)
(: total double) (: total double)
@ -372,6 +569,17 @@
(: run-share double) (: run-share double)
(: skip-share double) (: skip-share double)
(: two-finger-share double) (: two-finger-share double)
(: lateral-share double)
(: scissor-share double)
(: half-scissor-share double)
(: inroll-share double)
(: outroll-share double)
(: alternate-share double)
(: inroll3-share double)
(: outroll3-share double)
(: broken-share double)
(: redirect-share double)
(: bad-redirect-share double)
(: left-hand double) (: left-hand double)
(: left-pinky double) (: left-pinky double)
(: right-pinky double)))) (: right-pinky double))))
@ -428,7 +636,16 @@
(def runs (per-press (triple-sum (fun (a b c) (hand-run p a b c))))) (def runs (per-press (triple-sum (fun (a b c) (hand-run p a b c)))))
(def skips (per-press (triple-sum (fun (a b c) (same-finger-skip p a b c))))) (def skips (per-press (triple-sum (fun (a b c) (same-finger-skip p a b c)))))
(def two-fingers (per-press (triple-sum (fun (a b c) (two-finger-run p a b c))))) (def two-fingers (per-press (triple-sum (fun (a b c) (two-finger-run p a b c)))))
(def edges (record-ref counts edges))
(def flows (per-press (+ (triple-sum (fun (a b c) (flow-cost p a b c)))
(pair-sum edges (fun (a b) (edge-cost p (key a) (key b)))))))
(def triple-count (triple-sum (fun (a b c) 1.0))) (def triple-count (triple-sum (fun (a b c) 1.0)))
(def window-count (+ triple-count (pair-sum edges (fun (a b) 1.0))))
(: flow-share (-> (-> Flow bool) double))
(def flow-share
(fun (f) (/ (+ (triple-sum (fun (a b c) (if (f (flow a b c)) 1.0 0.0)))
(pair-sum edges (fun (a b) (if (f (edge-flow (key a) (key b))) 1.0 0.0))))
window-count)))
(def pair-count (pair-sum pairs (fun (a b) 1.0))) (def pair-count (pair-sum pairs (fun (a b) 1.0)))
(def share (def share
(fun (f) (/ (pair-sum pairs (fun (a b) (if (f (key a) (key b)) 1.0 0.0))) pair-count))) (fun (f) (/ (pair-sum pairs (fun (a b) (if (f (key a) (key b)) 1.0 0.0))) pair-count)))
@ -439,10 +656,11 @@
(runs runs) (runs runs)
(skips skips) (skips skips)
(two-fingers two-fingers) (two-fingers two-fingers)
(flows flows)
(pinkies pinkies) (pinkies pinkies)
(distance distance) (distance distance)
(total (+ position top-vowels (vec-fold (fun (x y) (+ x y)) 0.0 rule-totals) runs skips (total (+ position top-vowels (vec-fold (fun (x y) (+ x y)) 0.0 rule-totals) runs skips
two-fingers pinkies (* (record-ref p distance) distance))) two-fingers flows pinkies (* (record-ref p distance) distance)))
(home (press-share (fun (k) (= (record-ref k row) 1)))) (home (press-share (fun (k) (= (record-ref k row) 1))))
(left-pinky left-pinky) (left-pinky left-pinky)
(right-pinky right-pinky) (right-pinky right-pinky)
@ -451,6 +669,17 @@
(run-share (/ (triple-sum (fun (a b c) (if (> (hand-run p a b c) 0.0) 1.0 0.0))) triple-count)) (run-share (/ (triple-sum (fun (a b c) (if (> (hand-run p a b c) 0.0) 1.0 0.0))) triple-count))
(skip-share (/ (triple-sum (fun (a b c) (if (> (same-finger-skip p a b c) 0.0) 1.0 0.0))) triple-count)) (skip-share (/ (triple-sum (fun (a b c) (if (> (same-finger-skip p a b c) 0.0) 1.0 0.0))) triple-count))
(two-finger-share (/ (triple-sum (fun (a b c) (if (> (two-finger-run p a b c) 0.0) 1.0 0.0))) triple-count)) (two-finger-share (/ (triple-sum (fun (a b c) (if (> (two-finger-run p a b c) 0.0) 1.0 0.0))) triple-count))
(lateral-share (share (fun (a b) (and (scored-pair? a b) (lateral? a b)))))
(scissor-share (share (fun (a b) (and (scored-pair? a b) (= (scissor-rows a b) 2)))))
(half-scissor-share (share (fun (a b) (and (scored-pair? a b) (= (scissor-rows a b) 1)))))
(inroll-share (flow-share (fun (f) (match f (InRoll #t) (_ #f)))))
(outroll-share (flow-share (fun (f) (match f (OutRoll #t) (_ #f)))))
(alternate-share (flow-share (fun (f) (match f (Alternation #t) (_ #f)))))
(inroll3-share (flow-share (fun (f) (match f (InRoll3 #t) (_ #f)))))
(outroll3-share (flow-share (fun (f) (match f (OutRoll3 #t) (_ #f)))))
(broken-share (flow-share (fun (f) (match f (BrokenRoll #t) (_ #f)))))
(redirect-share (flow-share (fun (f) (match f (Redirect #t) (_ #f)))))
(bad-redirect-share (flow-share (fun (f) (match f (BadRedirect #t) (_ #f)))))
(left-hand (press-share (fun (k) (record-ref k left?)))))) (left-hand (press-share (fun (k) (record-ref k left?))))))
;; The score of each pair, per key press: what the pair costs `layout` on ;; The score of each pair, per key press: what the pair costs `layout` on

View file

@ -57,8 +57,9 @@
(type (: Found (Record (: score double) (: rows (Vec string))))) (type (: Found (Record (: score double) (: rows (Vec string)))))
;; A text, by unit: its weight in the mean, presses, the pairs typed with ;; A text, by unit: its weight in the mean, presses, the pairs typed with
;; their weights (a pair with spaces between weighs `spaced`) and their ;; their weights (a pair with spaces between weighs `spaced`), their counts
;; counts with no space between, and the triples with their counts. ;; with no space between and their counts at a word's start or end, and the
;; triples with their counts.
(type (: Text (Record (: share double) (type (: Text (Record (: share double)
(: presses double) (: presses double)
(: units (Array double)) (: units (Array double))
@ -66,6 +67,7 @@
(: second (Array int)) (: second (Array int))
(: weight (Array double)) (: weight (Array double))
(: plain (Array double)) (: plain (Array double))
(: edge (Array double))
(: triple-a (Array int)) (: triple-a (Array int))
(: triple-b (Array int)) (: triple-b (Array int))
(: triple-c (Array int)) (: triple-c (Array int))
@ -80,7 +82,8 @@
;; the key's cost, `top-vowel` and the travel from home. ;; the key's cost, `top-vowel` and the travel from home.
;; - penalties: the penalty of each pair of keys, at [a * keys + b]. ;; - penalties: the penalty of each pair of keys, at [a * keys + b].
;; travels: the distance cost of each pair with no space between, by ;; travels: the distance cost of each pair with no space between, by
;; `pair-travel`. triple-penalties: of each triple, at ;; `pair-travel`. edge-penalties: the cost of each pair at a word's start
;; or end, by `edge-cost`. triple-penalties: of each triple, at
;; [(a * keys + b) * keys + c]. ;; [(a * keys + b) * keys + c].
;; - left-pinky, right-pinky: whether each key is typed by that pinky. ;; - left-pinky, right-pinky: whether each key is typed by that pinky.
;; - left-keys: whether each key is on the left hand. ;; - left-keys: whether each key is on the left hand.
@ -92,6 +95,7 @@
(: costs (Array double)) (: costs (Array double))
(: penalties (Array double)) (: penalties (Array double))
(: travels (Array double)) (: travels (Array double))
(: edge-penalties (Array double))
(: triple-penalties (Array double)) (: triple-penalties (Array double))
(: left-pinky (Array bool)) (: left-pinky (Array bool))
(: right-pinky (Array bool)) (: right-pinky (Array bool))
@ -108,18 +112,22 @@
(loop (:for (Tuple c k) (record-ref counts presses)) (loop (:for (Tuple c k) (record-ref counts presses))
(:let u (map-ref unit-of c)) (:let u (map-ref unit-of c))
(:do (array-set! presses u (+ (array-ref presses u) (cast double k))))) (:do (array-set! presses u (+ (array-ref presses u) (cast double k)))))
;; Each pair of units: its weight, and its count with no space between. ;; Each pair of units: its weight, its count with no space between, and
(def (: pairs (MutableMap (Tuple int int) (Tuple double double))) (mutablemap)) ;; its count at a word's start or end.
(: add! (-> (MutableMap (Tuple char char) int) double double void)) (def (: pairs (MutableMap (Tuple int int) (Tuple double double double))) (mutablemap))
(def add! (fun (m weight plain) (: add! (-> (MutableMap (Tuple char char) int) double double double void))
(def add! (fun (m weight plain edge)
(loop (:for (Tuple pair k) m) (loop (:for (Tuple pair k) m)
(:let (Tuple a b) pair) (:let (Tuple a b) pair)
(:let n (cast double k)) (:let n (cast double k))
(:do (mutablemap-update! pairs (Tuple (map-ref unit-of a) (map-ref unit-of b)) (:do (mutablemap-update! pairs (Tuple (map-ref unit-of a) (map-ref unit-of b))
(fun (w) (Tuple (+ (fst w) (* weight n)) (+ (snd w) (* plain n)))) (fun (w)
#:default (Some (Tuple 0.0 0.0))))))) (def (Tuple w0 w1 w2) w)
(add! (record-ref counts pairs) 1.0 1.0) (Tuple (+ w0 (* weight n)) (+ w1 (* plain n)) (+ w2 (* edge n))))
(add! (record-ref counts spaced) (record-ref params spaced) 0.0) #:default (Some (Tuple 0.0 0.0 0.0)))))))
(add! (record-ref counts pairs) 1.0 1.0 0.0)
(add! (record-ref counts spaced) (record-ref params spaced) 0.0 0.0)
(add! (record-ref counts edges) 0.0 0.0 1.0)
(def entries (->vec pairs)) (def entries (->vec pairs))
(def (: triples (MutableMap (Tuple int int int) double)) (mutablemap)) (def (: triples (MutableMap (Tuple int int int) double)) (mutablemap))
(loop (:for (Tuple t k) (record-ref counts triples)) (loop (:for (Tuple t k) (record-ref counts triples))
@ -137,8 +145,9 @@
(units presses) (units presses)
(first (vec->array (vec-map (fun (e) (fst (fst e))) entries))) (first (vec->array (vec-map (fun (e) (fst (fst e))) entries)))
(second (vec->array (vec-map (fun (e) (snd (fst e))) entries))) (second (vec->array (vec-map (fun (e) (snd (fst e))) entries)))
(weight (vec->array (vec-map (fun (e) (fst (snd e))) entries))) (weight (vec->array (vec-map (fun (e) (def (Tuple w _ _) (snd e)) w) entries)))
(plain (vec->array (vec-map (fun (e) (snd (snd e))) entries))) (plain (vec->array (vec-map (fun (e) (def (Tuple _ w _) (snd e)) w) entries)))
(edge (vec->array (vec-map (fun (e) (def (Tuple _ _ w) (snd e)) w) entries)))
(triple-a (tri-unit 0)) (triple-a (tri-unit 0))
(triple-b (tri-unit 1)) (triple-b (tri-unit 1))
(triple-c (tri-unit 2)) (triple-c (tri-unit 2))
@ -195,6 +204,7 @@
(costs costs) (costs costs)
(penalties (pair-table (fun (a b) (pair-penalty params a b)))) (penalties (pair-table (fun (a b) (pair-penalty params a b))))
(travels (pair-table (fun (a b) (* distance (pair-travel a b))))) (travels (pair-table (fun (a b) (* distance (pair-travel a b)))))
(edge-penalties (pair-table (fun (a b) (edge-cost params a b))))
(triple-penalties triple-penalties) (triple-penalties triple-penalties)
(left-pinky (vec->array (vec-map (fun (k) (pinky? #t k)) board))) (left-pinky (vec->array (vec-map (fun (k) (pinky? #t k)) board)))
(right-pinky (vec->array (vec-map (fun (k) (pinky? #f k)) board))) (right-pinky (vec->array (vec-map (fun (k) (pinky? #f k)) board)))
@ -211,6 +221,7 @@
(def costs (record-ref p costs)) (def costs (record-ref p costs))
(def penalties (record-ref p penalties)) (def penalties (record-ref p penalties))
(def travels (record-ref p travels)) (def travels (record-ref p travels))
(def epen (record-ref p edge-penalties))
(def tpen (record-ref p triple-penalties)) (def tpen (record-ref p triple-penalties))
(def left (record-ref p left-pinky)) (def left (record-ref p left-pinky))
(def right (record-ref p right-pinky)) (def right (record-ref p right-pinky))
@ -223,6 +234,7 @@
(def second (record-ref t second)) (def second (record-ref t second))
(def weight (record-ref t weight)) (def weight (record-ref t weight))
(def plain (record-ref t plain)) (def plain (record-ref t plain))
(def edge (record-ref t edge))
(def total (record-ref t presses)) (def total (record-ref t presses))
(def keys-cost (def keys-cost
(loop (:for u (range 0 units)) (loop (:for u (range 0 units))
@ -231,7 +243,8 @@
(loop (:for i (range 0 (array-length first))) (loop (:for i (range 0 (array-length first)))
(:let at (+ (* (array-ref on (array-ref first i)) n) (array-ref on (array-ref second i)))) (:let at (+ (* (array-ref on (array-ref first i)) n) (array-ref on (array-ref second i))))
(:acc s (summing (+ (* (array-ref weight i) (array-ref penalties at)) (:acc s (summing (+ (* (array-ref weight i) (array-ref penalties at))
(* (array-ref plain i) (array-ref travels at))))))) (* (array-ref plain i) (array-ref travels at))
(* (array-ref edge i) (array-ref epen at)))))))
(def ta (record-ref t triple-a)) (def ta (record-ref t triple-a))
(def tb (record-ref t triple-b)) (def tb (record-ref t triple-b))
(def tc (record-ref t triple-c)) (def tc (record-ref t triple-c))

View file

@ -3,9 +3,12 @@
;; bjo run src/word.bjo word [layout] ;; bjo run src/word.bjo word [layout]
;; ;;
;; - layout: by name, the last in (keyscore layouts) unless given. ;; - layout: by name, the last in (keyscore layouts) unless given.
;; - Prints each pair's penalty by rule, each triple's hand-run and ;; - Prints each pair's penalty by rule, each triple's hand-run,
;; same-finger-skip penalties, and how often the corpora type each, per ;; same-finger-skip and two-finger-run penalties and its class with the
;; class's cost, and how often the corpora type each, per
;; million key presses. ;; million key presses.
;; - The word's first two and last two presses make a window each too, with
;; the space on neither hand. They are written "_ab" and "ab_".
(import (std prelude)) (import (std prelude))
(import (std maths)) (import (std maths))
@ -39,6 +42,20 @@
(defun (per-million n c) (defun (per-million n c)
(displayed (cast long (/ (* 1000000.0 (cast double n)) (cast double (presses-of c)))))) (displayed (cast long (/ (* 1000000.0 (cast double n)) (cast double (presses-of c))))))
;; The name of a triple class, as the report writes it.
(: (-> Flow string))
(defun (flow-name f)
(match f
(InRoll "inward roll")
(OutRoll "outward roll")
(InRoll3 "inward roll of three")
(OutRoll3 "outward roll of three")
(BrokenRoll "roll with ring above middle")
(Alternation "alternation")
(Redirect "redirect")
(BadRedirect "bad redirect")
(NoFlow "no class")))
(: (-> double string)) (: (-> double string))
(defun (num x) (defun (num x)
(if (= x (floor x)) (displayed (cast long x)) (render->string (numeric x #:precision 2)))) (if (= x (floor x)) (displayed (cast long x)) (render->string (numeric x #:precision 2))))
@ -46,6 +63,7 @@
(defun (main args) (defun (main args)
(def params (current-params)) (def params (current-params))
(def word (->list (map normalize (ref args 0)))) (def word (->list (map normalize (ref args 0))))
(def wv (list->vec word))
(: named? (-> Layout bool)) (: named? (-> Layout bool))
(def named? (fun (l) (= (record-ref l name) (ref args 1)))) (def named? (fun (l) (= (record-ref l name) (ref args 1))))
(def l (if (> (length args) 1) (def l (if (> (length args) 1)
@ -78,7 +96,14 @@
(if (= travel 0.0) "" (str " travel " (num travel) " from home")) (if (= travel 0.0) "" (str " travel " (num travel) " from home"))
" typed " (string-join (vec-map (fun (c) (per-million (pair-count c (Tuple a b)) c)) counts) " / "))))) " typed " (string-join (vec-map (fun (c) (per-million (pair-count c (Tuple a b)) c)) counts) " / ")))))
(println "") (println "")
(println "Triples:") (println "Windows:")
(: edge (-> string char char void))
(def edge (fun (shown a b)
(def ka (key a))
(def kb (key b))
(println (str " " shown " " (flow-name (edge-flow ka kb)) " " (num (edge-cost params ka kb))))))
(when (>= (vec-length wv) 2)
(edge (str "_" (char->string (vec-ref wv 0)) (char->string (vec-ref wv 1))) (vec-ref wv 0) (vec-ref wv 1)))
(loop (:for a word) (:for b (list-tail word)) (:for c (list-tail (list-tail word))) (loop (:for a word) (:for b (list-tail word)) (:for c (list-tail (list-tail word)))
(:let ka (key a)) (:let ka (key a))
(:let kb (key b)) (:let kb (key b))
@ -87,5 +112,11 @@
" hand run " (num (hand-run params ka kb kc)) " hand run " (num (hand-run params ka kb kc))
", same-finger skip " (num (same-finger-skip params ka kb kc)) ", same-finger skip " (num (same-finger-skip params ka kb kc))
", two-finger run " (num (two-finger-run params ka kb kc)) ", two-finger run " (num (two-finger-run params ka kb kc))
", " (flow-name (flow ka kb kc)) " " (num (flow-cost params ka kb kc))
" typed " (string-join (vec-map (fun (x) (per-million (triple-count x (Tuple a b c)) x)) counts) " / "))))) " typed " (string-join (vec-map (fun (x) (per-million (triple-count x (Tuple a b c)) x)) counts) " / ")))))
(def n (vec-length wv))
(when (>= n 2)
(def a (vec-ref wv (- n 2)))
(def b (vec-ref wv (- n 1)))
(edge (str (char->string a) (char->string b) "_") a b))
0) 0)

View file

@ -50,6 +50,8 @@
(current-app (: Avalonia.Application.Current #:get)) (current-app (: Avalonia.Application.Current #:get))
(content! (: Avalonia.Controls.ContentControl.Content (-> ContentControl Object void) #:set)) (content! (: Avalonia.Controls.ContentControl.Content (-> ContentControl Object void) #:set))
(show! (: Avalonia.Controls.Window.Show (-> Window void))) (show! (: Avalonia.Controls.Window.Show (-> Window void)))
(width! (: Avalonia.Layout.Layoutable.Width (-> Layoutable double void) #:set))
(height! (: Avalonia.Layout.Layoutable.Height (-> Layoutable double void) #:set))
(app-styles (: Avalonia.Application.Styles (-> Application Styles) #:get)) (app-styles (: Avalonia.Application.Styles (-> Application Styles) #:get))
(styles-add! (: Avalonia.Styling.Styles.Add (-> Styles IStyle void)))) (styles-add! (: Avalonia.Styling.Styles.Add (-> Styles IStyle void))))
@ -112,6 +114,10 @@
(ignore (wait-for scored?)) (ignore (wait-for scored?))
;; In a window, so that the theme gives the controls their templates. ;; In a window, so that the theme gives the controls their templates.
(def frame (Window.)) (def frame (Window.))
;; At the shots' size before it is shown: else the first shot is laid out
;; at the window's default size.
(width! (cast Layoutable frame) 1500.0)
(height! (cast Layoutable frame) 900.0)
(content! (cast ContentControl frame) (cast Object (app-control app))) (content! (cast ContentControl frame) (cast Object (app-control app)))
(show! frame) (show! frame)
(loop (:for (Tuple t name) (list (Tuple 0 "rules") (Tuple 1 "key-costs") (Tuple 2 "layout") (Tuple 3 "search"))) (loop (:for (Tuple t name) (list (Tuple 0 "rules") (Tuple 1 "key-costs") (Tuple 2 "layout") (Tuple 3 "search")))