spiegel-keyman/common/models/types
Marc Durdin 49eb062c65 feat(web): prediction casing follows current layer
Fixes #6455.

This involved adding an extra hint to the data passed into the lexical
model layer, being the CasingForm that the current layer wants to use.

Given there are several entry points to the lexical model layer, this
meant a few places where we needed to check the current layer.

I refactored the very long function `InputProcessor.processKeyEvent` to
extract out the `buildAlternates` function. There should be no
functional changes to the `buildAlternates` code. But it makes
`processKeyEvent` significantly easier to read.
2022-04-08 16:14:01 +10:00
..
.gitignore refactor(common/lmlayer): move @keymanapp/models-types to its new home 2020-05-19 19:14:15 -06:00
build.sh fix(developer): npm publish with correct tier 2022-02-13 14:18:42 +07:00
index.d.ts feat(web): prediction casing follows current layer 2022-04-08 16:14:01 +10:00
package-lock.json auto: increment beta version to 15.0.230 2022-04-07 14:02:52 -04:00
package.json auto: increment beta version to 15.0.230 2022-04-07 14:02:52 -04:00
README.md docs(common/lmlayer): update to reflect new package name 2020-05-19 19:43:57 -06:00
test.ts refactor(common/lmlayer): move @keymanapp/models-types to its new home 2020-05-19 19:14:15 -06:00

@keymanapp/models-types

Declares TypeScript types and interfaces required to define Lexical Models, Word breaking functions, and all things in between.

Install

(see below if you are working in the keymanapp/keyman repo!)

npm install --save-dev @keymanapp/models-types

Usage

Say you are creating a custom lexical model. Then import this module in your lexical model file!

// my-nifty-model.ts

import "@keymanapp/models-types";

export class MyNiftyClass implements LexicalModel {
  configure(capabilities: Capabilities): Configuration {
    // TODO: implement me!
    throw new Error("Method not implemented.");
  }
  predict(transform: Transform, context: Context): ProbabilityMass<Suggestion>[] {
    // TODO: implement me!
    throw new Error("Method not implemented.");
  }
  wordbreak(context: Context): string {
    // TODO: implement me!
    throw new Error("Method not implemented.");
  }
  punctuation?: LexicalModelPunctuation;
}

If your are creating a custom word breaker, you would do the same:

import "@keymanapp/models-types";

export let myShinyWordBreaker: WordBreakingFunction;
myShinyWordBreaker = function (phrase: string): Span[] {
  // TODO: implement me!
  throw new Error("Function not implemented")
}

Look at index.d.ts for documentation on each and every type!

Usage within keymanapp/keyman repo

To use it in other subprojects within keymanapp/keyman, ensure that this package is linked using Lerna. From the root of the repository, run:

npx lerna bootstrap

Add this dependency to your subproject like so:

npx lerna add @keymanapp/models-types path/to/your/subproject