speech-rule-engine
Version:
A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.
97 lines • 3.63 kB
JavaScript
;
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.AbstractSpeechGenerator = void 0;
const engine_setup_js_1 = require("../common/engine_setup.js");
const EnrichAttr = __importStar(require("../enrich_mathml/enrich_attr.js"));
const rebuild_stree_js_1 = require("../walker/rebuild_stree.js");
const SpeechGeneratorUtil = __importStar(require("./speech_generator_util.js"));
const locale_js_1 = require("../l10n/locale.js");
class AbstractSpeechGenerator {
constructor() {
this.modality = EnrichAttr.addPrefix('speech');
this.rebuilt_ = null;
this.options_ = {};
}
getRebuilt() {
return this.rebuilt_;
}
setRebuilt(rebuilt) {
this.rebuilt_ = rebuilt;
}
computeRebuilt(xml, force = false) {
if (!this.rebuilt_ || force) {
this.rebuilt_ = new rebuild_stree_js_1.RebuildStree(xml);
}
return this.rebuilt_;
}
setOptions(options) {
this.options_ = options || {};
this.modality = EnrichAttr.addPrefix(this.options_.modality || 'speech');
}
setOption(key, value) {
const options = this.getOptions();
options[key] = value;
this.setOptions(options);
}
getOptions() {
return this.options_;
}
generateSpeech(_node, xml) {
if (!this.rebuilt_) {
this.rebuilt_ = new rebuild_stree_js_1.RebuildStree(xml);
}
(0, engine_setup_js_1.setupEngine)(this.options_);
return SpeechGeneratorUtil.computeMarkup(this.getRebuilt().xml);
}
nextRules() {
this.setOptions(SpeechGeneratorUtil.nextRules(this.getOptions()));
}
nextStyle(id) {
this.setOption('style', SpeechGeneratorUtil.nextStyle(this.getRebuilt().nodeDict[id], this.getOptions()));
}
getLevel(depth) {
return locale_js_1.LOCALE.MESSAGES.navigate.LEVEL + ' ' + depth;
}
getActionable(actionable) {
return actionable
? actionable < 0
? locale_js_1.LOCALE.MESSAGES.navigate.EXPANDABLE
: locale_js_1.LOCALE.MESSAGES.navigate.COLLAPSIBLE
: '';
}
}
exports.AbstractSpeechGenerator = AbstractSpeechGenerator;
//# sourceMappingURL=abstract_speech_generator.js.map