speech-rule-engine
Version:
A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.
42 lines (41 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllBySemanticId = exports.getBySemanticId = exports.getSemanticRoot = exports.getAttribute = exports.splitAttribute = void 0;
const DomUtil = require("../common/dom_util.js");
const enrich_attr_js_1 = require("../enrich_mathml/enrich_attr.js");
function splitAttribute(attr) {
return !attr ? [] : attr.split(/,/);
}
exports.splitAttribute = splitAttribute;
function getAttribute(node, attr) {
return node.getAttribute(attr);
}
exports.getAttribute = getAttribute;
function getSemanticRoot(node) {
if (node.hasAttribute(enrich_attr_js_1.Attribute.TYPE) &&
!node.hasAttribute(enrich_attr_js_1.Attribute.PARENT)) {
return node;
}
const semanticNodes = DomUtil.querySelectorAllByAttr(node, enrich_attr_js_1.Attribute.TYPE);
for (let i = 0, semanticNode; (semanticNode = semanticNodes[i]); i++) {
if (!semanticNode.hasAttribute(enrich_attr_js_1.Attribute.PARENT)) {
return semanticNode;
}
}
return node;
}
exports.getSemanticRoot = getSemanticRoot;
function getBySemanticId(root, id) {
if (root.getAttribute(enrich_attr_js_1.Attribute.ID) === id) {
return root;
}
return DomUtil.querySelectorAllByAttrValue(root, enrich_attr_js_1.Attribute.ID, id)[0];
}
exports.getBySemanticId = getBySemanticId;
function getAllBySemanticId(root, id) {
if (root.getAttribute(enrich_attr_js_1.Attribute.ID) === id) {
return [root];
}
return DomUtil.querySelectorAllByAttrValue(root, enrich_attr_js_1.Attribute.ID, id);
}
exports.getAllBySemanticId = getAllBySemanticId;