UNPKG

speech-rule-engine

Version:

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

112 lines 4.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.SpeechStructure = void 0; const DomUtil = __importStar(require("../common/dom_util.js")); const aural_rendering_js_1 = require("../audio/aural_rendering.js"); const engine_js_1 = require("../common/engine.js"); class SpeechStructure { getSpeechMap(id) { let map = this.speechMaps.get(id); if (!map) { map = new Map(); this.speechMaps.set(id, map); } return map; } setMap(modality, id, descr) { const map = this.getSpeechMap(id); map.set(modality, descr); } constructor(node) { this.node = node; this.speechMaps = new Map(); this.nodeMap = null; } addNode(node, descr, modality = 'speech') { if (node.nodeType === DomUtil.NodeType.ELEMENT_NODE && node.hasAttribute('id')) { this.setMap(modality, node.getAttribute('id'), descr); } } get(id) { return this.speechMaps.get(id); } getNodeMap() { if (this.nodeMap) { return this.nodeMap; } this.nodeMap = new Map(); for (const node of DomUtil.querySelectorAllByAttr(this.node, 'id')) { const id = node.getAttribute('id'); if (!this.nodeMap.has(id)) { this.nodeMap.set(node.getAttribute('id'), node); continue; } const tag = node.parentNode.tagName; if (tag === 'children' || tag === 'stree') { this.nodeMap.set(id, node); } } return this.nodeMap; } completeModality(modality, func) { const oldModality = engine_js_1.Engine.getInstance().options.modality; engine_js_1.Engine.getInstance().options.modality = modality; for (const [id, descrs] of this.getNodeMap()) { const speechMap = this.getSpeechMap(id); if (!speechMap.has(modality)) { func(descrs); } } engine_js_1.Engine.getInstance().options.modality = oldModality; } json(mls = ['none']) { const result = {}; const oldMarkup = engine_js_1.Engine.getInstance().options.markup; for (const [id, map] of this.speechMaps) { const modality = {}; for (const ml of mls) { engine_js_1.Engine.getInstance().options.markup = ml; map.forEach((x, y) => (modality[`${y}-${ml}`] = (0, aural_rendering_js_1.markup)(x))); result[id] = modality; } } engine_js_1.Engine.getInstance().options.markup = oldMarkup; return result; } } exports.SpeechStructure = SpeechStructure; //# sourceMappingURL=speech_structure.js.map