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 { SearchPath } from "./search-path.js";
import { SearchSpace, PathInputProperties } from "./search-space.js";
Expand Down Expand Up @@ -111,7 +110,6 @@ export class ContextToken {
rawTransformDistributions.forEach((entry) => {
searchSpace = new SearchPath(searchSpace, entry, {
segment: {
trueTransform: entry[0].sample,
transitionId: entry[0].sample.id,
start: 0
},
Expand Down Expand Up @@ -236,27 +234,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 @@ -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, SearchSpace, PathInputProperties } from './search-space.js';
import { generateSpaceSeed, PathResult, SearchSpace, PathInputProperties, InputSegment } from './search-space.js';
import { generateSubsetId } from './tokenization-subsets.js';

import Distribution = LexicalModelTypes.Distribution;
Expand Down Expand Up @@ -98,7 +98,6 @@ export class SearchPath implements SearchSpace {
const keystroke = inputSource as ProbabilityMass<Transform>;
inputSource = {
segment: {
trueTransform: keystroke.sample,
transitionId: keystroke.sample.id,
start: 0
},
Expand Down Expand Up @@ -506,19 +505,19 @@ export class SearchPath implements SearchSpace {
return Object.values(this.returnedValues ?? {}).map(v => new SearchResult(v));
}

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

const parentSources = this.parentSpace.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 @@ -530,12 +529,12 @@ export class SearchPath implements SearchSpace {
*/
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
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 SearchSpace {
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
Loading