speech-rule-engine
Version:
A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.
42 lines (41 loc) • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.semanticMathmlNode = semanticMathmlNode;
exports.semanticMathmlSync = semanticMathmlSync;
exports.semanticMathml = semanticMathml;
exports.prepareMmlString = prepareMmlString;
const DomUtil = require("../common/dom_util.js");
const engine_js_1 = require("../common/engine.js");
const Semantic = require("../semantic_tree/semantic.js");
const EnrichMathml = require("./enrich_mathml.js");
require("./enrich_case_factory.js");
function semanticMathmlNode(mml, options) {
const clone = DomUtil.cloneNode(mml);
const tree = Semantic.getTree(clone, options);
return EnrichMathml.enrich(clone, tree, options);
}
function semanticMathmlSync(expr, options) {
const mml = DomUtil.parseInput(expr);
try {
return semanticMathmlNode(mml, options);
}
catch (err) {
console.error(err);
return mml;
}
}
function semanticMathml(expr, options, callback) {
engine_js_1.EnginePromise.getall().then(() => {
const mml = DomUtil.parseInput(expr);
callback(semanticMathmlNode(mml, options));
});
}
function prepareMmlString(expr) {
if (!expr.match(/^<math/)) {
expr = '<math>' + expr;
}
if (!expr.match(/\/math>$/)) {
expr += '</math>';
}
return expr;
}