Skip to content

Commit bc32ac3

Browse files
committed
feat(web): add prepareTokenizationSearch helper method
This method is designed to determine the appropriate range of tokens, within each context variant, should be eligible for correction when generating predictions and corrections. Build-bot: skip build:web Test-bot: skip
1 parent 245f43f commit bc32ac3

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

web/src/engine/predictive-text/worker-thread/src/main/predict-helpers.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,39 @@ export function determineTokenizedCorrectionSequence(
629629
};
630630
}
631631

632+
export function prepareTokenizationSearch(
633+
transition: ContextTransition,
634+
tokenizations: ContextTokenization[]
635+
) {
636+
// Goal - determine what parts of each tokenization are searchable & prep them for correcion-search.
637+
const tokenizationAnalyses = tokenizations.map((tokenization) => {
638+
return {
639+
tokenization: tokenization,
640+
analysis: determineSuggestionRange(transition.base.displayTokenization.tokens, tokenization.tokens, (a, b) => a.spaceId == b.spaceId)
641+
};
642+
});
643+
644+
const biggestCommonRemoval = tokenizationAnalyses.reduce(
645+
(biggest, current) => biggest.length > current.analysis.tokensToRemove.length ? biggest : current.analysis.tokensToRemove,
646+
[] as ContextTokenLike[]
647+
);
648+
649+
const tokenizationSetup = tokenizationAnalyses.map((tuple) => {
650+
// These tokens are unaffected by the input whatsoever, though their
651+
// probability may affect thresholding for the non-locked tokens.
652+
const unaffectedTokenCount = biggestCommonRemoval.length - tuple.analysis.tokensToRemove.length;
653+
654+
const mutatedLength = tuple.analysis.tokensToPredict.length;
655+
return new TokenizationCorrector(tuple.tokenization, mutatedLength, (token, index) => {
656+
return index >= unaffectedTokenCount // is a modified token
657+
&& index == mutatedLength - 1 // TEMP: adjacent to the caret (TO BE REMOVED)
658+
&& correctionValidForAutoSelect(token.exampleInput); // and is eligible text-correction
659+
});
660+
});
661+
662+
return tokenizationSetup;
663+
}
664+
632665
/**
633666
* This method performs the correction-search and model-lookup operations for
634667
* prediction generation by using the user's context state and potential

0 commit comments

Comments
 (0)