Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { LexicalModelTypes } from '@keymanapp/common-types';
import { deepCopy, KMWString } from "@keymanapp/web-utils";

import { SearchQuotientNode, PathInputProperties } from "./search-quotient-node.js";
import { TokenSplitMap } from "./context-tokenization.js";
Expand Down Expand Up @@ -109,7 +108,6 @@ export class ContextToken {
textToCharTransforms(rawText).forEach((transform) => {
let inputMetadata: PathInputProperties = {
segment: {
trueTransform: transform,
start: 0,
transitionId: undefined
},
Expand Down Expand Up @@ -235,27 +233,4 @@ export class ContextToken {

return tokensFromSplit;
}
}

export function preprocessInputSources(inputSources: ReadonlyArray<PathInputProperties>) {
const alteredSources = deepCopy(inputSources);
let trickledDeleteLeft = 0;
for(let i = alteredSources.length - 1; i >= 0; i--) {
const source = alteredSources[i];
if(trickledDeleteLeft) {
const insLen = KMWString.length(source.segment.trueTransform.insert);
if(insLen <= trickledDeleteLeft) {
source.segment.trueTransform.insert = '';
trickledDeleteLeft -= insLen;
} else {
source.segment.trueTransform.insert = KMWString.substring(source.segment.trueTransform.insert, 0, insLen - trickledDeleteLeft);
trickledDeleteLeft = 0;
}
}
trickledDeleteLeft += source.segment.trueTransform.deleteLeft;
source.segment.trueTransform.deleteLeft = 0;
}

alteredSources[0].segment.trueTransform.deleteLeft = trickledDeleteLeft;
return alteredSources;
}
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ export class ContextTokenization {

const inputSource: PathInputProperties = {
segment: {
trueTransform: sourceInput,
transitionId: sourceInput.id,
start: appliedLength
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ type CompleteSearchPath = {
export type PathResult = NullPath | IntermediateSearchPath | CompleteSearchPath;

export interface InputSegment {
/**
* The Transform corresponding to the keystroke applied to the true context
* for this input event.
*
* @deprecated Slated for removal within epic/autocorrect.
*/
trueTransform: Transform;

/**
* The transform / transition ID of the corresponding input event.
*/
Expand Down Expand Up @@ -203,12 +195,11 @@ export interface SearchQuotientNode {
readonly bestExample: { text: string, p: number };

/**
* Gets components useful for building a string-based representation of the
* keystroke range corrected by this search space.
*
* TODO: will return only the `inputSegment` part of each entry in the future.
* Gets components representing the keystroke range corrected by this search
* space. If only part of any keystroke's effects are used, this will also
* be noted.
*/
readonly inputSegments: PathInputProperties[];
readonly inputSegments: InputSegment[];

/**
* Gets a compact string-based representation of `inputRange` that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { LexicalModelTypes } from '@keymanapp/common-types';

import { SearchNode, SearchResult } from './distance-modeler.js';
import { generateSpaceSeed, PathInputProperties, PathResult, SearchQuotientNode } from './search-quotient-node.js';
import { generateSpaceSeed, InputSegment, PathResult, SearchQuotientNode } from './search-quotient-node.js';
import { SearchQuotientSpur } from './search-quotient-spur.js';

import LexicalModel = LexicalModelTypes.LexicalModel;
Expand Down Expand Up @@ -90,7 +90,7 @@ export class SearchQuotientRoot implements SearchQuotientNode {
}

// Return a new array each time; avoid aliasing potential!
get inputSegments(): PathInputProperties[] {
get inputSegments(): InputSegment[] {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { LexicalModelTypes } from '@keymanapp/common-types';
import { buildMergedTransform } from '@keymanapp/models-templates';

import { EDIT_DISTANCE_COST_SCALE, SearchNode, SearchResult } from './distance-modeler.js';
import { generateSpaceSeed, PathResult, SearchQuotientNode, PathInputProperties } from './search-quotient-node.js';
import { generateSpaceSeed, InputSegment, PathInputProperties, PathResult, SearchQuotientNode } from './search-quotient-node.js';
import { generateSubsetId } from './tokenization-subsets.js';
import { SearchQuotientRoot } from './search-quotient-root.js';
import { LegacyQuotientRoot } from './legacy-quotient-root.js';
Expand Down Expand Up @@ -78,7 +78,6 @@ export abstract class SearchQuotientSpur implements SearchQuotientNode {
const keystroke = inputSource as ProbabilityMass<Transform>;
inputSource = {
segment: {
trueTransform: keystroke.sample,
transitionId: keystroke.sample.id,
start: 0
},
Expand Down Expand Up @@ -466,19 +465,19 @@ export abstract class SearchQuotientSpur implements SearchQuotientNode {
return Object.values(this.returnedValues ?? {}).map(v => new SearchResult(v));
}

public get inputSegments(): PathInputProperties[] {
public get inputSegments(): InputSegment[] {
if(!this.parentNode) {
return [];
}

const parentSources = this.parentNode.inputSegments;
if(this.inputSource) {
const inputId = this.inputSource.segment.transitionId;
if(inputId && parentSources.length > 0 && parentSources[parentSources.length - 1].segment.transitionId == inputId) {
if(inputId && parentSources.length > 0 && parentSources[parentSources.length - 1].transitionId == inputId) {
return parentSources;
}

parentSources.push(this.inputSource);
parentSources.push(this.inputSource.segment);
}

return parentSources;
Expand All @@ -490,12 +489,12 @@ export abstract class SearchQuotientSpur implements SearchQuotientNode {
*/
get sourceRangeKey(): string {
const components: string[] = [];
const sources = this.inputSegments;
const segments = this.inputSegments;

for(const source of sources) {
const i = source.segment.start;
const j = source.segment.end;
let component = (`T${source.segment.transitionId}${i != 0 || j !== undefined ? '@' + i : ''}`);
for(const segment of segments) {
const i = segment.start;
const j = segment.end;
let component = (`T${segment.transitionId}${i != 0 || j !== undefined ? '@' + i : ''}`);
if(j) {
component = component + '-' + j;
}
Expand Down
Loading