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 @@ -21,6 +21,13 @@ import Reversion = LexicalModelTypes.Reversion;
import Suggestion = LexicalModelTypes.Suggestion;
import Transform = LexicalModelTypes.Transform;

let SUGGESTION_ID_SEED = 0;
export function generateSuggestionId() {
const id = SUGGESTION_ID_SEED;
SUGGESTION_ID_SEED++;
return id;
}

export class ModelCompositor {
private lexicalModel: LexicalModel;
private _contextTracker?: correction.ContextTracker;
Expand Down Expand Up @@ -62,8 +69,6 @@ export class ModelCompositor {
*/
static readonly SINGLE_CHAR_KEY_PROB_EXPONENT = 16;

private SUGGESTION_ID_SEED = 0;

private testMode: boolean = false;
private verbose: boolean = true;
private configuration: Configuration;
Expand Down Expand Up @@ -193,11 +198,6 @@ export class ModelCompositor {
this.verbose
);

suggestions.forEach((suggestion) => {
suggestion.id = this.SUGGESTION_ID_SEED;
this.SUGGESTION_ID_SEED++;
});

if(revertableTransitionId) {
const reversion = this.contextTracker.peek(revertableTransitionId)?.reversion;
if(reversion) {
Expand Down Expand Up @@ -264,8 +264,7 @@ export class ModelCompositor {
// verification later.
reversion.id = -suggestion.id;
} else {
reversion.id = -this.SUGGESTION_ID_SEED;
this.SUGGESTION_ID_SEED++;
reversion.id = -generateSuggestionId();
}

// Step 3: if we track Contexts, update the tracking data as appropriate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ContextTracker } from './correction/context-tracker.js';
import { ContextState, determineContextSlideTransform } from './correction/context-state.js';
import { ContextTransition } from './correction/context-transition.js';
import { ExecutionTimer } from './correction/execution-timer.js';
import ModelCompositor from './model-compositor.js';
import ModelCompositor, { generateSuggestionId } from './model-compositor.js';
import { getBestMatches } from './correction/distance-modeler.js';

const searchForProperty = defaultWordbreaker.searchForProperty;
Expand Down Expand Up @@ -1023,15 +1023,19 @@ export function finalizeSuggestions(
mutableSuggestion.transform = mergedTransform;
}

const suggestionId = generateSuggestionId();

if(!verbose) {
return {
...prediction.sample,
p: tuple.totalProb
p: tuple.totalProb,
id: suggestionId
};
} else {
const sample: Outcome<Suggestion | Keep> = {
...prediction.sample,
p: tuple.totalProb,
id: suggestionId,
"lexical-p": prediction.p,
"correction-p": tuple.correction.p
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ describe('finalizeSuggestions', () => {
insert: testModelWithSpacing.punctuation.insertAfterWord,
deleteLeft: 0
});

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);
assert.sameDeepOrderedMembers(finalized, expected);
});

Expand All @@ -192,6 +196,10 @@ describe('finalizeSuggestions', () => {
const { unfinalized, expected } = build_its_is_set();
const finalized = finalizeSuggestions(testModelWithSpacing, unfinalized, context, transform, false);

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);

// We do not add a whitespace despite not splitting a token if there's a
// matching whitespace immediately to the caret's right.
assert.sameDeepOrderedMembers(finalized, expected);
Expand Down Expand Up @@ -223,6 +231,10 @@ describe('finalizeSuggestions', () => {
insert: testModelWithSpacing.punctuation.insertAfterWord,
deleteLeft: 0
});

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);
assert.sameDeepOrderedMembers(finalized, expected);
});

Expand Down Expand Up @@ -251,6 +263,10 @@ describe('finalizeSuggestions', () => {
insert: testModelWithSpacing.punctuation.insertAfterWord,
deleteLeft: 0
});

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);
assert.sameDeepOrderedMembers(finalized, expected);
});
});
Expand All @@ -274,6 +290,9 @@ describe('finalizeSuggestions', () => {
const { unfinalized, expected } = build_its_is_set();
const finalized = finalizeSuggestions(testModelWithoutSpacing, unfinalized, context, transform, false);

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);
assert.sameDeepOrderedMembers(finalized, expected);
});

Expand All @@ -298,6 +317,10 @@ describe('finalizeSuggestions', () => {
const { unfinalized, expected } = build_its_is_set();
const finalized = finalizeSuggestions(testModelWithoutSpacing, unfinalized, context, transform, false);

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);

// We do not add a whitespace despite not splitting a token if there's a
// matching whitespace immediately to the caret's right.
assert.sameDeepOrderedMembers(finalized, expected);
Expand Down Expand Up @@ -325,6 +348,9 @@ describe('finalizeSuggestions', () => {
const { unfinalized, expected } = build_its_is_set();
const finalized = finalizeSuggestions(testModelWithoutSpacing, unfinalized, context, transform, false);

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);
assert.sameDeepOrderedMembers(finalized, expected);
});
});
Expand Down Expand Up @@ -353,6 +379,10 @@ describe('finalizeSuggestions', () => {
insert: testModelWithSpacing.punctuation.insertAfterWord,
deleteLeft: 0
});

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);
assert.sameDeepOrderedMembers(finalized, expected);
});

Expand All @@ -371,14 +401,17 @@ describe('finalizeSuggestions', () => {
deleteLeft: 0
};


const { unfinalized, expected } = build_its_is_set();
const finalized = finalizeSuggestions(testModelWithSpacing, unfinalized, context, transform, false);

expected.forEach((entry) => entry.appendedTransform = {
insert: testModelWithSpacing.punctuation.insertAfterWord,
deleteLeft: 0
});

// For full deep equality, we can't (or at least, shouldn't) test against
// specific suggestion ID values,
finalized.forEach((entry) => delete entry.id);
assert.sameDeepOrderedMembers(finalized, expected);
});
});
Expand Down
Loading