Skip to content

Commit 36c1445

Browse files
committed
refactor(web): refactor intermediate composited prediction type
This reorganizes the type formerly known as CorrectionPredictionTuple, preparing it to share similarities with a new incoming type handling an earlier, tokenized intermediate stage that will be needed for some aspects of suggestion generation. Build-bot: skip build:web Test-bot: skip
1 parent 21ecf7a commit 36c1445

13 files changed

Lines changed: 803 additions & 657 deletions

web/src/engine/predictive-text/worker-thread/src/main/correction/tokenization-corrector.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class TokenizationCorrector implements CorrectionSearchable<ReadonlyArray
5858
private _previousResults: TokenizationResultMapping[] = [];
5959

6060
// fully private
61+
public readonly modelsCorrectables: boolean;
6162
private selectionQueue: PriorityQueue<QuotientNodeFinalizer>;
6263
private tokenCostMap: Map<number, number>;
6364
private tokenLookupMap: Map<number, ContextToken>;
@@ -172,13 +173,16 @@ export class TokenizationCorrector implements CorrectionSearchable<ReadonlyArray
172173
this._correctables = [];
173174

174175
this.tokenLookupMap = new Map();
176+
let modelsCorrectables = false;
175177

176178
orderedTokens.forEach((token, index) => {
177179
// New issue: this mangles the space IDs! We almost certainly need some
178180
// sort of proper map to the source token.
179181
const searchModule = new QuotientNodeFinalizer(token.searchModule, index == orderedTokens.length - 1);
180182
this.tokenLookupMap.set(searchModule.spaceId, token);
181-
if(!filterClosure(token)) {
183+
const passesFilter = filterClosure(token);
184+
modelsCorrectables ||= passesFilter;
185+
if(!passesFilter) {
182186
this._uncorrectables.push(searchModule);
183187
} else if(index == tailCorrectionLength - 1) {
184188
// The sole assignment case for this field. It may only be assigned for
@@ -189,6 +193,8 @@ export class TokenizationCorrector implements CorrectionSearchable<ReadonlyArray
189193
this._correctables.push(searchModule);
190194
}
191195
});
196+
// Set a readonly flag indicating if this Corrector started with correctable entries.
197+
this.modelsCorrectables = modelsCorrectables;
192198

193199
this._generatedTokenResults = new Map();
194200
const uncorrectables = this._uncorrectables;

web/src/engine/predictive-text/worker-thread/src/main/model-compositor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as models from '@keymanapp/models-templates';
22
import { LexicalModelTypes } from '@keymanapp/common-types';
33

4-
import * as correction from './correction/index.js'
5-
import TransformUtils from './transformUtils.js';
64
import { applySuggestionCasing, correctAndEnumerate, createDefaultKeep, dedupeSuggestions, finalizeSuggestions, predictionAutoSelect, processSimilarity, toAnnotatedSuggestion, tupleDisplayOrderSort } from './predict-helpers.js';
75
import { detectCurrentCasing, determineModelTokenizer, determineModelWordbreaker, determinePunctuationFromModel } from './model-helpers.js';
6+
import TransformUtils from './transformUtils.js';
87

8+
import * as correction from './correction/index.js'
99
import { ContextTracker } from './correction/context-tracker.js';
1010
import { DEFAULT_ALLOTTED_CORRECTION_TIME_INTERVAL } from './correction/distance-modeler.js';
1111

@@ -162,10 +162,13 @@ export class ModelCompositor {
162162
// lexicon for a word. (Example: "Apple" the company vs "apple" the fruit.)
163163
for(let tuple of rawPredictions) {
164164
if(currentCasing && currentCasing != 'lower') {
165-
applySuggestionCasing(tuple.prediction.sample, basePrefix, this.lexicalModel, currentCasing);
165+
applySuggestionCasing(tuple.components.prediction, basePrefix, this.lexicalModel, currentCasing);
166166
}
167167
}
168168

169+
// what if... we fuse suggestions together here, after the 'apply casing' step?
170+
// deduplication, etc function fine from a fused-prediction perspective here.
171+
169172
// We want to dedupe before trimming the list so that we can present a full set
170173
// of viable distinct suggestions if available.
171174
const deduplicatedSuggestionTuples = dedupeSuggestions(this.lexicalModel, rawPredictions, context);

0 commit comments

Comments
 (0)