speech-rule-engine
Version:
A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.
109 lines • 3.1 kB
JavaScript
import * as EngineConst from './engine_const.js';
import * as Dcstr from '../rule_engine/dynamic_cstr.js';
export class Options {
constructor(options = {}) {
this.delay = false;
this.domain = 'mathspeak';
this.style = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.STYLE];
this.locale = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE];
this.subiso = '';
this.modality = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.MODALITY];
this.speech = EngineConst.Speech.NONE;
this.markup = EngineConst.Markup.NONE;
this.mark = true;
this.automark = false;
this.character = true;
this.cleanpause = true;
this.cayleyshort = true;
this.linebreaks = false;
this.rate = '100';
this.walker = 'Table';
this.structure = false;
this.aria = false;
this.tree = false;
this.strict = false;
this.pprint = false;
this.rules = '';
this.prune = '';
this.set(options);
}
set(options) {
this.ensureDomain(options);
for (const [option, value] of Object.entries(options)) {
if (Options.BINARY_FEATURES.includes(option) || Options.STRING_FEATURES.includes(option)) {
this[option] = value;
continue;
}
}
}
json() {
const features = {};
const engineFeatures = [].concat(Options.STRING_FEATURES, Options.BINARY_FEATURES);
engineFeatures.forEach(x => features[x] = this[x]);
return features;
}
ensureDomain(feature) {
if ((feature.modality && feature.modality !== 'speech') ||
(!feature.modality && this.modality !== 'speech')) {
return;
}
if (!feature.domain && !feature.locale) {
return;
}
if (feature.domain === 'default') {
feature.domain = 'mathspeak';
return;
}
const locale = (feature.locale || this.locale);
const domain = (feature.domain || this.domain);
if (MATHSPEAK_ONLY.indexOf(locale) !== -1 && domain !== 'mathspeak') {
feature.domain = 'mathspeak';
return;
}
if (locale === 'en') {
if (EN_RULES.indexOf(domain) === -1) {
feature.domain = 'mathspeak';
}
return;
}
if (domain !== 'mathspeak' && domain !== 'clearspeak') {
feature.domain = 'mathspeak';
}
}
}
Options.BINARY_FEATURES = [
'automark',
'mark',
'character',
'cleanpause',
'strict',
'structure',
'aria',
'pprint',
'cayleyshort',
'linebreaks',
'tree'
];
Options.STRING_FEATURES = [
'markup',
'style',
'domain',
'speech',
'walker',
'locale',
'delay',
'modality',
'rate',
'rules',
'subiso',
'prune'
];
const MATHSPEAK_ONLY = ['ca', 'da', 'es'];
const EN_RULES = [
'chromevox',
'clearspeak',
'mathspeak',
'emacspeak',
'html'
];
//# sourceMappingURL=options.js.map