UNPKG

speech-rule-engine

Version:

A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.

143 lines 5.16 kB
"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.EnrichAttributes = exports.Attribute = void 0; exports.makeIdList = makeIdList; exports.setAttributes = setAttributes; exports.removeAttributePrefix = removeAttributePrefix; exports.addPrefix = addPrefix; exports.addMrow = addMrow; const DomUtil = __importStar(require("../common/dom_util.js")); const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js"); const Prefix = 'data-semantic-'; var Attribute; (function (Attribute) { Attribute["ADDED"] = "data-semantic-added"; Attribute["ALTERNATIVE"] = "data-semantic-alternative"; Attribute["CHILDREN"] = "data-semantic-children"; Attribute["COLLAPSED"] = "data-semantic-collapsed"; Attribute["CONTENT"] = "data-semantic-content"; Attribute["EMBELLISHED"] = "data-semantic-embellished"; Attribute["FENCEPOINTER"] = "data-semantic-fencepointer"; Attribute["FONT"] = "data-semantic-font"; Attribute["ID"] = "data-semantic-id"; Attribute["ANNOTATION"] = "data-semantic-annotation"; Attribute["ATTRIBUTES"] = "data-semantic-attributes"; Attribute["OPERATOR"] = "data-semantic-operator"; Attribute["OWNS"] = "data-semantic-owns"; Attribute["PARENT"] = "data-semantic-parent"; Attribute["POSTFIX"] = "data-semantic-postfix"; Attribute["PREFIX"] = "data-semantic-prefix"; Attribute["ROLE"] = "data-semantic-role"; Attribute["SPEECH"] = "data-semantic-speech"; Attribute["STRUCTURE"] = "data-semantic-structure"; Attribute["SUMMARY"] = "data-semantic-summary"; Attribute["TYPE"] = "data-semantic-type"; })(Attribute || (exports.Attribute = Attribute = {})); exports.EnrichAttributes = [ Attribute.ADDED, Attribute.ALTERNATIVE, Attribute.CHILDREN, Attribute.COLLAPSED, Attribute.CONTENT, Attribute.EMBELLISHED, Attribute.FENCEPOINTER, Attribute.FONT, Attribute.ID, Attribute.ANNOTATION, Attribute.ATTRIBUTES, Attribute.OPERATOR, Attribute.OWNS, Attribute.PARENT, Attribute.POSTFIX, Attribute.PREFIX, Attribute.ROLE, Attribute.SPEECH, Attribute.STRUCTURE, Attribute.SUMMARY, Attribute.TYPE ]; function makeIdList(nodes) { return nodes .map(function (node) { return node.id; }) .join(','); } function setAttributes(mml, semantic) { mml.setAttribute(Attribute.TYPE, semantic.type); const attributes = semantic.allAttributes(); for (let i = 0, attr; (attr = attributes[i]); i++) { mml.setAttribute(Prefix + attr[0].toLowerCase(), attr[1]); } if (semantic.childNodes.length) { mml.setAttribute(Attribute.CHILDREN, makeIdList(semantic.childNodes)); } if (semantic.contentNodes.length) { mml.setAttribute(Attribute.CONTENT, makeIdList(semantic.contentNodes)); } if (semantic.parent) { mml.setAttribute(Attribute.PARENT, semantic.parent.id.toString()); } const external = semantic.attributesXml(); if (external) { mml.setAttribute(Attribute.ATTRIBUTES, external); } setPostfix(mml, semantic); } function setPostfix(mml, semantic) { const postfix = []; if (semantic.role === semantic_meaning_js_1.SemanticRole.MGLYPH) { postfix.push('image'); } if (semantic.attributes['href']) { postfix.push('link'); } if (postfix.length) { mml.setAttribute(Attribute.POSTFIX, postfix.join(' ')); } } function removeAttributePrefix(mml) { return mml.toString().replace(new RegExp(Prefix, 'g'), ''); } function addPrefix(attr) { return (Prefix + attr); } function addMrow() { const mrow = DomUtil.createElement('mrow'); mrow.setAttribute(Attribute.ADDED, 'true'); return mrow; } //# sourceMappingURL=enrich_attr.js.map