コンテンツにスキップ

Analysis Query Grammar

このコンテンツはまだ日本語訳がありません。

Analysis queries describe what to select or calculate from a keystroke report. The expected result type depends on where the query runs.

To inspect adjacent presses that move one finger to a different key, use a sfdk collection in Keystrokes. To measure how often they occur, add freq in a metric:

bi.sfdk
bi.sfdk.freq * 100

Predicates and scalar comparisons return a Boolean within an expression; a missing numeric result can be nil. A local cost expression starts from the current candidate window rather than an entire report.

A same-finger skipgram leaves one event between the two keys, so the query starts with triples. For each triple, the endpoint selector supplies the pair to compare. A dot stage can filter the current collection, select positions or physical keys, map its items, or reduce it to one result. The input and output types of each stage determine which stage can follow it. For example, ends accepts a window wider than a pair.

tri.ends.sfdk

For a thumb-free rhythm comparison, keep rolls and redirects only if every event passes the no-thumb test. A parenthesized filter after a dot sees the current window or pair. Prefix ! binds first, followed by & and \, then |. Use parentheses to change that order. Use every to require a condition, such as excluding thumb actions, at each event.

tri.((roll | redirect) & every(!thumb))

Collection operators#

Either#

left | right

Matches when either expression matches.

tri.(alternation | roll)

Both#

left & right

Matches when both expressions match.

tri.(roll & inward)

Except#

left \ right

Matches the left expression except where the right expression matches.

tri.(roll \ key_repeat)

Not#

!expression

Matches when the following expression does not match.

tri.(!key_repeat)

Group#

(expression)

Groups an expression so its operators are applied together.

tri.(alternation | roll)

Filter#

.(expression)

Keeps windows that satisfy the expression in parentheses.

tri.(alternation | roll)

Comparison#

left < right

Compares a distance with a length in key units.

bi.row_change(1u < abs(dy) < 1.5u)

A metric can give longer moves more weight by squaring each measured distance before summing. Operator precedence, from weakest to strongest: ??, |, &, comparisons, + and -, * and /, unary ! and -, then ^. Coalescing and exponentiation associate to the right. Use == for scalar equality; Browse’s = belongs to the separate layout grammar. The example squares d and uses ?? for missing values before summing.

bi.kp.map((d ^ 2) ?? 0).sum

Numeric expressions use decimal literals, true, false, and nil. An argument list uses commas and may use name:value; a set within one argument uses its own operators. A length predicate accepts a unit suffix such as 1u; scalar distances are in key units already. See values and arguments for names, units, and accepted values.

This grammar names the typed stages and value families listed in the other reference pages. The bracketed pieces are optional, braces repeat, and whitespace may separate tokens. A stage must accept the type yielded by its predecessor, and the complete expression must have the result type required at its call site.

query = scalar-or-collection ;
scalar-or-collection = coalesce ;
coalesce = boolean-or [ "??" coalesce ] ;
boolean-or = boolean-and { "|" boolean-and } ;
boolean-and = comparison { "&" comparison } ;
comparison = sum { ("==" | "!=" | "<" | "<=" | ">" | ">=") sum } ;
sum = product { ("+" | "-") product } ;
product = unary { ("*" | "/") unary } ;
unary = ("!" | "-") unary | power ;
power = atom [ "^" unary ] ;
atom = primary { "." stage } ;
primary = scalar-literal | report-source | scoped-value
| scoped-call | "(" scalar-or-collection ")" ;
report-source = "uni" | "bi" | "tri" | "quad" | "quint" ;
stage = cataloged-selector | cataloged-predicate
| numeric-property | numeric-reducer
| scoped-call | "(" condition ")" ;
condition = intersection { "|" intersection } ;
intersection = condition-atom { ("&" | "\") condition-atom } ;
condition-atom = "!" condition-atom | "(" condition ")"
| cataloged-predicate [ "(" arguments ")" ]
| compatible-scalar-comparison ;
scoped-call = cataloged-call "(" [ arguments ] ")" ;
arguments = argument { "," argument } ;
argument = [ argument-name ":" ] value-for-that-argument ;
scalar-literal = decimal | "true" | "false" | "nil" ;

A condition accepted by a stage may contain a singleton test, a typed scalar operation, or a length constraint, depending on that stage. Sources, positions, and scope lists the input contexts; predicates and event roles and functions and numeric results list the productions accepted in those contexts. Queries have no comment syntax.

Metric query grammar#

A report source starts a pipeline. Dot stages filter, project, or reduce the current collection. Parenthesized filter stages accept Boolean expressions over the current item.

Collection union uses |. Intersection uses &. Difference uses \. Prefix ! negates a condition, and parentheses group it. Unary expressions bind first; & and \ bind before |.

Numeric precedence from lowest to highest is ??, |, &, comparisons, + and -, * and /, then ^. Coalescing and exponentiation associate to the right. Exponentiation binds before unary minus and logical not.

Spaces and line breaks may separate tokens. Metric queries do not have comment syntax.

tri.(roll | redirect).freq
tri.(roll \ redirect).count
bi.akp.map((d ^ 2) ?? 0).sum

Type legend#

input type → output type

start is the beginning of a report pipeline. Window1 through Window5 are ordered windows containing exactly that many consecutive resolved keystrokes; Window accepts any supported width. same-as-input means a filter preserves the input collection and its width.

Keystroke is one resolved action within a window. Event is a selected window position such as first or last. Key is a physical key with its effective finger for that event. KeyCollection contains those keys selected from an event. KeyPair is one ordered physical-key pair, and KeyPairCollection contains those pairs. NumberCollection contains mapped numeric values. map means the current mapped-item scope.

Number and Boolean are scalar results. Nil is an absent numeric or Boolean value. Length is a distance in key units. numeric-expression accepts a complete numeric expression; length-condition is the distance-comparison form used by positional predicates.

finger-set, finger-pair, and finger-pair-set describe accepted fingers or ordered finger combinations. participation-set selects event roles. trigger-kind-set distinguishes keys from chords. ergonomic-direction selects a natural or inverted row change. singleton-expression is a condition checked against one keystroke. enum is the closed value list shown by that argument, and boolean accepts true or false.