Enable word list model in the top-level API.

This commit is contained in:
Eddie Antonio Santos 2019-01-18 14:23:16 -07:00
parent a042a18858
commit 82ba375fb5
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87
3 changed files with 13 additions and 3 deletions

View file

@ -100,12 +100,20 @@ interface Capabilities {
}
/**
* TODO: discriminated union of different model types.
* Describes what kind of model to instantiate.
*/
interface ModelDescription {
type ModelDescription = DummyModelDescription | WordListModelDescription;
interface DummyModelDescription {
type: 'dummy';
futureSuggestions?: Suggestion[][];
}
interface WordListModelDescription {
type: 'wordlist';
/**
* Words to predict, one word per entry in the array.
*/
wordlist: string[];
}
/**
* Configuration of the LMLayer, sent back to the keyboard.

View file

@ -28,7 +28,7 @@ describe('LMLayer using the word list model', function () {
}).then(function (suggestions) {
// TODO: not super sure what to assert here!
assert.isAtLeast(suggestions.length, EXPECTED_SUGGESTIONS);
return lmLayer.predict(type('t'), emptyContext());
return lmLayer.predict(type('t'), atEndOfBuffer(''));
}).then(function (suggestions) {
assert.isAtLeast(suggestions.length, EXPECTED_SUGGESTIONS);
return lmLayer.predict(type('h'), atEndOfBuffer('t'));

View file

@ -145,6 +145,8 @@ class LMLayerWorker {
model = new LMLayerWorker.models.DummyModel(capabilities, {
futureSuggestions: desc.futureSuggestions
});
} else if (desc.type === 'wordlist') {
model = new LMLayerWorker.models.WordListModel(capabilities, desc.wordlist);
} else {
throw new Error('Invalid model');
}