speech-rule-engine
Version:
A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.
146 lines • 4.62 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Options = void 0;
const EngineConst = __importStar(require("./engine_const.js"));
const Dcstr = __importStar(require("../rule_engine/dynamic_cstr.js"));
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';
}
}
}
exports.Options = Options;
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