mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-18 11:57:38 +00:00
feat(web): adds split-distribution SearchPath re-merge unit test
This commit is contained in:
parent
b1ffa83c8b
commit
fdd47c2977
1 changed files with 66 additions and 0 deletions
|
|
@ -1814,5 +1814,71 @@ describe('SearchQuotientSpur', () => {
|
|||
runCommonAssertions(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('correctly merges paths previously split mid-input', () => {
|
||||
let path: SearchQuotientNode = new LegacyQuotientRoot(testModel);
|
||||
const startSample = {sample: { insert: 'a', deleteLeft: 0 }, p: 1}
|
||||
path = new LegacyQuotientSpur(path, [startSample], startSample);
|
||||
|
||||
const inputDistribution = [
|
||||
{sample: { insert: 'four', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.4},
|
||||
{sample: { insert: 'then', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.3},
|
||||
{sample: { insert: 'nine', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.2},
|
||||
{sample: { insert: 'what', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.06},
|
||||
{sample: { insert: 'cent', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.04}
|
||||
];
|
||||
|
||||
const mergeTarget = new LegacyQuotientSpur(path, inputDistribution, inputDistribution[0]);
|
||||
assert.equal(mergeTarget.codepointLength, 4);
|
||||
assert.equal(mergeTarget.inputCount, 2);
|
||||
|
||||
// This test models a previous split at codepoint index 2, splitting
|
||||
// the input distribution accordingly. (Note: deleteLeft = 1!)
|
||||
const headDistributionSplit = [
|
||||
{sample: { insert: 'fo', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.4},
|
||||
{sample: { insert: 'th', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.3},
|
||||
{sample: { insert: 'ni', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.2},
|
||||
{sample: { insert: 'wh', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.06},
|
||||
{sample: { insert: 'ce', deleteLeft: 1, deleteRight: 0, id: 42 }, p: 0.04}
|
||||
];
|
||||
const headPath = new LegacyQuotientSpur(
|
||||
path, headDistributionSplit, {
|
||||
segment: {
|
||||
start: 0,
|
||||
trueTransform: inputDistribution[0].sample,
|
||||
transitionId: inputDistribution[0].sample.id
|
||||
},
|
||||
bestProbFromSet: inputDistribution[0].p,
|
||||
subsetId: mergeTarget.inputSource.subsetId
|
||||
}
|
||||
);
|
||||
|
||||
const tailDistributionSplit = [
|
||||
{sample: { insert: 'ur', deleteLeft: 0, deleteRight: 0, id: 42 }, p: 0.4},
|
||||
{sample: { insert: 'en', deleteLeft: 0, deleteRight: 0, id: 42 }, p: 0.3},
|
||||
{sample: { insert: 'ne', deleteLeft: 0, deleteRight: 0, id: 42 }, p: 0.2},
|
||||
{sample: { insert: 'at', deleteLeft: 0, deleteRight: 0, id: 42 }, p: 0.06},
|
||||
{sample: { insert: 'nt', deleteLeft: 0, deleteRight: 0, id: 42 }, p: 0.04}
|
||||
];
|
||||
const tailPath = new LegacyQuotientSpur(
|
||||
new LegacyQuotientRoot(testModel), tailDistributionSplit, {
|
||||
segment: {
|
||||
start: 2,
|
||||
trueTransform: inputDistribution[0].sample,
|
||||
transitionId: inputDistribution[0].sample.id
|
||||
},
|
||||
bestProbFromSet: inputDistribution[0].p,
|
||||
subsetId: mergeTarget.inputSource.subsetId
|
||||
}
|
||||
);
|
||||
|
||||
const remerged = headPath.merge(tailPath);
|
||||
|
||||
assert.deepEqual(remerged.bestExample, mergeTarget.bestExample);
|
||||
assert.equal(remerged.inputCount, 2);
|
||||
assert.isTrue(remerged instanceof SearchQuotientSpur);
|
||||
assert.deepEqual((remerged as SearchQuotientSpur).inputs, inputDistribution);
|
||||
assert.isTrue(quotientPathHasInputs(remerged, [[startSample], inputDistribution]));
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue