-
-
Notifications
You must be signed in to change notification settings - Fork 142
feat(web): implement dedicated substitution-spur class, tests 🚂 🔪 #15688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jahorton
merged 8 commits into
epic/boundary-correction
from
feat/web/substitution-spurs
May 29, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6552f2b
feat(web): implement dedicated substitution-spur class, tests
jahorton 856466e
change(web): update TokenizationCorrector, QuotientNodeFinalizer unit…
jahorton 77b22a2
change(web): adds temp constructRoot() method to handle legacy vs non…
jahorton 8ba4d0b
change(web): safeguard clusters from clustering roots
jahorton 7445486
Merge branch 'epic/autocorrect' into feat/web/substitution-spurs
jahorton 3f768dd
change(web): drop unit test targeting now-invalid case
jahorton 1a1c93d
docs(web): add test file header
jahorton da12b14
change(web): disables one unit test temporarily (to be restored in fo…
jahorton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...rc/engine/predictive-text/worker-thread/src/main/correction/substitution-quotient-spur.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * Keyman is copyright (C) SIL Global. MIT License. | ||
| * | ||
| * Created by jahorton on 2026-02-03 | ||
| * | ||
| * This file adds a SearchQuotientSpur variant modeling match & substitute edit | ||
| * operations in regard to the corresponding keystroke. | ||
| */ | ||
|
|
||
| import { LexicalModelTypes } from "@keymanapp/common-types"; | ||
| import { KMWString } from "@keymanapp/web-utils"; | ||
|
|
||
| import { SearchNode } from "./distance-modeler.js"; | ||
| import { PathInputProperties, SearchQuotientNode } from "./search-quotient-node.js"; | ||
| import { SearchQuotientSpur } from "./search-quotient-spur.js"; | ||
| import { TokenResultMapping } from "./token-result-mapping.js"; | ||
|
|
||
| import Distribution = LexicalModelTypes.Distribution; | ||
| import ProbabilityMass = LexicalModelTypes.ProbabilityMass; | ||
| import Transform = LexicalModelTypes.Transform; | ||
|
|
||
| export class SubstitutionQuotientSpur extends SearchQuotientSpur { | ||
| public readonly insertLength: number; | ||
| public readonly leftDeleteLength: number; | ||
|
|
||
| constructor( | ||
| parentNode: SearchQuotientNode, | ||
| inputs: Distribution<Readonly<Transform>>, | ||
| inputSource: PathInputProperties | ProbabilityMass<Transform> | ||
| ) { | ||
| // Compute this SearchPath's codepoint length & edge length. | ||
| const inputSample = inputs?.[0].sample ?? { insert: '', deleteLeft: 0 }; | ||
| const insertLength = KMWString.length(inputSample.insert); | ||
| super(parentNode, inputs, inputSource, parentNode.codepointLength + insertLength - inputSample.deleteLeft); | ||
|
|
||
| // Compute this SearchPath's codepoint length & edge length. | ||
| this.insertLength = insertLength; | ||
| this.leftDeleteLength = inputSample.deleteLeft; | ||
| } | ||
|
|
||
| construct(parentNode: SearchQuotientNode, inputs: ProbabilityMass<Readonly<Transform>>[], inputSource: PathInputProperties): this { | ||
| return new SubstitutionQuotientSpur(parentNode, inputs, inputSource) as this; | ||
| } | ||
|
|
||
| protected buildEdgesFromResults(baseResults: ReadonlyArray<TokenResultMapping>): SearchNode[] { | ||
| return baseResults.flatMap((n) => n.buildSubstitutionEdges(this.inputs, this.spaceId)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
web/src/test/auto/headless/engine/predictive-text/helpers/buildQuotientDocFixture.tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * Keyman is copyright (C) SIL Global. MIT License. | ||
| * | ||
| * Created by jahorton on 2026-03-10 | ||
| * | ||
| * This file validates that the fixture corresponding to the quotient-graph-doc examples | ||
| * meets certain expectations and properties relied upon in other unit tests. | ||
| */ | ||
|
|
||
| import { assert } from "chai"; | ||
|
|
||
| import { buildQuotientDocFixture } from "./buildQuotientDocFixture.js"; | ||
|
|
||
| describe('buildQuotientDocFixture() fixture', () => { | ||
| it('constructs paths properly', () => { | ||
| const {searchRoot, nodes} = buildQuotientDocFixture(); | ||
|
|
||
| [searchRoot /*, nodes.sc1, nodes.sc2*/].forEach((n) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have the commented nodes in these tests?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| assert.equal(n.inputCount, 0); | ||
| }); | ||
| [/*nodes.k1c0,*/ nodes.k1c1, nodes.k1c2 /*, nodes.k1c3*/].forEach((n) => { | ||
| assert.equal(n.inputCount, 1); | ||
| }); | ||
| [/*nodes.k2c0, nodes.k2c1,*/ nodes.k2c2, nodes.k2c3].forEach((n) => { | ||
| assert.equal(n.inputCount, 2); | ||
| }); | ||
|
|
||
| [searchRoot/*, nodes.k1c0, nodes.k2c0*/].forEach((n) => { | ||
| assert.equal(n.codepointLength, 0); | ||
| }); | ||
| [/*nodes.sc1, */nodes.k1c1/*, nodes.k2c1*/].forEach((n) => { | ||
| assert.equal(n.codepointLength, 1); | ||
| }); | ||
| [/*nodes.sc2,*/ nodes.k1c2, nodes.k2c2].forEach((n) => { | ||
| assert.equal(n.codepointLength, 2); | ||
| }); | ||
| [/*nodes.k1c3,*/ nodes.k2c3].forEach((n) => { | ||
| assert.equal(n.codepointLength, 3); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.