Allow for the partial specification of punctuation, with more robust defaults selector thing.

This commit is contained in:
Eddie Antonio Santos 2019-07-29 15:40:08 -06:00
parent 5e2528a78c
commit b20541ea8b
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87
2 changed files with 25 additions and 7 deletions

View file

@ -39,7 +39,6 @@ describe('Custom Punctuation', function () {
quotesForKeepSuggestion: {
open: "«", close: "»"
},
insertAfterWord: " "
}
});
@ -85,9 +84,6 @@ describe('Custom Punctuation', function () {
// U+1680 OGHAM SPACE MARK:
// it's technically whitespace, but it don't look it!
insertAfterWord: "",
quotesForKeepSuggestion: {
open: "“", close: "”"
},
}
});

View file

@ -49,7 +49,7 @@ class ModelCompositor {
let postContext = models.applyTransform(inputTransform, context);
let keepOptionText = this.lexicalModel.wordbreak(postContext);
let keepOption: Suggestion = null;
let punctuation = this.determinePunctuationFromModel();
let punctuation = this.determinePunctuationFromModel(this.lexicalModel);
for(let alt of transformDistribution) {
let transform = alt.sample;
@ -153,8 +153,30 @@ class ModelCompositor {
return suggestions;
}
private determinePunctuationFromModel() {
return this.lexicalModel.punctuation || DEFAULT_PUNCTUATION;
/**
* Returns the punctuation used for this model, filling out unspecified fields
*/
private determinePunctuationFromModel(model: WorkerInternalModel): LexicalModelPunctuation {
let defaults = DEFAULT_PUNCTUATION;
// Use the defaults of the model does not provide any punctuation at all.
if (!model.punctuation)
return defaults;
let specifiedPunctuation = this.lexicalModel.punctuation;
let insertAfterWord = specifiedPunctuation.insertAfterWord;
if (insertAfterWord !== '' && !insertAfterWord) {
insertAfterWord = defaults.insertAfterWord;
}
let quotesForKeepSuggestion = specifiedPunctuation.quotesForKeepSuggestion;
if (!quotesForKeepSuggestion) {
quotesForKeepSuggestion = defaults.quotesForKeepSuggestion;
}
return {
insertAfterWord, quotesForKeepSuggestion
}
}
}