add initial marp implementation with sample content and build configuration
This commit is contained in:
14
node_modules/speech-rule-engine/mjs/audio/abstract_audio_renderer.d.ts
generated
vendored
Normal file
14
node_modules/speech-rule-engine/mjs/audio/abstract_audio_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { KeyCode } from '../common/event_util.js';
|
||||
import { AudioRenderer } from './audio_renderer.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
import { Span } from './span.js';
|
||||
export declare abstract class AbstractAudioRenderer implements AudioRenderer {
|
||||
private separator_;
|
||||
abstract markup(descrs: AuditoryDescription[]): string;
|
||||
set separator(sep: string);
|
||||
get separator(): string;
|
||||
error(_key: KeyCode | string): string | null;
|
||||
merge(spans: Span[]): string;
|
||||
finalize(str: string): string;
|
||||
pauseValue(value: string): number;
|
||||
}
|
||||
47
node_modules/speech-rule-engine/mjs/audio/abstract_audio_renderer.js
generated
vendored
Normal file
47
node_modules/speech-rule-engine/mjs/audio/abstract_audio_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Engine } from '../common/engine.js';
|
||||
export class AbstractAudioRenderer {
|
||||
constructor() {
|
||||
this.separator_ = ' ';
|
||||
}
|
||||
set separator(sep) {
|
||||
this.separator_ = sep;
|
||||
}
|
||||
get separator() {
|
||||
return Engine.getInstance().modality === 'braille' ? '' : this.separator_;
|
||||
}
|
||||
error(_key) {
|
||||
return null;
|
||||
}
|
||||
merge(spans) {
|
||||
let str = '';
|
||||
const len = spans.length - 1;
|
||||
for (let i = 0, span; (span = spans[i]); i++) {
|
||||
str += span.speech;
|
||||
if (i < len) {
|
||||
const sep = span.attributes['separator'];
|
||||
str += sep !== undefined ? sep : this.separator;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
finalize(str) {
|
||||
return str;
|
||||
}
|
||||
pauseValue(value) {
|
||||
let numeric;
|
||||
switch (value) {
|
||||
case 'long':
|
||||
numeric = 750;
|
||||
break;
|
||||
case 'medium':
|
||||
numeric = 500;
|
||||
break;
|
||||
case 'short':
|
||||
numeric = 250;
|
||||
break;
|
||||
default:
|
||||
numeric = parseInt(value, 10);
|
||||
}
|
||||
return Math.floor((numeric * Engine.getInstance().getRate()) / 100);
|
||||
}
|
||||
}
|
||||
11
node_modules/speech-rule-engine/mjs/audio/acss_renderer.d.ts
generated
vendored
Normal file
11
node_modules/speech-rule-engine/mjs/audio/acss_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import * as AudioUtil from './audio_util.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
import { MarkupRenderer } from './markup_renderer.js';
|
||||
export declare class AcssRenderer extends MarkupRenderer {
|
||||
markup(descrs: AuditoryDescription[]): string;
|
||||
error(key: number): string;
|
||||
prosodyElement(key: EngineConst.personalityProps, value: number): string;
|
||||
pause(pause: AudioUtil.Pause): string;
|
||||
private prosody_;
|
||||
}
|
||||
63
node_modules/speech-rule-engine/mjs/audio/acss_renderer.js
generated
vendored
Normal file
63
node_modules/speech-rule-engine/mjs/audio/acss_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import * as EventUtil from '../common/event_util.js';
|
||||
import * as AudioUtil from './audio_util.js';
|
||||
import { MarkupRenderer } from './markup_renderer.js';
|
||||
export class AcssRenderer extends MarkupRenderer {
|
||||
markup(descrs) {
|
||||
this.setScaleFunction(-2, 2, 0, 10, 0);
|
||||
const markup = AudioUtil.personalityMarkup(descrs);
|
||||
const result = [];
|
||||
const currentPers = { open: [] };
|
||||
let pause = null;
|
||||
let isString = false;
|
||||
for (let i = 0, descr; (descr = markup[i]); i++) {
|
||||
if (AudioUtil.isMarkupElement(descr)) {
|
||||
AudioUtil.mergeMarkup(currentPers, descr);
|
||||
continue;
|
||||
}
|
||||
if (AudioUtil.isPauseElement(descr)) {
|
||||
if (isString) {
|
||||
pause = AudioUtil.mergePause(pause, descr, Math.max);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const str = '"' + this.merge(descr.span) + '"';
|
||||
isString = true;
|
||||
if (pause) {
|
||||
result.push(this.pause(pause));
|
||||
pause = null;
|
||||
}
|
||||
const prosody = this.prosody_(currentPers);
|
||||
result.push(prosody ? '(text (' + prosody + ') ' + str + ')' : str);
|
||||
}
|
||||
return '(exp ' + result.join(' ') + ')';
|
||||
}
|
||||
error(key) {
|
||||
return '(error "' + EventUtil.Move.get(key) + '")';
|
||||
}
|
||||
prosodyElement(key, value) {
|
||||
value = this.applyScaleFunction(value);
|
||||
switch (key) {
|
||||
case EngineConst.personalityProps.RATE:
|
||||
return '(richness . ' + value + ')';
|
||||
case EngineConst.personalityProps.PITCH:
|
||||
return '(average-pitch . ' + value + ')';
|
||||
case EngineConst.personalityProps.VOLUME:
|
||||
return '(stress . ' + value + ')';
|
||||
}
|
||||
return '(value . ' + value + ')';
|
||||
}
|
||||
pause(pause) {
|
||||
return ('(pause . ' +
|
||||
this.pauseValue(pause[EngineConst.personalityProps.PAUSE]) +
|
||||
')');
|
||||
}
|
||||
prosody_(pros) {
|
||||
const keys = pros.open;
|
||||
const result = [];
|
||||
for (let i = 0, key; (key = keys[i]); i++) {
|
||||
result.push(this.prosodyElement(key, pros[key]));
|
||||
}
|
||||
return result.join(' ');
|
||||
}
|
||||
}
|
||||
10
node_modules/speech-rule-engine/mjs/audio/audio_renderer.d.ts
generated
vendored
Normal file
10
node_modules/speech-rule-engine/mjs/audio/audio_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { KeyCode } from '../common/event_util.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
import { Span } from './span.js';
|
||||
export interface AudioRenderer {
|
||||
separator: string;
|
||||
markup(descrs: AuditoryDescription[]): string;
|
||||
error(key: KeyCode | string): string | null;
|
||||
merge(strs: Span[]): string;
|
||||
finalize(str: string): string;
|
||||
}
|
||||
1
node_modules/speech-rule-engine/mjs/audio/audio_renderer.js
generated
vendored
Normal file
1
node_modules/speech-rule-engine/mjs/audio/audio_renderer.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
19
node_modules/speech-rule-engine/mjs/audio/audio_util.d.ts
generated
vendored
Normal file
19
node_modules/speech-rule-engine/mjs/audio/audio_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
export interface Tags {
|
||||
open?: EngineConst.personalityProps[];
|
||||
close?: EngineConst.personalityProps[];
|
||||
[personality: string]: any;
|
||||
}
|
||||
export type PauseValue = number | string;
|
||||
export interface Pause {
|
||||
pause: PauseValue;
|
||||
[personality: string]: any;
|
||||
}
|
||||
export type Markup = Pause | Tags;
|
||||
export declare function mergePause(oldPause: Pause | null, newPause: Pause, opt_merge?: (p1: PauseValue, p2: PauseValue) => PauseValue): Pause;
|
||||
export declare function mergeMarkup(oldPers: Tags, newPers: Tags): void;
|
||||
export declare function sortClose(open: EngineConst.personalityProps[], descrs: Tags[]): EngineConst.personalityProps[];
|
||||
export declare function personalityMarkup(descrs: AuditoryDescription[]): Markup[];
|
||||
export declare function isMarkupElement(element: Markup): boolean;
|
||||
export declare function isPauseElement(element: Markup): boolean;
|
||||
292
node_modules/speech-rule-engine/mjs/audio/audio_util.js
generated
vendored
Normal file
292
node_modules/speech-rule-engine/mjs/audio/audio_util.js
generated
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
import { setdifference } from '../common/base_util.js';
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { Engine } from '../common/engine.js';
|
||||
import { Span } from './span.js';
|
||||
export function mergePause(oldPause, newPause, opt_merge) {
|
||||
if (!oldPause) {
|
||||
return newPause;
|
||||
}
|
||||
return { pause: mergePause_(oldPause.pause, newPause.pause, opt_merge) };
|
||||
}
|
||||
function mergePause_(oldPause, newPause, opt_merge) {
|
||||
const merge = opt_merge ||
|
||||
function (x, y) {
|
||||
if (typeof x === 'number' && typeof y === 'number') {
|
||||
return x + y;
|
||||
}
|
||||
if (typeof x === 'number') {
|
||||
return y;
|
||||
}
|
||||
if (typeof y === 'number') {
|
||||
return x;
|
||||
}
|
||||
return [oldPause, newPause].sort()[0];
|
||||
};
|
||||
return merge.call(null, oldPause, newPause);
|
||||
}
|
||||
export function mergeMarkup(oldPers, newPers) {
|
||||
delete oldPers.open;
|
||||
newPers.close.forEach((x) => delete oldPers[x]);
|
||||
newPers.open.forEach((x) => (oldPers[x] = newPers[x]));
|
||||
const keys = Object.keys(oldPers);
|
||||
oldPers.open = keys;
|
||||
}
|
||||
export function sortClose(open, descrs) {
|
||||
if (open.length <= 1) {
|
||||
return open;
|
||||
}
|
||||
const result = [];
|
||||
for (let i = 0, descr; (descr = descrs[i]), open.length; i++) {
|
||||
if (!descr.close || !descr.close.length) {
|
||||
continue;
|
||||
}
|
||||
descr.close.forEach(function (x) {
|
||||
const index = open.indexOf(x);
|
||||
if (index !== -1) {
|
||||
result.unshift(x);
|
||||
open.splice(index, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
let PersonalityRanges_ = {};
|
||||
let LastOpen_ = [];
|
||||
export function personalityMarkup(descrs) {
|
||||
PersonalityRanges_ = {};
|
||||
LastOpen_ = [];
|
||||
let result = [];
|
||||
const currentPers = {};
|
||||
for (let i = 0, descr; (descr = descrs[i]); i++) {
|
||||
let pause = null;
|
||||
const span = descr.descriptionSpan();
|
||||
const pers = descr.personality;
|
||||
const join = pers[EngineConst.personalityProps.JOIN];
|
||||
delete pers[EngineConst.personalityProps.JOIN];
|
||||
if (typeof pers[EngineConst.personalityProps.PAUSE] !== 'undefined') {
|
||||
pause = {
|
||||
[EngineConst.personalityProps.PAUSE]: pers[EngineConst.personalityProps.PAUSE]
|
||||
};
|
||||
delete pers[EngineConst.personalityProps.PAUSE];
|
||||
}
|
||||
const diff = personalityDiff_(pers, currentPers);
|
||||
appendMarkup_(result, span, diff, join, pause, true);
|
||||
}
|
||||
result = result.concat(finaliseMarkup_());
|
||||
result = simplifyMarkup_(result);
|
||||
result = Engine.getInstance().cleanpause ? cleanPause(result) : result;
|
||||
return result;
|
||||
}
|
||||
function cleanPause(markup) {
|
||||
while (isPauseElement(markup[0])) {
|
||||
markup.shift();
|
||||
}
|
||||
while (isPauseElement(markup[markup.length - 1])) {
|
||||
markup.pop();
|
||||
}
|
||||
return markup;
|
||||
}
|
||||
function appendElement_(markup, element) {
|
||||
const last = markup[markup.length - 1];
|
||||
if (!last) {
|
||||
markup.push(element);
|
||||
return;
|
||||
}
|
||||
if (isSpanElement(element) && isSpanElement(last)) {
|
||||
if (typeof last.join === 'undefined') {
|
||||
last.span = last.span.concat(element.span);
|
||||
return;
|
||||
}
|
||||
const lstr = last['span'].pop();
|
||||
const fstr = element['span'].shift();
|
||||
last['span'].push(lstr + last.join + fstr);
|
||||
last['span'] = last['span'].concat(element.span);
|
||||
last.join = element.join;
|
||||
return;
|
||||
}
|
||||
if (isPauseElement(element) && isPauseElement(last)) {
|
||||
last.pause = mergePause_(last.pause, element.pause);
|
||||
return;
|
||||
}
|
||||
markup.push(element);
|
||||
}
|
||||
function simplifyMarkup_(markup) {
|
||||
const lastPers = {};
|
||||
const result = [];
|
||||
for (let i = 0, element; (element = markup[i]); i++) {
|
||||
if (!isMarkupElement(element)) {
|
||||
appendElement_(result, element);
|
||||
continue;
|
||||
}
|
||||
if (!element.close || element.close.length !== 1 || element.open.length) {
|
||||
copyValues_(element, lastPers);
|
||||
result.push(element);
|
||||
continue;
|
||||
}
|
||||
let nextElement = markup[i + 1];
|
||||
if (!nextElement || isSpanElement(nextElement)) {
|
||||
copyValues_(element, lastPers);
|
||||
result.push(element);
|
||||
continue;
|
||||
}
|
||||
const pauseElement = isPauseElement(nextElement) ? nextElement : null;
|
||||
if (pauseElement) {
|
||||
nextElement = markup[i + 2];
|
||||
}
|
||||
if (nextElement &&
|
||||
isMarkupElement(nextElement) &&
|
||||
nextElement.open[0] === element.close[0] &&
|
||||
!nextElement.close.length &&
|
||||
nextElement[nextElement.open[0]] === lastPers[nextElement.open[0]]) {
|
||||
if (pauseElement) {
|
||||
appendElement_(result, pauseElement);
|
||||
i = i + 2;
|
||||
}
|
||||
else {
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
copyValues_(element, lastPers);
|
||||
result.push(element);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function copyValues_(from, to) {
|
||||
if (from['rate']) {
|
||||
to['rate'] = from['rate'];
|
||||
}
|
||||
if (from['pitch']) {
|
||||
to['pitch'] = from['pitch'];
|
||||
}
|
||||
if (from['volume']) {
|
||||
to['volume'] = from['volume'];
|
||||
}
|
||||
}
|
||||
function finaliseMarkup_() {
|
||||
const final = [];
|
||||
for (let i = LastOpen_.length - 1; i >= 0; i--) {
|
||||
const pers = LastOpen_[i];
|
||||
if (pers.length) {
|
||||
const markup = { open: [], close: [] };
|
||||
for (let j = 0; j < pers.length; j++) {
|
||||
const per = pers[j];
|
||||
markup.close.push(per);
|
||||
markup[per] = 0;
|
||||
}
|
||||
final.push(markup);
|
||||
}
|
||||
}
|
||||
return final;
|
||||
}
|
||||
export function isMarkupElement(element) {
|
||||
return typeof element === 'object' && element.open;
|
||||
}
|
||||
export function isPauseElement(element) {
|
||||
return (typeof element === 'object' &&
|
||||
Object.keys(element).length === 1 &&
|
||||
Object.keys(element)[0] === EngineConst.personalityProps.PAUSE);
|
||||
}
|
||||
function isSpanElement(element) {
|
||||
const keys = Object.keys(element);
|
||||
return (typeof element === 'object' &&
|
||||
((keys.length === 1 && keys[0] === 'span') ||
|
||||
(keys.length === 2 &&
|
||||
((keys[0] === 'span' && keys[1] === 'join') ||
|
||||
(keys[1] === 'span' && keys[0] === 'join')))));
|
||||
}
|
||||
function appendMarkup_(markup, span, pers, join, pause, merge = false) {
|
||||
if (merge) {
|
||||
const last = markup[markup.length - 1];
|
||||
let oldJoin;
|
||||
if (last) {
|
||||
oldJoin = last[EngineConst.personalityProps.JOIN];
|
||||
}
|
||||
if (last && !span.speech && pause && isPauseElement(last)) {
|
||||
const pauseProp = EngineConst.personalityProps.PAUSE;
|
||||
last[pauseProp] = mergePause_(last[pauseProp], pause[pauseProp]);
|
||||
pause = null;
|
||||
}
|
||||
if (last &&
|
||||
span.speech &&
|
||||
Object.keys(pers).length === 0 &&
|
||||
isSpanElement(last)) {
|
||||
if (typeof oldJoin !== 'undefined') {
|
||||
const lastSpan = last['span'].pop();
|
||||
span = Span.stringAttr(lastSpan.speech + oldJoin + span.speech, lastSpan.attributes);
|
||||
}
|
||||
last['span'].push(span);
|
||||
span = Span.empty();
|
||||
last[EngineConst.personalityProps.JOIN] = join;
|
||||
}
|
||||
}
|
||||
if (Object.keys(pers).length !== 0) {
|
||||
markup.push(pers);
|
||||
}
|
||||
if (span.speech) {
|
||||
markup.push({ span: [span], join: join });
|
||||
}
|
||||
if (pause) {
|
||||
markup.push(pause);
|
||||
}
|
||||
}
|
||||
function personalityDiff_(current, old) {
|
||||
if (!old) {
|
||||
return current;
|
||||
}
|
||||
const result = {};
|
||||
for (const prop of EngineConst.personalityPropList) {
|
||||
const currentValue = current[prop];
|
||||
const oldValue = old[prop];
|
||||
if ((!currentValue && !oldValue) ||
|
||||
(currentValue && oldValue && currentValue === oldValue)) {
|
||||
continue;
|
||||
}
|
||||
const value = currentValue || 0;
|
||||
if (!isMarkupElement(result)) {
|
||||
result.open = [];
|
||||
result.close = [];
|
||||
}
|
||||
if (!currentValue) {
|
||||
result.close.push(prop);
|
||||
}
|
||||
if (!oldValue) {
|
||||
result.open.push(prop);
|
||||
}
|
||||
if (oldValue && currentValue) {
|
||||
result.close.push(prop);
|
||||
result.open.push(prop);
|
||||
}
|
||||
old[prop] = value;
|
||||
result[prop] = value;
|
||||
PersonalityRanges_[prop]
|
||||
? PersonalityRanges_[prop].push(value)
|
||||
: (PersonalityRanges_[prop] = [value]);
|
||||
}
|
||||
if (isMarkupElement(result)) {
|
||||
let c = result.close.slice();
|
||||
while (c.length > 0) {
|
||||
let lo = LastOpen_.pop();
|
||||
const loNew = setdifference(lo, c);
|
||||
c = setdifference(c, lo);
|
||||
lo = loNew;
|
||||
if (c.length === 0) {
|
||||
if (lo.length !== 0) {
|
||||
LastOpen_.push(lo);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (lo.length === 0) {
|
||||
continue;
|
||||
}
|
||||
result.close = result.close.concat(lo);
|
||||
result.open = result.open.concat(lo);
|
||||
for (let i = 0, open; (open = lo[i]); i++) {
|
||||
result[open] = old[open];
|
||||
}
|
||||
}
|
||||
LastOpen_.push(result.open);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
66
node_modules/speech-rule-engine/mjs/audio/auditory_description.d.ts
generated
vendored
Normal file
66
node_modules/speech-rule-engine/mjs/audio/auditory_description.d.ts
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import { Span } from './span.js';
|
||||
interface AudioDescr {
|
||||
context?: string;
|
||||
text: string;
|
||||
userValue?: string;
|
||||
annotation?: string;
|
||||
attributes?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
personality?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
layout?: string;
|
||||
}
|
||||
interface AudioFlags {
|
||||
adjust?: boolean;
|
||||
preprocess?: boolean;
|
||||
correct?: boolean;
|
||||
translate?: boolean;
|
||||
}
|
||||
export declare class AuditoryItem {
|
||||
data: AuditoryDescription;
|
||||
prev: AuditoryItem;
|
||||
next: AuditoryItem;
|
||||
constructor(data?: AuditoryDescription);
|
||||
}
|
||||
export declare class AuditoryList extends Set<AuditoryItem> {
|
||||
annotations: AuditoryItem[];
|
||||
private anchor;
|
||||
constructor(descrs: AuditoryDescription[]);
|
||||
first(): AuditoryItem;
|
||||
last(): AuditoryItem;
|
||||
push(item: AuditoryItem): void;
|
||||
pop(): AuditoryItem;
|
||||
delete(item: AuditoryItem): boolean;
|
||||
insertAfter(descr: AuditoryDescription, item: AuditoryItem): void;
|
||||
insertBefore(descr: AuditoryDescription, item: AuditoryItem): void;
|
||||
prevText(item: AuditoryItem): AuditoryItem;
|
||||
[Symbol.iterator](): IterableIterator<AuditoryItem>;
|
||||
nextText(item: AuditoryItem): AuditoryItem;
|
||||
clear(): void;
|
||||
empty(): boolean;
|
||||
toList(): AuditoryDescription[];
|
||||
}
|
||||
export declare class AuditoryDescription {
|
||||
context: string;
|
||||
text: string;
|
||||
userValue: string;
|
||||
annotation: string;
|
||||
attributes: {
|
||||
[key: string]: string;
|
||||
};
|
||||
personality: {
|
||||
[key: string]: string;
|
||||
};
|
||||
layout: string;
|
||||
static create(args: AudioDescr, flags?: AudioFlags): AuditoryDescription;
|
||||
constructor({ context, text, userValue, annotation, attributes, personality, layout }: AudioDescr);
|
||||
isEmpty(): boolean;
|
||||
clone(): AuditoryDescription;
|
||||
toString(): string;
|
||||
descriptionString(): string;
|
||||
descriptionSpan(): Span;
|
||||
equals(that: AuditoryDescription): boolean;
|
||||
}
|
||||
export {};
|
||||
179
node_modules/speech-rule-engine/mjs/audio/auditory_description.js
generated
vendored
Normal file
179
node_modules/speech-rule-engine/mjs/audio/auditory_description.js
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
import { Grammar } from '../rule_engine/grammar.js';
|
||||
import { Span } from './span.js';
|
||||
export class AuditoryItem {
|
||||
constructor(data = null) {
|
||||
this.data = data;
|
||||
this.prev = null;
|
||||
this.next = null;
|
||||
}
|
||||
}
|
||||
export class AuditoryList extends Set {
|
||||
constructor(descrs) {
|
||||
super();
|
||||
this.annotations = [];
|
||||
this.anchor = new AuditoryItem();
|
||||
this.anchor.next = this.anchor;
|
||||
this.anchor.prev = this.anchor;
|
||||
descrs.forEach((d) => {
|
||||
const item = new AuditoryItem(d);
|
||||
if (d.annotation) {
|
||||
this.annotations.push(item);
|
||||
}
|
||||
this.push(item);
|
||||
});
|
||||
}
|
||||
first() {
|
||||
return this.empty ? null : this.anchor.next;
|
||||
}
|
||||
last() {
|
||||
return this.empty ? null : this.anchor.prev;
|
||||
}
|
||||
push(item) {
|
||||
item.next = this.anchor;
|
||||
item.prev = this.anchor.prev;
|
||||
item.prev.next = item;
|
||||
this.anchor.prev = item;
|
||||
super.add(item);
|
||||
}
|
||||
pop() {
|
||||
const item = this.last();
|
||||
if (!item) {
|
||||
return null;
|
||||
}
|
||||
this.delete(item);
|
||||
return item;
|
||||
}
|
||||
delete(item) {
|
||||
if (!this.has(item)) {
|
||||
return false;
|
||||
}
|
||||
super.delete(item);
|
||||
item.prev.next = item.next;
|
||||
item.next = item.prev;
|
||||
return true;
|
||||
}
|
||||
insertAfter(descr, item) {
|
||||
this.insertBefore(descr, item.next);
|
||||
}
|
||||
insertBefore(descr, item) {
|
||||
const nitem = new AuditoryItem(descr);
|
||||
if (!item || !this.has(item)) {
|
||||
this.push(nitem);
|
||||
return;
|
||||
}
|
||||
item.prev.next = nitem;
|
||||
nitem.prev = item.prev;
|
||||
nitem.next = item;
|
||||
item.prev = nitem;
|
||||
}
|
||||
prevText(item) {
|
||||
do {
|
||||
item = item.prev;
|
||||
} while (item !== this.anchor && !item.data.text);
|
||||
return item === this.anchor ? null : item;
|
||||
}
|
||||
*[Symbol.iterator]() {
|
||||
let current = this.anchor.next;
|
||||
while (current !== this.anchor) {
|
||||
yield current;
|
||||
current = current.next;
|
||||
}
|
||||
}
|
||||
nextText(item) {
|
||||
while (item !== this.anchor && !item.data.text) {
|
||||
item = item.next;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
clear() {
|
||||
this.anchor.next = this.anchor;
|
||||
this.anchor.prev = this.anchor;
|
||||
super.clear();
|
||||
}
|
||||
empty() {
|
||||
return this.anchor.prev === this.anchor && this.anchor === this.anchor.next;
|
||||
}
|
||||
toList() {
|
||||
const result = [];
|
||||
let item = this.anchor.next;
|
||||
while (item !== this.anchor) {
|
||||
result.push(item.data);
|
||||
item = item.next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
export class AuditoryDescription {
|
||||
static create(args, flags = {}) {
|
||||
args.text = Grammar.getInstance().apply(args.text, flags);
|
||||
return new AuditoryDescription(args);
|
||||
}
|
||||
constructor({ context, text, userValue, annotation, attributes, personality, layout }) {
|
||||
this.context = context || '';
|
||||
this.text = text || '';
|
||||
this.userValue = userValue || '';
|
||||
this.annotation = annotation || '';
|
||||
this.attributes = attributes || {};
|
||||
this.personality = personality || {};
|
||||
this.layout = layout || '';
|
||||
}
|
||||
isEmpty() {
|
||||
return (this.context.length === 0 &&
|
||||
this.text.length === 0 &&
|
||||
this.userValue.length === 0 &&
|
||||
this.annotation.length === 0);
|
||||
}
|
||||
clone() {
|
||||
let personality;
|
||||
if (this.personality) {
|
||||
personality = {};
|
||||
for (const [key, val] of Object.entries(this.personality)) {
|
||||
personality[key] = val;
|
||||
}
|
||||
}
|
||||
let attributes;
|
||||
if (this.attributes) {
|
||||
attributes = {};
|
||||
for (const [key, val] of Object.entries(this.attributes)) {
|
||||
attributes[key] = val;
|
||||
}
|
||||
}
|
||||
return new AuditoryDescription({
|
||||
context: this.context,
|
||||
text: this.text,
|
||||
userValue: this.userValue,
|
||||
annotation: this.annotation,
|
||||
personality: personality,
|
||||
attributes: attributes,
|
||||
layout: this.layout
|
||||
});
|
||||
}
|
||||
toString() {
|
||||
return ('AuditoryDescription(context="' +
|
||||
this.context +
|
||||
'" ' +
|
||||
' text="' +
|
||||
this.text +
|
||||
'" ' +
|
||||
' userValue="' +
|
||||
this.userValue +
|
||||
'" ' +
|
||||
' annotation="' +
|
||||
this.annotation +
|
||||
'")');
|
||||
}
|
||||
descriptionString() {
|
||||
return this.context && this.text
|
||||
? this.context + ' ' + this.text
|
||||
: this.context || this.text;
|
||||
}
|
||||
descriptionSpan() {
|
||||
return Span.stringAttr(this.descriptionString(), this.attributes);
|
||||
}
|
||||
equals(that) {
|
||||
return (this.context === that.context &&
|
||||
this.text === that.text &&
|
||||
this.userValue === that.userValue &&
|
||||
this.annotation === that.annotation);
|
||||
}
|
||||
}
|
||||
12
node_modules/speech-rule-engine/mjs/audio/aural_rendering.d.ts
generated
vendored
Normal file
12
node_modules/speech-rule-engine/mjs/audio/aural_rendering.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { AudioRenderer } from './audio_renderer.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
import { Span } from './span.js';
|
||||
export declare function setSeparator(sep: string): void;
|
||||
export declare function getSeparator(): string;
|
||||
export declare function markup(descrs: AuditoryDescription[]): string;
|
||||
export declare function merge(strs: (Span | string)[]): string;
|
||||
export declare function finalize(str: string): string;
|
||||
export declare function error(key: string): string;
|
||||
export declare function registerRenderer(type: EngineConst.Markup, renderer: AudioRenderer): void;
|
||||
export declare function isXml(): boolean;
|
||||
68
node_modules/speech-rule-engine/mjs/audio/aural_rendering.js
generated
vendored
Normal file
68
node_modules/speech-rule-engine/mjs/audio/aural_rendering.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import { Engine } from '../common/engine.js';
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { AcssRenderer } from './acss_renderer.js';
|
||||
import { LayoutRenderer } from './layout_renderer.js';
|
||||
import { PunctuationRenderer } from './punctuation_renderer.js';
|
||||
import { SableRenderer } from './sable_renderer.js';
|
||||
import { Span } from './span.js';
|
||||
import { SsmlRenderer } from './ssml_renderer.js';
|
||||
import { CountingRenderer, StringRenderer } from './string_renderer.js';
|
||||
import { XmlRenderer } from './xml_renderer.js';
|
||||
const xmlInstance = new SsmlRenderer();
|
||||
const renderers = new Map([
|
||||
[EngineConst.Markup.NONE, new StringRenderer()],
|
||||
[EngineConst.Markup.COUNTING, new CountingRenderer()],
|
||||
[EngineConst.Markup.PUNCTUATION, new PunctuationRenderer()],
|
||||
[EngineConst.Markup.LAYOUT, new LayoutRenderer()],
|
||||
[EngineConst.Markup.ACSS, new AcssRenderer()],
|
||||
[EngineConst.Markup.SABLE, new SableRenderer()],
|
||||
[EngineConst.Markup.VOICEXML, xmlInstance],
|
||||
[EngineConst.Markup.SSML, xmlInstance]
|
||||
]);
|
||||
export function setSeparator(sep) {
|
||||
const renderer = renderers.get(Engine.getInstance().markup);
|
||||
if (renderer) {
|
||||
renderer.separator = sep;
|
||||
}
|
||||
}
|
||||
export function getSeparator() {
|
||||
const renderer = renderers.get(Engine.getInstance().markup);
|
||||
return renderer ? renderer.separator : '';
|
||||
}
|
||||
export function markup(descrs) {
|
||||
const renderer = renderers.get(Engine.getInstance().markup);
|
||||
if (!renderer) {
|
||||
return '';
|
||||
}
|
||||
return renderer.markup(descrs);
|
||||
}
|
||||
export function merge(strs) {
|
||||
const span = strs.map((s) => {
|
||||
return typeof s === 'string' ? Span.stringEmpty(s) : s;
|
||||
});
|
||||
const renderer = renderers.get(Engine.getInstance().markup);
|
||||
if (!renderer) {
|
||||
return strs.join();
|
||||
}
|
||||
return renderer.merge(span);
|
||||
}
|
||||
export function finalize(str) {
|
||||
const renderer = renderers.get(Engine.getInstance().markup);
|
||||
if (!renderer) {
|
||||
return str;
|
||||
}
|
||||
return renderer.finalize(str);
|
||||
}
|
||||
export function error(key) {
|
||||
const renderer = renderers.get(Engine.getInstance().markup);
|
||||
if (!renderer) {
|
||||
return '';
|
||||
}
|
||||
return renderer.error(key);
|
||||
}
|
||||
export function registerRenderer(type, renderer) {
|
||||
renderers.set(type, renderer);
|
||||
}
|
||||
export function isXml() {
|
||||
return renderers.get(Engine.getInstance().markup) instanceof XmlRenderer;
|
||||
}
|
||||
17
node_modules/speech-rule-engine/mjs/audio/layout_renderer.d.ts
generated
vendored
Normal file
17
node_modules/speech-rule-engine/mjs/audio/layout_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as AudioUtil from './audio_util.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
import { XmlRenderer } from './xml_renderer.js';
|
||||
export declare class LayoutRenderer extends XmlRenderer {
|
||||
static options: {
|
||||
cayleyshort: boolean;
|
||||
linebreaks: boolean;
|
||||
};
|
||||
finalize(str: string): string;
|
||||
pause(_pause: AudioUtil.Pause): string;
|
||||
prosodyElement(attr: string, value: number): string;
|
||||
closeTag(tag: string): string;
|
||||
markup(descrs: AuditoryDescription[]): string;
|
||||
private processContent;
|
||||
private values;
|
||||
private layoutValue;
|
||||
}
|
||||
368
node_modules/speech-rule-engine/mjs/audio/layout_renderer.js
generated
vendored
Normal file
368
node_modules/speech-rule-engine/mjs/audio/layout_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,368 @@
|
||||
import { Debugger } from '../common/debugger.js';
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { Engine } from '../common/engine.js';
|
||||
import * as AudioUtil from './audio_util.js';
|
||||
import { XmlRenderer } from './xml_renderer.js';
|
||||
export class LayoutRenderer extends XmlRenderer {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.values = new Map();
|
||||
}
|
||||
finalize(str) {
|
||||
setRelValues(this.values.get('rel'));
|
||||
return setTwoDim(str);
|
||||
}
|
||||
pause(_pause) {
|
||||
return '';
|
||||
}
|
||||
prosodyElement(attr, value) {
|
||||
return attr === EngineConst.personalityProps.LAYOUT ? `<${value}>` : '';
|
||||
}
|
||||
closeTag(tag) {
|
||||
return `</${tag}>`;
|
||||
}
|
||||
markup(descrs) {
|
||||
this.values.clear();
|
||||
const result = [];
|
||||
let content = [];
|
||||
for (const descr of descrs) {
|
||||
if (!descr.layout) {
|
||||
content.push(descr);
|
||||
continue;
|
||||
}
|
||||
result.push(this.processContent(content));
|
||||
content = [];
|
||||
const [pref, layout, value] = this.layoutValue(descr.layout);
|
||||
if (pref === 'begin') {
|
||||
result.push('<' + layout + (value ? ` value="${value}"` : '') + '>');
|
||||
continue;
|
||||
}
|
||||
if (pref === 'end') {
|
||||
result.push('</' + layout + '>');
|
||||
continue;
|
||||
}
|
||||
console.warn('Something went wrong with layout markup: ' + layout);
|
||||
}
|
||||
result.push(this.processContent(content));
|
||||
return result.join('');
|
||||
}
|
||||
processContent(content) {
|
||||
const result = [];
|
||||
const markup = AudioUtil.personalityMarkup(content);
|
||||
for (let i = 0, descr; (descr = markup[i]); i++) {
|
||||
if (descr.span) {
|
||||
result.push(this.merge(descr.span));
|
||||
continue;
|
||||
}
|
||||
if (AudioUtil.isPauseElement(descr)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result.join('');
|
||||
}
|
||||
layoutValue(layout) {
|
||||
const match = layout.match(/^(begin|end|)(.*\D)(\d*)$/);
|
||||
const value = match[3];
|
||||
if (!value) {
|
||||
return [match[1], match[2], ''];
|
||||
}
|
||||
layout = match[2];
|
||||
if (!this.values.has(layout)) {
|
||||
this.values.set(layout, {});
|
||||
}
|
||||
this.values.get(layout)[value] = true;
|
||||
return [match[1], layout, value];
|
||||
}
|
||||
}
|
||||
LayoutRenderer.options = {
|
||||
cayleyshort: Engine.getInstance().cayleyshort,
|
||||
linebreaks: Engine.getInstance().linebreaks
|
||||
};
|
||||
let twodExpr = '';
|
||||
const handlers = {
|
||||
TABLE: handleTable,
|
||||
CASES: handleCases,
|
||||
CAYLEY: handleCayley,
|
||||
MATRIX: handleMatrix,
|
||||
CELL: recurseTree,
|
||||
FENCE: recurseTree,
|
||||
ROW: recurseTree,
|
||||
FRACTION: handleFraction,
|
||||
NUMERATOR: handleFractionPart,
|
||||
DENOMINATOR: handleFractionPart,
|
||||
REL: handleRelation,
|
||||
OP: handleRelation
|
||||
};
|
||||
function applyHandler(element) {
|
||||
const tag = DomUtil.tagName(element);
|
||||
const handler = handlers[tag];
|
||||
return handler ? handler(element) : element.textContent;
|
||||
}
|
||||
const relValues = new Map();
|
||||
function setRelValues(values) {
|
||||
relValues.clear();
|
||||
if (!values)
|
||||
return;
|
||||
const keys = Object.keys(values)
|
||||
.map((x) => parseInt(x))
|
||||
.sort();
|
||||
for (let i = 0, key; (key = keys[i]); i++) {
|
||||
relValues.set(key, i + 1);
|
||||
}
|
||||
}
|
||||
function setTwoDim(str) {
|
||||
twodExpr = '';
|
||||
const dom = DomUtil.parseInput(`<all>${str}</all>`);
|
||||
Debugger.getInstance().output(DomUtil.formatXml(dom.toString()));
|
||||
twodExpr = recurseTree(dom);
|
||||
return twodExpr;
|
||||
}
|
||||
function combineContent(str1, str2) {
|
||||
if (!str1 || !str2) {
|
||||
return str1 + str2;
|
||||
}
|
||||
const height1 = strHeight(str1);
|
||||
const height2 = strHeight(str2);
|
||||
const diff = height1 - height2;
|
||||
str1 = diff < 0 ? padCell(str1, height2, strWidth(str1)) : str1;
|
||||
str2 = diff > 0 ? padCell(str2, height1, strWidth(str2)) : str2;
|
||||
const lines1 = str1.split(/\r\n|\r|\n/);
|
||||
const lines2 = str2.split(/\r\n|\r|\n/);
|
||||
const result = [];
|
||||
for (let i = 0; i < lines1.length; i++) {
|
||||
result.push(lines1[i] + lines2[i]);
|
||||
}
|
||||
return result.join('\n');
|
||||
}
|
||||
function recurseTree(dom) {
|
||||
let result = '';
|
||||
for (const child of Array.from(dom.childNodes)) {
|
||||
if (child.nodeType === DomUtil.NodeType.TEXT_NODE) {
|
||||
result = combineContent(result, child.textContent);
|
||||
continue;
|
||||
}
|
||||
result = combineContent(result, applyHandler(child));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function strHeight(str) {
|
||||
return str.split(/\r\n|\r|\n/).length;
|
||||
}
|
||||
function strWidth(str) {
|
||||
return str.split(/\r\n|\r|\n/).reduce((max, x) => Math.max(x.length, max), 0);
|
||||
}
|
||||
function padHeight(str, height) {
|
||||
const padding = height - strHeight(str);
|
||||
return str + (padding > 0 ? new Array(padding + 1).join('\n') : '');
|
||||
}
|
||||
function padWidth(str, width) {
|
||||
const lines = str.split(/\r\n|\r|\n/);
|
||||
const result = [];
|
||||
for (const line of lines) {
|
||||
const padding = width - line.length;
|
||||
result.push(line + (padding > 0 ? new Array(padding + 1).join('⠀') : ''));
|
||||
}
|
||||
return result.join('\n');
|
||||
}
|
||||
function padCell(str, height, width) {
|
||||
str = padHeight(str, height);
|
||||
return padWidth(str, width);
|
||||
}
|
||||
function assembleRows(matrix) {
|
||||
const children = Array.from(matrix.childNodes);
|
||||
const mat = [];
|
||||
for (const row of children) {
|
||||
if (row.nodeType !== DomUtil.NodeType.ELEMENT_NODE) {
|
||||
continue;
|
||||
}
|
||||
mat.push(handleRow(row));
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
function getMaxParameters(mat) {
|
||||
const maxHeight = mat.reduce((max, x) => Math.max(x.height, max), 0);
|
||||
const maxWidth = [];
|
||||
for (let i = 0; i < mat[0].width.length; i++) {
|
||||
maxWidth.push(mat.map((x) => x.width[i]).reduce((max, x) => Math.max(max, x), 0));
|
||||
}
|
||||
return [maxHeight, maxWidth];
|
||||
}
|
||||
function combineCells(mat, maxWidth) {
|
||||
const newMat = [];
|
||||
for (const row of mat) {
|
||||
if (row.height === 0) {
|
||||
continue;
|
||||
}
|
||||
const newCells = [];
|
||||
for (let i = 0; i < row.cells.length; i++) {
|
||||
newCells.push(padCell(row.cells[i], row.height, maxWidth[i]));
|
||||
}
|
||||
row.cells = newCells;
|
||||
newMat.push(row);
|
||||
}
|
||||
return newMat;
|
||||
}
|
||||
function combineRows(mat, maxHeight) {
|
||||
if (maxHeight === 1) {
|
||||
return mat
|
||||
.map((row) => row.lfence + row.cells.join(row.sep) + row.rfence)
|
||||
.join('\n');
|
||||
}
|
||||
const result = [];
|
||||
for (const row of mat) {
|
||||
const sep = verticalArrange(row.sep, row.height);
|
||||
let str = row.cells.shift();
|
||||
while (row.cells.length) {
|
||||
str = combineContent(str, sep);
|
||||
str = combineContent(str, row.cells.shift());
|
||||
}
|
||||
str = combineContent(verticalArrange(row.lfence, row.height), str);
|
||||
str = combineContent(str, verticalArrange(row.rfence, row.height));
|
||||
result.push(str);
|
||||
result.push(row.lfence + new Array(strWidth(str) - 3).join(row.sep) + row.rfence);
|
||||
}
|
||||
return result.slice(0, -1).join('\n');
|
||||
}
|
||||
function verticalArrange(char, height) {
|
||||
let str = '';
|
||||
while (height) {
|
||||
str += char + '\n';
|
||||
height--;
|
||||
}
|
||||
return str.slice(0, -1);
|
||||
}
|
||||
function getFence(node) {
|
||||
if (node.nodeType === DomUtil.NodeType.ELEMENT_NODE &&
|
||||
DomUtil.tagName(node) === 'FENCE') {
|
||||
return applyHandler(node);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function handleMatrix(matrix) {
|
||||
let mat = assembleRows(matrix);
|
||||
const [maxHeight, maxWidth] = getMaxParameters(mat);
|
||||
mat = combineCells(mat, maxWidth);
|
||||
return combineRows(mat, maxHeight);
|
||||
}
|
||||
function handleTable(table) {
|
||||
let mat = assembleRows(table);
|
||||
mat.forEach((row) => {
|
||||
row.cells = row.cells.slice(1).slice(0, -1);
|
||||
row.width = row.width.slice(1).slice(0, -1);
|
||||
});
|
||||
const [maxHeight, maxWidth] = getMaxParameters(mat);
|
||||
mat = combineCells(mat, maxWidth);
|
||||
return combineRows(mat, maxHeight);
|
||||
}
|
||||
function handleCases(cases) {
|
||||
let mat = assembleRows(cases);
|
||||
mat.forEach((row) => {
|
||||
row.cells = row.cells.slice(0, -1);
|
||||
row.width = row.width.slice(0, -1);
|
||||
});
|
||||
const [maxHeight, maxWidth] = getMaxParameters(mat);
|
||||
mat = combineCells(mat, maxWidth);
|
||||
return combineRows(mat, maxHeight);
|
||||
}
|
||||
function handleCayley(cayley) {
|
||||
let mat = assembleRows(cayley);
|
||||
mat.forEach((row) => {
|
||||
row.cells = row.cells.slice(1).slice(0, -1);
|
||||
row.width = row.width.slice(1).slice(0, -1);
|
||||
row.sep = row.sep + row.sep;
|
||||
});
|
||||
const [maxHeight, maxWidth] = getMaxParameters(mat);
|
||||
const bar = {
|
||||
lfence: '',
|
||||
rfence: '',
|
||||
cells: maxWidth.map((x) => '⠐' + new Array(x).join('⠒')),
|
||||
width: maxWidth,
|
||||
height: 1,
|
||||
sep: mat[0].sep
|
||||
};
|
||||
if (Engine.getInstance().cayleyshort && mat[0].cells[0] === '⠀') {
|
||||
bar.cells[0] = '⠀';
|
||||
}
|
||||
mat.splice(1, 0, bar);
|
||||
mat = combineCells(mat, maxWidth);
|
||||
return combineRows(mat, maxHeight);
|
||||
}
|
||||
function handleRow(row) {
|
||||
const children = Array.from(row.childNodes);
|
||||
const lfence = getFence(children[0]);
|
||||
const rfence = getFence(children[children.length - 1]);
|
||||
if (lfence) {
|
||||
children.shift();
|
||||
}
|
||||
if (rfence) {
|
||||
children.pop();
|
||||
}
|
||||
let sep = '';
|
||||
const cells = [];
|
||||
for (const child of children) {
|
||||
if (child.nodeType === DomUtil.NodeType.TEXT_NODE) {
|
||||
sep = child.textContent;
|
||||
continue;
|
||||
}
|
||||
const result = applyHandler(child);
|
||||
cells.push(result);
|
||||
}
|
||||
return {
|
||||
lfence: lfence,
|
||||
rfence: rfence,
|
||||
sep: sep,
|
||||
cells: cells,
|
||||
height: cells.reduce((max, x) => Math.max(strHeight(x), max), 0),
|
||||
width: cells.map(strWidth)
|
||||
};
|
||||
}
|
||||
function centerCell(cell, width) {
|
||||
const cw = strWidth(cell);
|
||||
const center = (width - cw) / 2;
|
||||
const [lpad, rpad] = Math.floor(center) === center
|
||||
? [center, center]
|
||||
: [Math.floor(center), Math.ceil(center)];
|
||||
const lines = cell.split(/\r\n|\r|\n/);
|
||||
const result = [];
|
||||
const [lstr, rstr] = [
|
||||
new Array(lpad + 1).join('⠀'),
|
||||
new Array(rpad + 1).join('⠀')
|
||||
];
|
||||
for (const line of lines) {
|
||||
result.push(lstr + line + rstr);
|
||||
}
|
||||
return result.join('\n');
|
||||
}
|
||||
function handleFraction(frac) {
|
||||
const [open, num, , den, close] = Array.from(frac.childNodes);
|
||||
const numerator = applyHandler(num);
|
||||
const denominator = applyHandler(den);
|
||||
const nwidth = strWidth(numerator);
|
||||
const dwidth = strWidth(denominator);
|
||||
let maxWidth = Math.max(nwidth, dwidth);
|
||||
const bar = open + new Array(maxWidth + 1).join('⠒') + close;
|
||||
maxWidth = bar.length;
|
||||
return (`${centerCell(numerator, maxWidth)}\n${bar}\n` +
|
||||
`${centerCell(denominator, maxWidth)}`);
|
||||
}
|
||||
function handleFractionPart(prt) {
|
||||
const fchild = prt.firstChild;
|
||||
const content = recurseTree(prt);
|
||||
if (fchild && fchild.nodeType === DomUtil.NodeType.ELEMENT_NODE) {
|
||||
if (DomUtil.tagName(fchild) === 'ENGLISH') {
|
||||
return '⠰' + content;
|
||||
}
|
||||
if (DomUtil.tagName(fchild) === 'NUMBER') {
|
||||
return '⠼' + content;
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
function handleRelation(rel) {
|
||||
if (!Engine.getInstance().linebreaks) {
|
||||
return recurseTree(rel);
|
||||
}
|
||||
const value = relValues.get(parseInt(rel.getAttribute('value')));
|
||||
return (value ? `<br value="${value}"/>` : '') + recurseTree(rel);
|
||||
}
|
||||
11
node_modules/speech-rule-engine/mjs/audio/markup_renderer.d.ts
generated
vendored
Normal file
11
node_modules/speech-rule-engine/mjs/audio/markup_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { AbstractAudioRenderer } from './abstract_audio_renderer.js';
|
||||
import { Pause } from './audio_util.js';
|
||||
export declare abstract class MarkupRenderer extends AbstractAudioRenderer {
|
||||
protected ignoreElements: string[];
|
||||
private scaleFunction;
|
||||
abstract pause(pause: Pause): void;
|
||||
abstract prosodyElement(key: string, value: number): void;
|
||||
setScaleFunction(a: number, b: number, c: number, d: number, decimals?: number): void;
|
||||
applyScaleFunction(value: number): number;
|
||||
protected ignoreElement(key: string): boolean;
|
||||
}
|
||||
24
node_modules/speech-rule-engine/mjs/audio/markup_renderer.js
generated
vendored
Normal file
24
node_modules/speech-rule-engine/mjs/audio/markup_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { AbstractAudioRenderer } from './abstract_audio_renderer.js';
|
||||
export class MarkupRenderer extends AbstractAudioRenderer {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.ignoreElements = [EngineConst.personalityProps.LAYOUT];
|
||||
this.scaleFunction = null;
|
||||
}
|
||||
setScaleFunction(a, b, c, d, decimals = 0) {
|
||||
this.scaleFunction = (x) => {
|
||||
const delta = (x - a) / (b - a);
|
||||
const num = c * (1 - delta) + d * delta;
|
||||
return +(Math.round((num + 'e+' + decimals)) +
|
||||
'e-' +
|
||||
decimals);
|
||||
};
|
||||
}
|
||||
applyScaleFunction(value) {
|
||||
return this.scaleFunction ? this.scaleFunction(value) : value;
|
||||
}
|
||||
ignoreElement(key) {
|
||||
return this.ignoreElements.indexOf(key) !== -1;
|
||||
}
|
||||
}
|
||||
8
node_modules/speech-rule-engine/mjs/audio/punctuation_renderer.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/mjs/audio/punctuation_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { AbstractAudioRenderer } from './abstract_audio_renderer.js';
|
||||
import * as AudioUtil from './audio_util.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
export declare class PunctuationRenderer extends AbstractAudioRenderer {
|
||||
private static PAUSE_PUNCTUATION;
|
||||
markup(descrs: AuditoryDescription[]): string;
|
||||
pause(pause: AudioUtil.PauseValue): string;
|
||||
}
|
||||
50
node_modules/speech-rule-engine/mjs/audio/punctuation_renderer.js
generated
vendored
Normal file
50
node_modules/speech-rule-engine/mjs/audio/punctuation_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { AbstractAudioRenderer } from './abstract_audio_renderer.js';
|
||||
import * as AudioUtil from './audio_util.js';
|
||||
export class PunctuationRenderer extends AbstractAudioRenderer {
|
||||
markup(descrs) {
|
||||
const markup = AudioUtil.personalityMarkup(descrs);
|
||||
let str = '';
|
||||
let pause = null;
|
||||
let span = false;
|
||||
for (let i = 0, descr; (descr = markup[i]); i++) {
|
||||
if (AudioUtil.isMarkupElement(descr)) {
|
||||
continue;
|
||||
}
|
||||
if (AudioUtil.isPauseElement(descr)) {
|
||||
pause = descr;
|
||||
continue;
|
||||
}
|
||||
if (pause) {
|
||||
str += this.pause(pause[EngineConst.personalityProps.PAUSE]);
|
||||
pause = null;
|
||||
}
|
||||
str += (span ? this.separator : '') + this.merge(descr.span);
|
||||
span = true;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
pause(pause) {
|
||||
let newPause;
|
||||
if (typeof pause === 'number') {
|
||||
if (pause <= 250) {
|
||||
newPause = 'short';
|
||||
}
|
||||
else if (pause <= 500) {
|
||||
newPause = 'medium';
|
||||
}
|
||||
else {
|
||||
newPause = 'long';
|
||||
}
|
||||
}
|
||||
else {
|
||||
newPause = pause;
|
||||
}
|
||||
return PunctuationRenderer.PAUSE_PUNCTUATION.get(newPause) || '';
|
||||
}
|
||||
}
|
||||
PunctuationRenderer.PAUSE_PUNCTUATION = new Map([
|
||||
['short', ','],
|
||||
['medium', ';'],
|
||||
['long', '.']
|
||||
]);
|
||||
9
node_modules/speech-rule-engine/mjs/audio/sable_renderer.d.ts
generated
vendored
Normal file
9
node_modules/speech-rule-engine/mjs/audio/sable_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { Pause } from './audio_util.js';
|
||||
import { XmlRenderer } from './xml_renderer.js';
|
||||
export declare class SableRenderer extends XmlRenderer {
|
||||
finalize(str: string): string;
|
||||
pause(pause: Pause): string;
|
||||
prosodyElement(tag: EngineConst.personalityProps, value: number): string;
|
||||
closeTag(tag: string): string;
|
||||
}
|
||||
35
node_modules/speech-rule-engine/mjs/audio/sable_renderer.js
generated
vendored
Normal file
35
node_modules/speech-rule-engine/mjs/audio/sable_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { XmlRenderer } from './xml_renderer.js';
|
||||
export class SableRenderer extends XmlRenderer {
|
||||
finalize(str) {
|
||||
return ('<?xml version="1.0"?>' +
|
||||
'<!DOCTYPE SABLE PUBLIC "-//SABLE//DTD SABLE speech mark up//EN"' +
|
||||
' "Sable.v0_2.dtd" []><SABLE>' +
|
||||
this.separator +
|
||||
str +
|
||||
this.separator +
|
||||
'</SABLE>');
|
||||
}
|
||||
pause(pause) {
|
||||
return ('<BREAK ' +
|
||||
'MSEC="' +
|
||||
this.pauseValue(pause[EngineConst.personalityProps.PAUSE]) +
|
||||
'"/>');
|
||||
}
|
||||
prosodyElement(tag, value) {
|
||||
value = this.applyScaleFunction(value);
|
||||
switch (tag) {
|
||||
case EngineConst.personalityProps.PITCH:
|
||||
return '<PITCH RANGE="' + value + '%">';
|
||||
case EngineConst.personalityProps.RATE:
|
||||
return '<RATE SPEED="' + value + '%">';
|
||||
case EngineConst.personalityProps.VOLUME:
|
||||
return '<VOLUME LEVEL="' + value + '%">';
|
||||
default:
|
||||
return '<' + tag.toUpperCase() + ' VALUE="' + value + '">';
|
||||
}
|
||||
}
|
||||
closeTag(tag) {
|
||||
return '</' + tag.toUpperCase() + '>';
|
||||
}
|
||||
}
|
||||
15
node_modules/speech-rule-engine/mjs/audio/span.d.ts
generated
vendored
Normal file
15
node_modules/speech-rule-engine/mjs/audio/span.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
export type SpanAttrs = {
|
||||
[key: string]: string;
|
||||
};
|
||||
export declare class Span {
|
||||
speech: string;
|
||||
attributes: SpanAttrs;
|
||||
constructor(speech: string, attributes: SpanAttrs);
|
||||
static empty(): Span;
|
||||
static stringEmpty(str: string): Span;
|
||||
static stringAttr(str: string, attr: SpanAttrs): Span;
|
||||
static singleton(str: string, def?: SpanAttrs): Span[];
|
||||
static node(str: string, node: Element, def?: SpanAttrs): Span;
|
||||
static attributeList: string[];
|
||||
static getAttributes(node: Element): SpanAttrs;
|
||||
}
|
||||
33
node_modules/speech-rule-engine/mjs/audio/span.js
generated
vendored
Normal file
33
node_modules/speech-rule-engine/mjs/audio/span.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
export class Span {
|
||||
constructor(speech, attributes) {
|
||||
this.speech = speech;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
static empty() {
|
||||
return new Span('', {});
|
||||
}
|
||||
static stringEmpty(str) {
|
||||
return new Span(str, {});
|
||||
}
|
||||
static stringAttr(str, attr) {
|
||||
return new Span(str, attr);
|
||||
}
|
||||
static singleton(str, def = {}) {
|
||||
return [Span.stringAttr(str, def)];
|
||||
}
|
||||
static node(str, node, def = {}) {
|
||||
const attr = Span.getAttributes(node);
|
||||
Object.assign(attr, def);
|
||||
return new Span(str, attr);
|
||||
}
|
||||
static getAttributes(node) {
|
||||
const attrs = {};
|
||||
for (const attr of Span.attributeList) {
|
||||
if (node.hasAttribute(attr)) {
|
||||
attrs[attr] = node.getAttribute(attr);
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
}
|
||||
Span.attributeList = ['id', 'extid'];
|
||||
17
node_modules/speech-rule-engine/mjs/audio/ssml_renderer.d.ts
generated
vendored
Normal file
17
node_modules/speech-rule-engine/mjs/audio/ssml_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Pause } from './audio_util.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
import { Span } from './span.js';
|
||||
import { XmlRenderer } from './xml_renderer.js';
|
||||
export declare class SsmlRenderer extends XmlRenderer {
|
||||
finalize(str: string): string;
|
||||
pause(pause: Pause): string;
|
||||
prosodyElement(attr: string, value: number): string;
|
||||
closeTag(_tag: string): string;
|
||||
static MARK_ONCE: boolean;
|
||||
static MARK_KIND: boolean;
|
||||
private static CHARACTER_ATTR;
|
||||
private static MARKS;
|
||||
markup(descrs: AuditoryDescription[]): string;
|
||||
merge(spans: Span[]): string;
|
||||
private isEmptySpan;
|
||||
}
|
||||
82
node_modules/speech-rule-engine/mjs/audio/ssml_renderer.js
generated
vendored
Normal file
82
node_modules/speech-rule-engine/mjs/audio/ssml_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
import { Engine } from '../common/engine.js';
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { XmlRenderer } from './xml_renderer.js';
|
||||
export class SsmlRenderer extends XmlRenderer {
|
||||
finalize(str) {
|
||||
return ('<?xml version="1.0"?><speak version="1.1"' +
|
||||
' xmlns="http://www.w3.org/2001/10/synthesis"' +
|
||||
` xml:lang="${Engine.getInstance().locale}">` +
|
||||
'<prosody rate="' +
|
||||
Engine.getInstance().getRate() +
|
||||
'%">' +
|
||||
this.separator +
|
||||
str +
|
||||
this.separator +
|
||||
'</prosody></speak>');
|
||||
}
|
||||
pause(pause) {
|
||||
return ('<break ' +
|
||||
'time="' +
|
||||
this.pauseValue(pause[EngineConst.personalityProps.PAUSE]) +
|
||||
'ms"/>');
|
||||
}
|
||||
prosodyElement(attr, value) {
|
||||
value = Math.floor(this.applyScaleFunction(value));
|
||||
const valueStr = value < 0 ? value.toString() : '+' + value.toString();
|
||||
return ('<prosody ' +
|
||||
attr.toLowerCase() +
|
||||
'="' +
|
||||
valueStr +
|
||||
(attr === EngineConst.personalityProps.VOLUME ? '>' : '%">'));
|
||||
}
|
||||
closeTag(_tag) {
|
||||
return '</prosody>';
|
||||
}
|
||||
markup(descrs) {
|
||||
SsmlRenderer.MARKS = {};
|
||||
return super.markup(descrs);
|
||||
}
|
||||
merge(spans) {
|
||||
const result = [];
|
||||
let lastMark = '';
|
||||
for (let i = 0; i < spans.length; i++) {
|
||||
const span = spans[i];
|
||||
if (this.isEmptySpan(span))
|
||||
continue;
|
||||
const kind = SsmlRenderer.MARK_KIND ? span.attributes['kind'] : '';
|
||||
const id = Engine.getInstance().automark
|
||||
? span.attributes['id']
|
||||
: Engine.getInstance().mark
|
||||
? span.attributes['extid']
|
||||
: '';
|
||||
if (id &&
|
||||
id !== lastMark &&
|
||||
!(SsmlRenderer.MARK_ONCE && SsmlRenderer.MARKS[id])) {
|
||||
result.push(kind ? `<mark name="${id}" kind="${kind}"/>` : `<mark name="${id}"/>`);
|
||||
lastMark = id;
|
||||
SsmlRenderer.MARKS[id] = true;
|
||||
}
|
||||
if (Engine.getInstance().character &&
|
||||
span.speech.length === 1 &&
|
||||
span.speech.match(/[a-zA-Z]/)) {
|
||||
result.push('<say-as interpret-as="' +
|
||||
SsmlRenderer.CHARACTER_ATTR +
|
||||
'">' +
|
||||
span.speech +
|
||||
'</say-as>');
|
||||
}
|
||||
else {
|
||||
result.push(span.speech);
|
||||
}
|
||||
}
|
||||
return result.join(this.separator);
|
||||
}
|
||||
isEmptySpan(span) {
|
||||
const sep = span.attributes['separator'];
|
||||
return span.speech.match(/^\s*$/) && (!sep || sep.match(/^\s*$/));
|
||||
}
|
||||
}
|
||||
SsmlRenderer.MARK_ONCE = false;
|
||||
SsmlRenderer.MARK_KIND = true;
|
||||
SsmlRenderer.CHARACTER_ATTR = 'character';
|
||||
SsmlRenderer.MARKS = {};
|
||||
8
node_modules/speech-rule-engine/mjs/audio/string_renderer.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/mjs/audio/string_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { AbstractAudioRenderer } from './abstract_audio_renderer.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
export declare class StringRenderer extends AbstractAudioRenderer {
|
||||
markup(descrs: AuditoryDescription[]): string;
|
||||
}
|
||||
export declare class CountingRenderer extends StringRenderer {
|
||||
finalize(str: string): string;
|
||||
}
|
||||
34
node_modules/speech-rule-engine/mjs/audio/string_renderer.js
generated
vendored
Normal file
34
node_modules/speech-rule-engine/mjs/audio/string_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Engine } from '../common/engine.js';
|
||||
import { AbstractAudioRenderer } from './abstract_audio_renderer.js';
|
||||
import { personalityMarkup } from './audio_util.js';
|
||||
export class StringRenderer extends AbstractAudioRenderer {
|
||||
markup(descrs) {
|
||||
let str = '';
|
||||
const markup = personalityMarkup(descrs);
|
||||
const clean = markup.filter((x) => x.span);
|
||||
if (!clean.length) {
|
||||
return str;
|
||||
}
|
||||
const len = clean.length - 1;
|
||||
for (let i = 0, descr; (descr = clean[i]); i++) {
|
||||
if (descr.span) {
|
||||
str += this.merge(descr.span);
|
||||
}
|
||||
if (i >= len) {
|
||||
continue;
|
||||
}
|
||||
const join = descr.join;
|
||||
str += typeof join === 'undefined' ? this.separator : join;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
export class CountingRenderer extends StringRenderer {
|
||||
finalize(str) {
|
||||
const output = super.finalize(str);
|
||||
const count = Engine.getInstance().modality === 'braille' ? '⣿⠀⣿⠀⣿⠀⣿⠀⣿⠀' : '0123456789';
|
||||
let second = new Array(Math.trunc(output.length / 10) + 1).join(count);
|
||||
second += count.slice(0, output.length % 10);
|
||||
return output + '\n' + second;
|
||||
}
|
||||
}
|
||||
7
node_modules/speech-rule-engine/mjs/audio/xml_renderer.d.ts
generated
vendored
Normal file
7
node_modules/speech-rule-engine/mjs/audio/xml_renderer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { AuditoryDescription } from './auditory_description.js';
|
||||
import { MarkupRenderer } from './markup_renderer.js';
|
||||
export declare abstract class XmlRenderer extends MarkupRenderer {
|
||||
abstract closeTag(tag: EngineConst.personalityProps): void;
|
||||
markup(descrs: AuditoryDescription[]): string;
|
||||
}
|
||||
38
node_modules/speech-rule-engine/mjs/audio/xml_renderer.js
generated
vendored
Normal file
38
node_modules/speech-rule-engine/mjs/audio/xml_renderer.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { SREError } from '../common/engine.js';
|
||||
import * as AudioUtil from './audio_util.js';
|
||||
import { MarkupRenderer } from './markup_renderer.js';
|
||||
export class XmlRenderer extends MarkupRenderer {
|
||||
markup(descrs) {
|
||||
this.setScaleFunction(-2, 2, -100, 100, 2);
|
||||
const markup = AudioUtil.personalityMarkup(descrs);
|
||||
const result = [];
|
||||
const currentOpen = [];
|
||||
for (let i = 0, descr; (descr = markup[i]); i++) {
|
||||
if (descr.span) {
|
||||
result.push(this.merge(descr.span));
|
||||
continue;
|
||||
}
|
||||
if (AudioUtil.isPauseElement(descr)) {
|
||||
result.push(this.pause(descr));
|
||||
continue;
|
||||
}
|
||||
if (descr.close.length) {
|
||||
for (let j = 0; j < descr.close.length; j++) {
|
||||
const last = currentOpen.pop();
|
||||
if (descr.close.indexOf(last) === -1) {
|
||||
throw new SREError('Unknown closing markup element: ' + last);
|
||||
}
|
||||
result.push(this.closeTag(last));
|
||||
}
|
||||
}
|
||||
if (descr.open.length) {
|
||||
const open = AudioUtil.sortClose(descr.open.slice(), markup.slice(i + 1));
|
||||
open.forEach((o) => {
|
||||
result.push(this.prosodyElement(o, descr[o]));
|
||||
currentOpen.push(o);
|
||||
});
|
||||
}
|
||||
}
|
||||
return result.join(' ');
|
||||
}
|
||||
}
|
||||
3
node_modules/speech-rule-engine/mjs/common/base_util.d.ts
generated
vendored
Normal file
3
node_modules/speech-rule-engine/mjs/common/base_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export declare function removeEmpty(strs: string[]): string[];
|
||||
export declare function interleaveLists(list1: any[], list2: any[]): any[];
|
||||
export declare function setdifference(a: any[], b: any[]): any[];
|
||||
24
node_modules/speech-rule-engine/mjs/common/base_util.js
generated
vendored
Normal file
24
node_modules/speech-rule-engine/mjs/common/base_util.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
export function removeEmpty(strs) {
|
||||
return strs.filter((str) => str);
|
||||
}
|
||||
export function interleaveLists(list1, list2) {
|
||||
const result = [];
|
||||
while (list1.length || list2.length) {
|
||||
if (list1.length) {
|
||||
result.push(list1.shift());
|
||||
}
|
||||
if (list2.length) {
|
||||
result.push(list2.shift());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function setdifference(a, b) {
|
||||
if (!a) {
|
||||
return [];
|
||||
}
|
||||
if (!b) {
|
||||
return a;
|
||||
}
|
||||
return a.filter((x) => b.indexOf(x) < 0);
|
||||
}
|
||||
5
node_modules/speech-rule-engine/mjs/common/browser_util.d.ts
generated
vendored
Normal file
5
node_modules/speech-rule-engine/mjs/common/browser_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare function detectIE(): boolean;
|
||||
export declare function detectEdge(): boolean;
|
||||
export declare const mapsForIE: {
|
||||
[key: string]: any;
|
||||
};
|
||||
60
node_modules/speech-rule-engine/mjs/common/browser_util.js
generated
vendored
Normal file
60
node_modules/speech-rule-engine/mjs/common/browser_util.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import { SystemExternal } from './system_external.js';
|
||||
import { xpath } from './xpath_util.js';
|
||||
export function detectIE() {
|
||||
const isIE = typeof window !== 'undefined' &&
|
||||
'ActiveXObject' in window &&
|
||||
'clipboardData' in window;
|
||||
if (!isIE) {
|
||||
return false;
|
||||
}
|
||||
loadMapsForIE();
|
||||
loadWGXpath();
|
||||
return true;
|
||||
}
|
||||
export function detectEdge() {
|
||||
var _a;
|
||||
const isEdge = typeof window !== 'undefined' &&
|
||||
'MSGestureEvent' in window &&
|
||||
((_a = window.chrome) === null || _a === void 0 ? void 0 : _a.loadTimes) === null;
|
||||
if (!isEdge) {
|
||||
return false;
|
||||
}
|
||||
document.evaluate = null;
|
||||
loadWGXpath(true);
|
||||
return true;
|
||||
}
|
||||
export const mapsForIE = null;
|
||||
function loadWGXpath(opt_isEdge) {
|
||||
loadScript(SystemExternal.WGXpath);
|
||||
installWGXpath(opt_isEdge);
|
||||
}
|
||||
function installWGXpath(opt_isEdge, opt_count) {
|
||||
let count = opt_count || 1;
|
||||
if (typeof wgxpath === 'undefined' && count < 10) {
|
||||
setTimeout(function () {
|
||||
installWGXpath(opt_isEdge, count++);
|
||||
}, 200);
|
||||
return;
|
||||
}
|
||||
if (count >= 10) {
|
||||
return;
|
||||
}
|
||||
SystemExternal.wgxpath = wgxpath;
|
||||
opt_isEdge
|
||||
? SystemExternal.wgxpath.install({ document: document })
|
||||
: SystemExternal.wgxpath.install();
|
||||
xpath.evaluate = document.evaluate;
|
||||
xpath.result = XPathResult;
|
||||
xpath.createNSResolver = document.createNSResolver;
|
||||
}
|
||||
function loadMapsForIE() {
|
||||
loadScript(SystemExternal.mathmapsIePath);
|
||||
}
|
||||
function loadScript(src) {
|
||||
const scr = SystemExternal.document.createElement('script');
|
||||
scr.type = 'text/javascript';
|
||||
scr.src = src;
|
||||
SystemExternal.document.head
|
||||
? SystemExternal.document.head.appendChild(scr)
|
||||
: SystemExternal.document.body.appendChild(scr);
|
||||
}
|
||||
20
node_modules/speech-rule-engine/mjs/common/cli.d.ts
generated
vendored
Normal file
20
node_modules/speech-rule-engine/mjs/common/cli.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
export declare class Cli {
|
||||
static process: any;
|
||||
static commander: any;
|
||||
setup: {
|
||||
[key: string]: string | boolean;
|
||||
};
|
||||
processors: string[];
|
||||
dp: DOMParser;
|
||||
private output;
|
||||
constructor();
|
||||
set(arg: string, value: string | boolean, _def: string): void;
|
||||
processor(processor: string): void;
|
||||
private loadLocales;
|
||||
enumerate(all?: boolean): Promise<void>;
|
||||
execute(input: string): void;
|
||||
readline(): void;
|
||||
commandLine(): Promise<void>;
|
||||
private runProcessors_;
|
||||
private readExpression_;
|
||||
}
|
||||
245
node_modules/speech-rule-engine/mjs/common/cli.js
generated
vendored
Normal file
245
node_modules/speech-rule-engine/mjs/common/cli.js
generated
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { Axis, DynamicCstr } from '../rule_engine/dynamic_cstr.js';
|
||||
import * as MathCompoundStore from '../rule_engine/math_compound_store.js';
|
||||
import { SpeechRuleEngine } from '../rule_engine/speech_rule_engine.js';
|
||||
import { ClearspeakPreferences } from '../speech_rules/clearspeak_preferences.js';
|
||||
import { Debugger } from './debugger.js';
|
||||
import { EnginePromise, SREError } from './engine.js';
|
||||
import * as EngineConst from './engine_const.js';
|
||||
import * as ProcessorFactory from './processor_factory.js';
|
||||
import * as System from './system.js';
|
||||
import { SystemExternal } from './system_external.js';
|
||||
import { Variables } from './variables.js';
|
||||
export class Cli {
|
||||
constructor() {
|
||||
this.setup = {
|
||||
mode: EngineConst.Mode.SYNC
|
||||
};
|
||||
this.processors = [];
|
||||
this.output = Cli.process.stdout;
|
||||
this.dp = new SystemExternal.xmldom.DOMParser({
|
||||
onError: (_key, _msg) => {
|
||||
throw new SREError('XML DOM error!');
|
||||
}
|
||||
});
|
||||
}
|
||||
set(arg, value, _def) {
|
||||
this.setup[arg] = typeof value === 'undefined' ? true : value;
|
||||
}
|
||||
processor(processor) {
|
||||
this.processors.push(processor);
|
||||
}
|
||||
loadLocales() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
for (const loc of Variables.LOCALES.keys()) {
|
||||
yield System.setupEngine({ locale: loc });
|
||||
}
|
||||
});
|
||||
}
|
||||
enumerate() {
|
||||
return __awaiter(this, arguments, void 0, function* (all = false) {
|
||||
const promise = System.setupEngine(this.setup);
|
||||
const order = DynamicCstr.DEFAULT_ORDER.slice(0, -1);
|
||||
return (all ? this.loadLocales() : promise).then(() => EnginePromise.getall().then(() => {
|
||||
const length = order.map((x) => x.length);
|
||||
const maxLength = (obj, index) => {
|
||||
length[index] = Math.max.apply(null, Object.keys(obj)
|
||||
.map((x) => x.length)
|
||||
.concat(length[index]));
|
||||
};
|
||||
const compStr = (str, length) => str + new Array(length - str.length + 1).join(' ');
|
||||
let dynamic = SpeechRuleEngine.getInstance().enumerate();
|
||||
dynamic = MathCompoundStore.enumerate(dynamic);
|
||||
const table = [];
|
||||
maxLength(dynamic, 0);
|
||||
for (const [ax1, dyna1] of Object.entries(dynamic)) {
|
||||
let clear1 = true;
|
||||
maxLength(dyna1, 1);
|
||||
for (const [ax2, dyna2] of Object.entries(dyna1)) {
|
||||
let clear2 = true;
|
||||
maxLength(dyna2, 2);
|
||||
for (const [ax3, dyna3] of Object.entries(dyna2)) {
|
||||
const styles = Object.keys(dyna3).sort();
|
||||
if (ax3 === 'clearspeak') {
|
||||
let clear3 = true;
|
||||
const prefs = ClearspeakPreferences.getLocalePreferences(dynamic)[ax1];
|
||||
if (!prefs) {
|
||||
continue;
|
||||
}
|
||||
for (const dyna4 of Object.values(prefs)) {
|
||||
table.push([
|
||||
compStr(clear1 ? ax1 : '', length[0]),
|
||||
compStr(clear2 ? ax2 : '', length[1]),
|
||||
compStr(clear3 ? ax3 : '', length[2]),
|
||||
dyna4.join(', ')
|
||||
]);
|
||||
clear1 = false;
|
||||
clear2 = false;
|
||||
clear3 = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
table.push([
|
||||
compStr(clear1 ? ax1 : '', length[0]),
|
||||
compStr(clear2 ? ax2 : '', length[1]),
|
||||
compStr(ax3, length[2]),
|
||||
styles.join(', ')
|
||||
]);
|
||||
}
|
||||
clear1 = false;
|
||||
clear2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
let i = 0;
|
||||
const header = order.map((x) => compStr(x, length[i++]));
|
||||
const markdown = Cli.commander.opts().pprint;
|
||||
const separator = length.map((x) => new Array(x + 1).join(markdown ? '-' : '='));
|
||||
if (!markdown) {
|
||||
separator[i - 1] = separator[i - 1] + '========================';
|
||||
}
|
||||
table.unshift(separator);
|
||||
table.unshift(header);
|
||||
let output = table.map((x) => x.join(' | '));
|
||||
if (markdown) {
|
||||
output = output.map((x) => `| ${x} |`);
|
||||
output.unshift(`# Options SRE v${System.version}\n`);
|
||||
}
|
||||
console.info(output.join('\n'));
|
||||
}));
|
||||
});
|
||||
}
|
||||
execute(input) {
|
||||
EnginePromise.getall().then(() => {
|
||||
this.runProcessors_((proc, file) => this.output.write(System.processFile(proc, file) + '\n'), input);
|
||||
});
|
||||
}
|
||||
readline() {
|
||||
Cli.process.stdin.setEncoding('utf8');
|
||||
const inter = SystemExternal.extRequire('readline').createInterface({
|
||||
input: Cli.process.stdin,
|
||||
output: this.output
|
||||
});
|
||||
let input = '';
|
||||
inter.on('line', ((expr) => {
|
||||
input += expr;
|
||||
if (this.readExpression_(input)) {
|
||||
inter.close();
|
||||
}
|
||||
}).bind(this));
|
||||
inter.on('close', (() => {
|
||||
this.runProcessors_((proc, expr) => {
|
||||
inter.output.write(ProcessorFactory.output(proc, expr) + '\n');
|
||||
}, input);
|
||||
System.engineReady().then(() => Debugger.getInstance().exit(() => System.exit(0)));
|
||||
}).bind(this));
|
||||
}
|
||||
commandLine() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const commander = Cli.commander;
|
||||
const system = System;
|
||||
const set = ((key) => {
|
||||
return (val, def) => this.set(key, val, def);
|
||||
}).bind(this);
|
||||
const processor = this.processor.bind(this);
|
||||
commander
|
||||
.version(system.version)
|
||||
.usage('[options] <file ...>')
|
||||
.option('-i, --input [name]', 'Input file [name]. (Deprecated)')
|
||||
.option('-o, --output [name]', 'Output file [name]. Defaults to stdout.')
|
||||
.option('-d, --domain [name]', 'Speech rule set [name]. See --options' + ' for details.', set(Axis.DOMAIN), DynamicCstr.DEFAULT_VALUES[Axis.DOMAIN])
|
||||
.option('-s, --style [name]', 'Speech style [name]. See --options' + ' for details.', set(Axis.STYLE), DynamicCstr.DEFAULT_VALUES[Axis.STYLE])
|
||||
.option('-c, --locale [code]', 'Locale [code].', set(Axis.LOCALE), DynamicCstr.DEFAULT_VALUES[Axis.LOCALE])
|
||||
.option('-b, --modality [name]', 'Modality [name].', set(Axis.MODALITY), DynamicCstr.DEFAULT_VALUES[Axis.MODALITY])
|
||||
.option('-k, --markup [name]', 'Generate speech output with markup tags.', set('markup'), 'none')
|
||||
.option('-e, --automark', 'Automatically set marks for external reference.', set('automark'))
|
||||
.option('-L, --linebreaks', 'Linebreak marking in 2D output.', set('linebreaks'))
|
||||
.option('-r, --rate [value]', 'Base rate [value] for tagged speech' + ' output.', set('rate'), '100')
|
||||
.option('-p, --speech', 'Generate speech output (default).', () => processor('speech'))
|
||||
.option('-a, --audit', 'Generate auditory descriptions (JSON format).', () => processor('description'))
|
||||
.option('-j, --json', 'Generate JSON of semantic tree.', () => processor('json'))
|
||||
.option('-x, --xml', 'Generate XML of semantic tree.', () => processor('semantic'))
|
||||
.option('-m, --mathml', 'Generate enriched MathML.', () => processor('enriched'))
|
||||
.option('-u, --rebuild', 'Rebuild semantic tree from enriched MathML.', () => processor('rebuild'))
|
||||
.option('-t, --latex', 'Accepts LaTeX input for certain locale/modality combinations.', () => processor('latex'))
|
||||
.option('-g, --generate <depth>', 'Include generated speech in enriched' +
|
||||
' MathML (with -m option only).', set('speech'), 'none')
|
||||
.option('-w, --structure', 'Include structure attribute in enriched' +
|
||||
' MathML (with -m option only).', set('structure'))
|
||||
.option('-A, --aria', 'Include aria tree annotations' +
|
||||
' MathML (with -m and -w option only).', set('aria'))
|
||||
.option('-P, --pprint', 'Pretty print output whenever possible.', set('pprint'))
|
||||
.option('-f, --rules [name]', 'Loads a local rule file [name].', set('rules'))
|
||||
.option('-C, --subiso [name]', 'Supplementary country code (or similar) for the given locale.', set('subiso'))
|
||||
.option('-N, --number', 'Translate number to word.', () => processor('number'))
|
||||
.option('-O, --ordinal', 'Translate number to ordinal.', () => processor('ordinal'), 'ordinal')
|
||||
.option('-S, --numeric', 'Translate number to numeric ordinal.', () => processor('numericOrdinal'))
|
||||
.option('-F, --vulgar', 'Translate vulgar fraction to word. Provide vulgar fraction as slash seperated numbers.', () => processor('vulgar'))
|
||||
.option('-v, --verbose', 'Verbose mode.')
|
||||
.option('-l, --log [name]', 'Log file [name].')
|
||||
.option('--opt', 'List engine setup options. Output as markdown with -P option.')
|
||||
.option('--opt-all', 'List engine setup options for all available locales. Output as markdown with -P option.')
|
||||
.on('option:opt', () => {
|
||||
this.enumerate().then(() => System.exit(0));
|
||||
})
|
||||
.on('option:opt-all', () => {
|
||||
this.enumerate(true).then(() => System.exit(0));
|
||||
})
|
||||
.parse(Cli.process.argv);
|
||||
yield System.engineReady().then(() => System.setupEngine(this.setup));
|
||||
const options = Cli.commander.opts();
|
||||
if (options.output) {
|
||||
this.output = SystemExternal.fs.createWriteStream(options.output);
|
||||
}
|
||||
if (options.verbose) {
|
||||
yield Debugger.getInstance().init(options.log);
|
||||
}
|
||||
if (options.input) {
|
||||
this.execute(options.input);
|
||||
}
|
||||
if (Cli.commander.args.length) {
|
||||
Cli.commander.args.forEach(this.execute.bind(this));
|
||||
System.engineReady().then(() => Debugger.getInstance().exit(() => System.exit(0)));
|
||||
}
|
||||
else {
|
||||
this.readline();
|
||||
}
|
||||
});
|
||||
}
|
||||
runProcessors_(processor, input) {
|
||||
try {
|
||||
if (!this.processors.length) {
|
||||
this.processors.push('speech');
|
||||
}
|
||||
if (input) {
|
||||
this.processors.forEach((proc) => processor(proc, input));
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err.name + ': ' + err.message);
|
||||
Debugger.getInstance().exit(() => Cli.process.exit(1));
|
||||
}
|
||||
}
|
||||
readExpression_(input) {
|
||||
try {
|
||||
const testInput = input.replace(/(&|#|;)/g, '');
|
||||
this.dp.parseFromString(testInput, 'text/xml');
|
||||
}
|
||||
catch (_err) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Cli.process = SystemExternal.extRequire('process');
|
||||
Cli.commander = SystemExternal.documentSupported
|
||||
? null
|
||||
: SystemExternal.extRequire('commander').program;
|
||||
15
node_modules/speech-rule-engine/mjs/common/debugger.d.ts
generated
vendored
Normal file
15
node_modules/speech-rule-engine/mjs/common/debugger.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
export declare class Debugger {
|
||||
private static instance;
|
||||
private isActive_;
|
||||
private outputFunction_;
|
||||
private fileHandle;
|
||||
private stream_;
|
||||
static getInstance(): Debugger;
|
||||
init(opt_file?: string): any;
|
||||
output(...args: any[]): void;
|
||||
generateOutput(func: () => string[]): void;
|
||||
exit(callback?: () => any): void;
|
||||
private constructor();
|
||||
private startDebugFile_;
|
||||
private output_;
|
||||
}
|
||||
61
node_modules/speech-rule-engine/mjs/common/debugger.js
generated
vendored
Normal file
61
node_modules/speech-rule-engine/mjs/common/debugger.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import { SystemExternal } from './system_external.js';
|
||||
export class Debugger {
|
||||
static getInstance() {
|
||||
Debugger.instance = Debugger.instance || new Debugger();
|
||||
return Debugger.instance;
|
||||
}
|
||||
init(opt_file) {
|
||||
if (opt_file) {
|
||||
this.startDebugFile_(opt_file);
|
||||
}
|
||||
this.isActive_ = true;
|
||||
return this.fileHandle;
|
||||
}
|
||||
output(...args) {
|
||||
if (this.isActive_) {
|
||||
this.output_(args);
|
||||
}
|
||||
}
|
||||
generateOutput(func) {
|
||||
if (this.isActive_) {
|
||||
this.output_(func.apply(func, []));
|
||||
}
|
||||
}
|
||||
exit(callback = () => { }) {
|
||||
this.fileHandle.then(() => {
|
||||
if (this.isActive_ && this.stream_) {
|
||||
this.stream_.end('', '', callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
constructor() {
|
||||
this.isActive_ = false;
|
||||
this.outputFunction_ = console.info;
|
||||
this.fileHandle = Promise.resolve();
|
||||
this.stream_ = null;
|
||||
}
|
||||
startDebugFile_(filename) {
|
||||
this.fileHandle = SystemExternal.fs.promises.open(filename, 'w');
|
||||
this.fileHandle = this.fileHandle.then((handle) => {
|
||||
this.stream_ = handle.createWriteStream(filename);
|
||||
this.outputFunction_ = function (...args) {
|
||||
this.stream_.write(args.join(' '));
|
||||
this.stream_.write('\n');
|
||||
}.bind(this);
|
||||
this.stream_.on('error', function (_error) {
|
||||
console.info('Invalid log file. Debug information sent to console.');
|
||||
this.outputFunction_ = console.info;
|
||||
}.bind(this));
|
||||
this.stream_.on('finish', function () {
|
||||
console.info('Finalizing debug file.');
|
||||
});
|
||||
});
|
||||
}
|
||||
output_(outputList) {
|
||||
if (console.info === this.outputFunction_) {
|
||||
this.outputFunction_.apply(console, ['Speech Rule Engine Debugger:'].concat(outputList));
|
||||
return;
|
||||
}
|
||||
this.fileHandle.then(() => this.outputFunction_.apply(this.outputFunction_, ['Speech Rule Engine Debugger:'].concat(outputList)));
|
||||
}
|
||||
}
|
||||
27
node_modules/speech-rule-engine/mjs/common/dom_util.d.ts
generated
vendored
Normal file
27
node_modules/speech-rule-engine/mjs/common/dom_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
export declare function toArray(nodeList: NodeList | NamedNodeMap): any[];
|
||||
export declare function parseInput(input: string): Element;
|
||||
export declare enum NodeType {
|
||||
ELEMENT_NODE = 1,
|
||||
ATTRIBUTE_NODE = 2,
|
||||
TEXT_NODE = 3,
|
||||
CDATA_SECTION_NODE = 4,
|
||||
ENTITY_REFERENCE_NODE = 5,
|
||||
ENTITY_NODE = 6,
|
||||
PROCESSING_INSTRUCTION_NODE = 7,
|
||||
COMMENT_NODE = 8,
|
||||
DOCUMENT_NODE = 9,
|
||||
DOCUMENT_TYPE_NODE = 10,
|
||||
DOCUMENT_FRAGMENT_NODE = 11,
|
||||
NOTATION_NODE = 12
|
||||
}
|
||||
export declare function replaceNode(oldNode: Node, newNode: Node): void;
|
||||
export declare function createElement(tag: string): Element;
|
||||
export declare function createElementNS(url: string, tag: string): Element;
|
||||
export declare function createTextNode(content: string): Text;
|
||||
export declare function formatXml(xml: string): string;
|
||||
export declare function querySelectorAllByAttr(node: Element, attr: string): Element[];
|
||||
export declare function querySelectorAllByAttrValue(node: Element, attr: string, value: string): Element[];
|
||||
export declare function querySelectorAll(node: Element, tag: string): Element[];
|
||||
export declare function tagName(node: Element): string;
|
||||
export declare function cloneNode(node: Element): Element;
|
||||
export declare function serializeXml(node: Element): string;
|
||||
156
node_modules/speech-rule-engine/mjs/common/dom_util.js
generated
vendored
Normal file
156
node_modules/speech-rule-engine/mjs/common/dom_util.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
import { Engine, SREError } from './engine.js';
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { SystemExternal } from './system_external.js';
|
||||
import * as XpathUtil from './xpath_util.js';
|
||||
export function toArray(nodeList) {
|
||||
const nodeArray = [];
|
||||
for (let i = 0, m = nodeList.length; i < m; i++) {
|
||||
nodeArray.push(nodeList[i]);
|
||||
}
|
||||
return nodeArray;
|
||||
}
|
||||
function trimInput(input) {
|
||||
input = input.replace(/ /g, ' ');
|
||||
return input.replace(/>[ \f\n\r\t\v\u200b]+</g, '><').trim();
|
||||
}
|
||||
export function parseInput(input) {
|
||||
const dp = new SystemExternal.xmldom.DOMParser();
|
||||
const clean_input = trimInput(input);
|
||||
const allValues = clean_input.match(/&(?!lt|gt|amp|quot|apos)\w+;/g);
|
||||
const html = !!allValues;
|
||||
if (!clean_input) {
|
||||
throw new Error('Empty input!');
|
||||
}
|
||||
try {
|
||||
const doc = dp.parseFromString(clean_input, html ? 'text/html' : 'text/xml');
|
||||
if (Engine.getInstance().mode === EngineConst.Mode.HTTP) {
|
||||
XpathUtil.xpath.currentDocument = doc;
|
||||
return html ? doc.body.childNodes[0] : doc.documentElement;
|
||||
}
|
||||
return doc.documentElement;
|
||||
}
|
||||
catch (err) {
|
||||
throw new SREError('Illegal input: ' + err.message);
|
||||
}
|
||||
}
|
||||
export var NodeType;
|
||||
(function (NodeType) {
|
||||
NodeType[NodeType["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
|
||||
NodeType[NodeType["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
|
||||
NodeType[NodeType["TEXT_NODE"] = 3] = "TEXT_NODE";
|
||||
NodeType[NodeType["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
|
||||
NodeType[NodeType["ENTITY_REFERENCE_NODE"] = 5] = "ENTITY_REFERENCE_NODE";
|
||||
NodeType[NodeType["ENTITY_NODE"] = 6] = "ENTITY_NODE";
|
||||
NodeType[NodeType["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
|
||||
NodeType[NodeType["COMMENT_NODE"] = 8] = "COMMENT_NODE";
|
||||
NodeType[NodeType["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
|
||||
NodeType[NodeType["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
|
||||
NodeType[NodeType["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
|
||||
NodeType[NodeType["NOTATION_NODE"] = 12] = "NOTATION_NODE";
|
||||
})(NodeType || (NodeType = {}));
|
||||
export function replaceNode(oldNode, newNode) {
|
||||
if (!oldNode.parentNode) {
|
||||
return;
|
||||
}
|
||||
oldNode.parentNode.insertBefore(newNode, oldNode);
|
||||
oldNode.parentNode.removeChild(oldNode);
|
||||
}
|
||||
export function createElement(tag) {
|
||||
return SystemExternal.document.createElement(tag);
|
||||
}
|
||||
export function createElementNS(url, tag) {
|
||||
return SystemExternal.document.createElementNS(url, tag);
|
||||
}
|
||||
export function createTextNode(content) {
|
||||
return SystemExternal.document.createTextNode(content);
|
||||
}
|
||||
export function formatXml(xml) {
|
||||
let formatted = '';
|
||||
let reg = /(>)(<)(\/*)/g;
|
||||
xml = xml.replace(reg, '$1\r\n$2$3');
|
||||
let pad = 0;
|
||||
let split = xml.split('\r\n');
|
||||
reg = /(\.)*(<)(\/*)/g;
|
||||
split = split
|
||||
.map((x) => x.replace(reg, '$1\r\n$2$3').split('\r\n'))
|
||||
.reduce((x, y) => x.concat(y), []);
|
||||
while (split.length) {
|
||||
let node = split.shift();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
let indent = 0;
|
||||
if (node.match(/^<\w[^>/]*>[^>]+$/)) {
|
||||
const match = matchingStartEnd(node, split[0]);
|
||||
if (match[0]) {
|
||||
if (match[1]) {
|
||||
node = node + split.shift().slice(0, -match[1].length);
|
||||
if (match[1].trim()) {
|
||||
split.unshift(match[1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
node = node + split.shift();
|
||||
}
|
||||
}
|
||||
else {
|
||||
indent = 1;
|
||||
}
|
||||
}
|
||||
else if (node.match(/^<\/\w/)) {
|
||||
if (pad !== 0) {
|
||||
pad -= 1;
|
||||
}
|
||||
}
|
||||
else if (node.match(/^<\w[^>]*[^/]>.*$/)) {
|
||||
indent = 1;
|
||||
}
|
||||
else if (node.match(/^<\w[^>]*\/>.+$/)) {
|
||||
const position = node.indexOf('>') + 1;
|
||||
const rest = node.slice(position);
|
||||
if (rest.trim()) {
|
||||
split.unshift();
|
||||
}
|
||||
node = node.slice(0, position) + rest;
|
||||
}
|
||||
else {
|
||||
indent = 0;
|
||||
}
|
||||
formatted += new Array(pad + 1).join(' ') + node + '\r\n';
|
||||
pad += indent;
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
function matchingStartEnd(start, end) {
|
||||
if (!end) {
|
||||
return [false, ''];
|
||||
}
|
||||
const tag1 = start.match(/^<([^> ]+).*>/);
|
||||
const tag2 = end.match(/^<\/([^>]+)>(.*)/);
|
||||
return tag1 && tag2 && tag1[1] === tag2[1] ? [true, tag2[2]] : [false, ''];
|
||||
}
|
||||
export function querySelectorAllByAttr(node, attr) {
|
||||
return node.querySelectorAll
|
||||
? toArray(node.querySelectorAll(`[${attr}]`))
|
||||
: XpathUtil.evalXPath(`.//*[@${attr}]`, node);
|
||||
}
|
||||
export function querySelectorAllByAttrValue(node, attr, value) {
|
||||
return node.querySelectorAll
|
||||
? toArray(node.querySelectorAll(`[${attr}="${value}"]`))
|
||||
: XpathUtil.evalXPath(`.//*[@${attr}="${value}"]`, node);
|
||||
}
|
||||
export function querySelectorAll(node, tag) {
|
||||
return node.querySelectorAll
|
||||
? toArray(node.querySelectorAll(tag))
|
||||
: XpathUtil.evalXPath(`.//${tag}`, node);
|
||||
}
|
||||
export function tagName(node) {
|
||||
return node.tagName.toUpperCase();
|
||||
}
|
||||
export function cloneNode(node) {
|
||||
return node.cloneNode(true);
|
||||
}
|
||||
export function serializeXml(node) {
|
||||
const xmls = new SystemExternal.xmldom.XMLSerializer();
|
||||
return xmls.serializeToString(node);
|
||||
}
|
||||
78
node_modules/speech-rule-engine/mjs/common/engine.d.ts
generated
vendored
Normal file
78
node_modules/speech-rule-engine/mjs/common/engine.d.ts
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
import { AuditoryDescription } from '../audio/auditory_description.js';
|
||||
import * as Dcstr from '../rule_engine/dynamic_cstr.js';
|
||||
import * as EngineConst from './engine_const.js';
|
||||
export declare class SREError extends Error {
|
||||
message: string;
|
||||
name: string;
|
||||
constructor(message?: string);
|
||||
}
|
||||
export declare class Engine {
|
||||
static BINARY_FEATURES: string[];
|
||||
static STRING_FEATURES: string[];
|
||||
private static instance;
|
||||
customLoader: (locale: string) => Promise<string>;
|
||||
evaluator: (p1: string, p2: Dcstr.DynamicCstr) => string | null;
|
||||
defaultParser: Dcstr.DynamicCstrParser;
|
||||
parser: Dcstr.DynamicCstrParser;
|
||||
parsers: {
|
||||
[key: string]: Dcstr.DynamicCstrParser;
|
||||
};
|
||||
dynamicCstr: Dcstr.DynamicCstr;
|
||||
comparator: Dcstr.Comparator;
|
||||
mode: EngineConst.Mode;
|
||||
init: boolean;
|
||||
delay: boolean;
|
||||
comparators: {
|
||||
[key: string]: () => Dcstr.Comparator;
|
||||
};
|
||||
domain: string;
|
||||
style: string;
|
||||
_defaultLocale: string;
|
||||
set defaultLocale(loc: string);
|
||||
get defaultLocale(): string;
|
||||
locale: string;
|
||||
subiso: string;
|
||||
modality: string;
|
||||
speech: EngineConst.Speech;
|
||||
markup: EngineConst.Markup;
|
||||
mark: boolean;
|
||||
automark: boolean;
|
||||
character: boolean;
|
||||
cleanpause: boolean;
|
||||
cayleyshort: boolean;
|
||||
linebreaks: boolean;
|
||||
rate: string;
|
||||
walker: string;
|
||||
structure: boolean;
|
||||
aria: boolean;
|
||||
ruleSets: string[];
|
||||
strict: boolean;
|
||||
isIE: boolean;
|
||||
isEdge: boolean;
|
||||
pprint: boolean;
|
||||
config: boolean;
|
||||
rules: string;
|
||||
prune: string;
|
||||
static getInstance(): Engine;
|
||||
static defaultEvaluator(str: string, _cstr: Dcstr.DynamicCstr): string;
|
||||
static nodeEvaluator: (node: Element) => AuditoryDescription[];
|
||||
static evaluateNode(node: Element): AuditoryDescription[];
|
||||
getRate(): number;
|
||||
setDynamicCstr(opt_dynamic?: Dcstr.AxisMap): void;
|
||||
private constructor();
|
||||
configurate(feature: {
|
||||
[key: string]: boolean | string;
|
||||
}): void;
|
||||
setCustomLoader(fn: any): void;
|
||||
}
|
||||
export default Engine;
|
||||
export declare class EnginePromise {
|
||||
static loaded: {
|
||||
[locale: string]: [boolean, boolean];
|
||||
};
|
||||
static promises: {
|
||||
[locale: string]: Promise<string>;
|
||||
};
|
||||
static get(locale?: string): Promise<string>;
|
||||
static getall(): Promise<string[]>;
|
||||
}
|
||||
175
node_modules/speech-rule-engine/mjs/common/engine.js
generated
vendored
Normal file
175
node_modules/speech-rule-engine/mjs/common/engine.js
generated
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
import * as Dcstr from '../rule_engine/dynamic_cstr.js';
|
||||
import * as EngineConst from './engine_const.js';
|
||||
import { Debugger } from './debugger.js';
|
||||
import { Variables } from './variables.js';
|
||||
export class SREError extends Error {
|
||||
constructor(message = '') {
|
||||
super();
|
||||
this.message = message;
|
||||
this.name = 'SRE Error';
|
||||
}
|
||||
}
|
||||
export class Engine {
|
||||
set defaultLocale(loc) {
|
||||
this._defaultLocale = Variables.ensureLocale(loc, this._defaultLocale);
|
||||
}
|
||||
get defaultLocale() {
|
||||
return this._defaultLocale;
|
||||
}
|
||||
static getInstance() {
|
||||
Engine.instance = Engine.instance || new Engine();
|
||||
return Engine.instance;
|
||||
}
|
||||
static defaultEvaluator(str, _cstr) {
|
||||
return str;
|
||||
}
|
||||
static evaluateNode(node) {
|
||||
return Engine.nodeEvaluator(node);
|
||||
}
|
||||
getRate() {
|
||||
const numeric = parseInt(this.rate, 10);
|
||||
return isNaN(numeric) ? 100 : numeric;
|
||||
}
|
||||
setDynamicCstr(opt_dynamic) {
|
||||
if (this.defaultLocale) {
|
||||
Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE] = this.defaultLocale;
|
||||
}
|
||||
if (opt_dynamic) {
|
||||
const keys = Object.keys(opt_dynamic);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const feature = keys[i];
|
||||
if (Dcstr.DynamicCstr.DEFAULT_ORDER.indexOf(feature) !== -1) {
|
||||
const value = opt_dynamic[feature];
|
||||
this[feature] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
EngineConst.DOMAIN_TO_STYLES[this.domain] = this.style;
|
||||
const dynamic = [this.locale, this.modality, this.domain, this.style].join('.');
|
||||
const fallback = Dcstr.DynamicProperties.createProp([Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE]], [Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.MODALITY]], [Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.DOMAIN]], [Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.STYLE]]);
|
||||
const comparator = this.comparators[this.domain];
|
||||
const parser = this.parsers[this.domain];
|
||||
this.parser = parser ? parser : this.defaultParser;
|
||||
this.dynamicCstr = this.parser.parse(dynamic);
|
||||
this.dynamicCstr.updateProperties(fallback.getProperties());
|
||||
this.comparator = comparator
|
||||
? comparator()
|
||||
: new Dcstr.DefaultComparator(this.dynamicCstr);
|
||||
}
|
||||
constructor() {
|
||||
this.customLoader = null;
|
||||
this.parsers = {};
|
||||
this.comparator = null;
|
||||
this.mode = EngineConst.Mode.SYNC;
|
||||
this.init = true;
|
||||
this.delay = false;
|
||||
this.comparators = {};
|
||||
this.domain = 'mathspeak';
|
||||
this.style = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.STYLE];
|
||||
this._defaultLocale = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE];
|
||||
this.locale = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE];
|
||||
this.subiso = '';
|
||||
this.modality = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.MODALITY];
|
||||
this.speech = EngineConst.Speech.NONE;
|
||||
this.markup = EngineConst.Markup.NONE;
|
||||
this.mark = true;
|
||||
this.automark = false;
|
||||
this.character = true;
|
||||
this.cleanpause = true;
|
||||
this.cayleyshort = true;
|
||||
this.linebreaks = false;
|
||||
this.rate = '100';
|
||||
this.walker = 'Table';
|
||||
this.structure = false;
|
||||
this.aria = false;
|
||||
this.ruleSets = [];
|
||||
this.strict = false;
|
||||
this.isIE = false;
|
||||
this.isEdge = false;
|
||||
this.pprint = false;
|
||||
this.config = false;
|
||||
this.rules = '';
|
||||
this.prune = '';
|
||||
this.locale = this.defaultLocale;
|
||||
this.evaluator = Engine.defaultEvaluator;
|
||||
this.defaultParser = new Dcstr.DynamicCstrParser(Dcstr.DynamicCstr.DEFAULT_ORDER);
|
||||
this.parser = this.defaultParser;
|
||||
this.dynamicCstr = Dcstr.DynamicCstr.defaultCstr();
|
||||
}
|
||||
configurate(feature) {
|
||||
if (this.mode === EngineConst.Mode.HTTP && !this.config) {
|
||||
configBlocks(feature);
|
||||
this.config = true;
|
||||
}
|
||||
configFeature(feature);
|
||||
}
|
||||
setCustomLoader(fn) {
|
||||
if (fn) {
|
||||
this.customLoader = fn;
|
||||
}
|
||||
}
|
||||
}
|
||||
Engine.BINARY_FEATURES = [
|
||||
'automark',
|
||||
'mark',
|
||||
'character',
|
||||
'cleanpause',
|
||||
'strict',
|
||||
'structure',
|
||||
'aria',
|
||||
'pprint',
|
||||
'cayleyshort',
|
||||
'linebreaks'
|
||||
];
|
||||
Engine.STRING_FEATURES = [
|
||||
'markup',
|
||||
'style',
|
||||
'domain',
|
||||
'speech',
|
||||
'walker',
|
||||
'defaultLocale',
|
||||
'locale',
|
||||
'delay',
|
||||
'modality',
|
||||
'rate',
|
||||
'rules',
|
||||
'subiso',
|
||||
'prune'
|
||||
];
|
||||
Engine.nodeEvaluator = function (_node) {
|
||||
return [];
|
||||
};
|
||||
export default Engine;
|
||||
function configFeature(feature) {
|
||||
if (typeof SREfeature !== 'undefined') {
|
||||
for (const [name, feat] of Object.entries(SREfeature)) {
|
||||
feature[name] = feat;
|
||||
}
|
||||
}
|
||||
}
|
||||
function configBlocks(feature) {
|
||||
const scripts = document.documentElement.querySelectorAll('script[type="text/x-sre-config"]');
|
||||
for (let i = 0, m = scripts.length; i < m; i++) {
|
||||
let inner;
|
||||
try {
|
||||
inner = scripts[i].innerHTML;
|
||||
const config = JSON.parse(inner);
|
||||
for (const [key, val] of Object.entries(config)) {
|
||||
feature[key] = val;
|
||||
}
|
||||
}
|
||||
catch (_err) {
|
||||
Debugger.getInstance().output('Illegal configuration ', inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
export class EnginePromise {
|
||||
static get(locale = Engine.getInstance().locale) {
|
||||
return EnginePromise.promises[locale] || Promise.resolve('');
|
||||
}
|
||||
static getall() {
|
||||
return Promise.all(Object.values(EnginePromise.promises));
|
||||
}
|
||||
}
|
||||
EnginePromise.loaded = {};
|
||||
EnginePromise.promises = {};
|
||||
32
node_modules/speech-rule-engine/mjs/common/engine_const.d.ts
generated
vendored
Normal file
32
node_modules/speech-rule-engine/mjs/common/engine_const.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
export declare enum Mode {
|
||||
SYNC = "sync",
|
||||
ASYNC = "async",
|
||||
HTTP = "http"
|
||||
}
|
||||
export declare enum personalityProps {
|
||||
PITCH = "pitch",
|
||||
RATE = "rate",
|
||||
VOLUME = "volume",
|
||||
PAUSE = "pause",
|
||||
JOIN = "join",
|
||||
LAYOUT = "layout"
|
||||
}
|
||||
export declare const personalityPropList: personalityProps[];
|
||||
export declare enum Speech {
|
||||
NONE = "none",
|
||||
SHALLOW = "shallow",
|
||||
DEEP = "deep"
|
||||
}
|
||||
export declare enum Markup {
|
||||
NONE = "none",
|
||||
LAYOUT = "layout",
|
||||
COUNTING = "counting",
|
||||
PUNCTUATION = "punctuation",
|
||||
SSML = "ssml",
|
||||
ACSS = "acss",
|
||||
SABLE = "sable",
|
||||
VOICEXML = "voicexml"
|
||||
}
|
||||
export declare const DOMAIN_TO_STYLES: {
|
||||
[key: string]: string;
|
||||
};
|
||||
43
node_modules/speech-rule-engine/mjs/common/engine_const.js
generated
vendored
Normal file
43
node_modules/speech-rule-engine/mjs/common/engine_const.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
export var Mode;
|
||||
(function (Mode) {
|
||||
Mode["SYNC"] = "sync";
|
||||
Mode["ASYNC"] = "async";
|
||||
Mode["HTTP"] = "http";
|
||||
})(Mode || (Mode = {}));
|
||||
export var personalityProps;
|
||||
(function (personalityProps) {
|
||||
personalityProps["PITCH"] = "pitch";
|
||||
personalityProps["RATE"] = "rate";
|
||||
personalityProps["VOLUME"] = "volume";
|
||||
personalityProps["PAUSE"] = "pause";
|
||||
personalityProps["JOIN"] = "join";
|
||||
personalityProps["LAYOUT"] = "layout";
|
||||
})(personalityProps || (personalityProps = {}));
|
||||
export const personalityPropList = [
|
||||
personalityProps.PITCH,
|
||||
personalityProps.RATE,
|
||||
personalityProps.VOLUME,
|
||||
personalityProps.PAUSE,
|
||||
personalityProps.JOIN
|
||||
];
|
||||
export var Speech;
|
||||
(function (Speech) {
|
||||
Speech["NONE"] = "none";
|
||||
Speech["SHALLOW"] = "shallow";
|
||||
Speech["DEEP"] = "deep";
|
||||
})(Speech || (Speech = {}));
|
||||
export var Markup;
|
||||
(function (Markup) {
|
||||
Markup["NONE"] = "none";
|
||||
Markup["LAYOUT"] = "layout";
|
||||
Markup["COUNTING"] = "counting";
|
||||
Markup["PUNCTUATION"] = "punctuation";
|
||||
Markup["SSML"] = "ssml";
|
||||
Markup["ACSS"] = "acss";
|
||||
Markup["SABLE"] = "sable";
|
||||
Markup["VOICEXML"] = "voicexml";
|
||||
})(Markup || (Markup = {}));
|
||||
export const DOMAIN_TO_STYLES = {
|
||||
mathspeak: 'default',
|
||||
clearspeak: 'default'
|
||||
};
|
||||
3
node_modules/speech-rule-engine/mjs/common/engine_setup.d.ts
generated
vendored
Normal file
3
node_modules/speech-rule-engine/mjs/common/engine_setup.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export declare function setup(feature: {
|
||||
[key: string]: boolean | string;
|
||||
}): Promise<string>;
|
||||
105
node_modules/speech-rule-engine/mjs/common/engine_setup.js
generated
vendored
Normal file
105
node_modules/speech-rule-engine/mjs/common/engine_setup.js
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import * as L10n from '../l10n/l10n.js';
|
||||
import * as MathMap from '../speech_rules/math_map.js';
|
||||
import * as BrowserUtil from './browser_util.js';
|
||||
import { Debugger } from './debugger.js';
|
||||
import { Engine, EnginePromise } from './engine.js';
|
||||
import * as FileUtil from './file_util.js';
|
||||
import { SystemExternal } from './system_external.js';
|
||||
const MATHSPEAK_ONLY = ['ca', 'da', 'es'];
|
||||
const EN_RULES = [
|
||||
'chromevox',
|
||||
'clearspeak',
|
||||
'mathspeak',
|
||||
'emacspeak',
|
||||
'html'
|
||||
];
|
||||
function ensureDomain(feature) {
|
||||
if ((feature.modality && feature.modality !== 'speech') ||
|
||||
(!feature.modality && Engine.getInstance().modality !== 'speech')) {
|
||||
return;
|
||||
}
|
||||
if (!feature.domain) {
|
||||
return;
|
||||
}
|
||||
if (feature.domain === 'default') {
|
||||
feature.domain = 'mathspeak';
|
||||
return;
|
||||
}
|
||||
const locale = (feature.locale || Engine.getInstance().locale);
|
||||
const domain = feature.domain;
|
||||
if (MATHSPEAK_ONLY.indexOf(locale) !== -1) {
|
||||
if (domain !== 'mathspeak') {
|
||||
feature.domain = 'mathspeak';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (locale === 'en') {
|
||||
if (EN_RULES.indexOf(domain) === -1) {
|
||||
feature.domain = 'mathspeak';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (domain !== 'mathspeak' && domain !== 'clearspeak') {
|
||||
feature.domain = 'mathspeak';
|
||||
}
|
||||
}
|
||||
export function setup(feature) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
ensureDomain(feature);
|
||||
const engine = Engine.getInstance();
|
||||
const setIf = (feat) => {
|
||||
if (typeof feature[feat] !== 'undefined') {
|
||||
engine[feat] = !!feature[feat];
|
||||
}
|
||||
};
|
||||
const setMulti = (feat) => {
|
||||
if (typeof feature[feat] !== 'undefined') {
|
||||
engine[feat] = feature[feat];
|
||||
}
|
||||
};
|
||||
setMulti('mode');
|
||||
engine.configurate(feature);
|
||||
Engine.BINARY_FEATURES.forEach(setIf);
|
||||
Engine.STRING_FEATURES.forEach(setMulti);
|
||||
if (feature.debug) {
|
||||
Debugger.getInstance().init();
|
||||
}
|
||||
if (feature.json) {
|
||||
SystemExternal.jsonPath = FileUtil.makePath(feature.json);
|
||||
}
|
||||
if (feature.xpath) {
|
||||
SystemExternal.WGXpath = feature.xpath;
|
||||
}
|
||||
engine.setCustomLoader(feature.custom);
|
||||
setupBrowsers(engine);
|
||||
L10n.setLocale();
|
||||
engine.setDynamicCstr();
|
||||
if (engine.init) {
|
||||
EnginePromise.promises['init'] = new Promise((res, _rej) => {
|
||||
setTimeout(() => {
|
||||
res('init');
|
||||
}, 10);
|
||||
});
|
||||
engine.init = false;
|
||||
return EnginePromise.get();
|
||||
}
|
||||
if (engine.delay) {
|
||||
engine.delay = false;
|
||||
return EnginePromise.get();
|
||||
}
|
||||
return MathMap.loadLocale();
|
||||
});
|
||||
}
|
||||
function setupBrowsers(engine) {
|
||||
engine.isIE = BrowserUtil.detectIE();
|
||||
engine.isEdge = BrowserUtil.detectEdge();
|
||||
}
|
||||
80
node_modules/speech-rule-engine/mjs/common/event_util.d.ts
generated
vendored
Normal file
80
node_modules/speech-rule-engine/mjs/common/event_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
export declare enum KeyCode {
|
||||
ENTER = 13,
|
||||
ESC = 27,
|
||||
SPACE = 32,
|
||||
PAGE_UP = 33,
|
||||
PAGE_DOWN = 34,
|
||||
END = 35,
|
||||
HOME = 36,
|
||||
LEFT = 37,
|
||||
UP = 38,
|
||||
RIGHT = 39,
|
||||
DOWN = 40,
|
||||
TAB = 9,
|
||||
LESS = 188,
|
||||
GREATER = 190,
|
||||
DASH = 189,
|
||||
ZERO = 48,
|
||||
ONE = 49,
|
||||
TWO = 50,
|
||||
THREE = 51,
|
||||
FOUR = 52,
|
||||
FIVE = 53,
|
||||
SIX = 54,
|
||||
SEVEN = 55,
|
||||
EIGHT = 56,
|
||||
NINE = 57,
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
T = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90
|
||||
}
|
||||
export declare const Move: Map<number, string>;
|
||||
declare enum EventType {
|
||||
CLICK = "click",
|
||||
DBLCLICK = "dblclick",
|
||||
MOUSEDOWN = "mousedown",
|
||||
MOUSEUP = "mouseup",
|
||||
MOUSEOVER = "mouseover",
|
||||
MOUSEOUT = "mouseout",
|
||||
MOUSEMOVE = "mousemove",
|
||||
SELECTSTART = "selectstart",
|
||||
KEYPRESS = "keypress",
|
||||
KEYDOWN = "keydown",
|
||||
KEYUP = "keyup",
|
||||
TOUCHSTART = "touchstart",
|
||||
TOUCHMOVE = "touchmove",
|
||||
TOUCHEND = "touchend",
|
||||
TOUCHCANCEL = "touchcancel"
|
||||
}
|
||||
export declare class Event {
|
||||
src: Node;
|
||||
type: EventType;
|
||||
callback: EventListener;
|
||||
constructor(src: Node, type: EventType, callback: EventListener);
|
||||
add(): void;
|
||||
remove(): void;
|
||||
}
|
||||
export {};
|
||||
138
node_modules/speech-rule-engine/mjs/common/event_util.js
generated
vendored
Normal file
138
node_modules/speech-rule-engine/mjs/common/event_util.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
export var KeyCode;
|
||||
(function (KeyCode) {
|
||||
KeyCode[KeyCode["ENTER"] = 13] = "ENTER";
|
||||
KeyCode[KeyCode["ESC"] = 27] = "ESC";
|
||||
KeyCode[KeyCode["SPACE"] = 32] = "SPACE";
|
||||
KeyCode[KeyCode["PAGE_UP"] = 33] = "PAGE_UP";
|
||||
KeyCode[KeyCode["PAGE_DOWN"] = 34] = "PAGE_DOWN";
|
||||
KeyCode[KeyCode["END"] = 35] = "END";
|
||||
KeyCode[KeyCode["HOME"] = 36] = "HOME";
|
||||
KeyCode[KeyCode["LEFT"] = 37] = "LEFT";
|
||||
KeyCode[KeyCode["UP"] = 38] = "UP";
|
||||
KeyCode[KeyCode["RIGHT"] = 39] = "RIGHT";
|
||||
KeyCode[KeyCode["DOWN"] = 40] = "DOWN";
|
||||
KeyCode[KeyCode["TAB"] = 9] = "TAB";
|
||||
KeyCode[KeyCode["LESS"] = 188] = "LESS";
|
||||
KeyCode[KeyCode["GREATER"] = 190] = "GREATER";
|
||||
KeyCode[KeyCode["DASH"] = 189] = "DASH";
|
||||
KeyCode[KeyCode["ZERO"] = 48] = "ZERO";
|
||||
KeyCode[KeyCode["ONE"] = 49] = "ONE";
|
||||
KeyCode[KeyCode["TWO"] = 50] = "TWO";
|
||||
KeyCode[KeyCode["THREE"] = 51] = "THREE";
|
||||
KeyCode[KeyCode["FOUR"] = 52] = "FOUR";
|
||||
KeyCode[KeyCode["FIVE"] = 53] = "FIVE";
|
||||
KeyCode[KeyCode["SIX"] = 54] = "SIX";
|
||||
KeyCode[KeyCode["SEVEN"] = 55] = "SEVEN";
|
||||
KeyCode[KeyCode["EIGHT"] = 56] = "EIGHT";
|
||||
KeyCode[KeyCode["NINE"] = 57] = "NINE";
|
||||
KeyCode[KeyCode["A"] = 65] = "A";
|
||||
KeyCode[KeyCode["B"] = 66] = "B";
|
||||
KeyCode[KeyCode["C"] = 67] = "C";
|
||||
KeyCode[KeyCode["D"] = 68] = "D";
|
||||
KeyCode[KeyCode["E"] = 69] = "E";
|
||||
KeyCode[KeyCode["F"] = 70] = "F";
|
||||
KeyCode[KeyCode["G"] = 71] = "G";
|
||||
KeyCode[KeyCode["H"] = 72] = "H";
|
||||
KeyCode[KeyCode["I"] = 73] = "I";
|
||||
KeyCode[KeyCode["J"] = 74] = "J";
|
||||
KeyCode[KeyCode["K"] = 75] = "K";
|
||||
KeyCode[KeyCode["L"] = 76] = "L";
|
||||
KeyCode[KeyCode["M"] = 77] = "M";
|
||||
KeyCode[KeyCode["N"] = 78] = "N";
|
||||
KeyCode[KeyCode["O"] = 79] = "O";
|
||||
KeyCode[KeyCode["P"] = 80] = "P";
|
||||
KeyCode[KeyCode["Q"] = 81] = "Q";
|
||||
KeyCode[KeyCode["R"] = 82] = "R";
|
||||
KeyCode[KeyCode["S"] = 83] = "S";
|
||||
KeyCode[KeyCode["T"] = 84] = "T";
|
||||
KeyCode[KeyCode["U"] = 85] = "U";
|
||||
KeyCode[KeyCode["V"] = 86] = "V";
|
||||
KeyCode[KeyCode["W"] = 87] = "W";
|
||||
KeyCode[KeyCode["X"] = 88] = "X";
|
||||
KeyCode[KeyCode["Y"] = 89] = "Y";
|
||||
KeyCode[KeyCode["Z"] = 90] = "Z";
|
||||
})(KeyCode || (KeyCode = {}));
|
||||
export const Move = new Map([
|
||||
[13, 'ENTER'],
|
||||
[27, 'ESC'],
|
||||
[32, 'SPACE'],
|
||||
[33, 'PAGE_UP'],
|
||||
[34, 'PAGE_DOWN'],
|
||||
[35, 'END'],
|
||||
[36, 'HOME'],
|
||||
[37, 'LEFT'],
|
||||
[38, 'UP'],
|
||||
[39, 'RIGHT'],
|
||||
[40, 'DOWN'],
|
||||
[9, 'TAB'],
|
||||
[188, 'LESS'],
|
||||
[190, 'GREATER'],
|
||||
[189, 'DASH'],
|
||||
[48, 'ZERO'],
|
||||
[49, 'ONE'],
|
||||
[50, 'TWO'],
|
||||
[51, 'THREE'],
|
||||
[52, 'FOUR'],
|
||||
[53, 'FIVE'],
|
||||
[54, 'SIX'],
|
||||
[55, 'SEVEN'],
|
||||
[56, 'EIGHT'],
|
||||
[57, 'NINE'],
|
||||
[65, 'A'],
|
||||
[66, 'B'],
|
||||
[67, 'C'],
|
||||
[68, 'D'],
|
||||
[69, 'E'],
|
||||
[70, 'F'],
|
||||
[71, 'G'],
|
||||
[72, 'H'],
|
||||
[73, 'I'],
|
||||
[74, 'J'],
|
||||
[75, 'K'],
|
||||
[76, 'L'],
|
||||
[77, 'M'],
|
||||
[78, 'N'],
|
||||
[79, 'O'],
|
||||
[80, 'P'],
|
||||
[81, 'Q'],
|
||||
[82, 'R'],
|
||||
[83, 'S'],
|
||||
[84, 'T'],
|
||||
[85, 'U'],
|
||||
[86, 'V'],
|
||||
[87, 'W'],
|
||||
[88, 'X'],
|
||||
[89, 'Y'],
|
||||
[90, 'Z']
|
||||
]);
|
||||
var EventType;
|
||||
(function (EventType) {
|
||||
EventType["CLICK"] = "click";
|
||||
EventType["DBLCLICK"] = "dblclick";
|
||||
EventType["MOUSEDOWN"] = "mousedown";
|
||||
EventType["MOUSEUP"] = "mouseup";
|
||||
EventType["MOUSEOVER"] = "mouseover";
|
||||
EventType["MOUSEOUT"] = "mouseout";
|
||||
EventType["MOUSEMOVE"] = "mousemove";
|
||||
EventType["SELECTSTART"] = "selectstart";
|
||||
EventType["KEYPRESS"] = "keypress";
|
||||
EventType["KEYDOWN"] = "keydown";
|
||||
EventType["KEYUP"] = "keyup";
|
||||
EventType["TOUCHSTART"] = "touchstart";
|
||||
EventType["TOUCHMOVE"] = "touchmove";
|
||||
EventType["TOUCHEND"] = "touchend";
|
||||
EventType["TOUCHCANCEL"] = "touchcancel";
|
||||
})(EventType || (EventType = {}));
|
||||
export class Event {
|
||||
constructor(src, type, callback) {
|
||||
this.src = src;
|
||||
this.type = type;
|
||||
this.callback = callback;
|
||||
}
|
||||
add() {
|
||||
this.src.addEventListener(this.type, this.callback);
|
||||
}
|
||||
remove() {
|
||||
this.src.removeEventListener(this.type, this.callback);
|
||||
}
|
||||
}
|
||||
2
node_modules/speech-rule-engine/mjs/common/file_util.d.ts
generated
vendored
Normal file
2
node_modules/speech-rule-engine/mjs/common/file_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare function makePath(path: string): string;
|
||||
export declare function localePath(locale: string, ext?: string): string;
|
||||
9
node_modules/speech-rule-engine/mjs/common/file_util.js
generated
vendored
Normal file
9
node_modules/speech-rule-engine/mjs/common/file_util.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { SystemExternal } from './system_external.js';
|
||||
export function makePath(path) {
|
||||
return path.match('/$') ? path : path + '/';
|
||||
}
|
||||
export function localePath(locale, ext = 'json') {
|
||||
return (makePath(SystemExternal.jsonPath) +
|
||||
locale +
|
||||
(ext.match(/^\./) ? ext : '.' + ext));
|
||||
}
|
||||
1
node_modules/speech-rule-engine/mjs/common/mathjax.d.ts
generated
vendored
Normal file
1
node_modules/speech-rule-engine/mjs/common/mathjax.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
20
node_modules/speech-rule-engine/mjs/common/mathjax.js
generated
vendored
Normal file
20
node_modules/speech-rule-engine/mjs/common/mathjax.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { EnginePromise } from './engine.js';
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import * as System from './system.js';
|
||||
(function () {
|
||||
const SIGNAL = MathJax.Callback.Signal('Sre');
|
||||
MathJax.Extension.Sre = {
|
||||
version: System.version,
|
||||
signal: SIGNAL,
|
||||
ConfigSre: function () {
|
||||
EnginePromise.getall().then(() => MathJax.Callback.Queue(MathJax.Hub.Register.StartupHook('mml Jax Ready', {}), ['Post', MathJax.Hub.Startup.signal, 'Sre Ready']));
|
||||
}
|
||||
};
|
||||
System.setupEngine({
|
||||
mode: EngineConst.Mode.HTTP,
|
||||
json: MathJax.Ajax.config.path['SRE'] + '/mathmaps',
|
||||
xpath: MathJax.Ajax.config.path['SRE'] + '/wgxpath.install.js',
|
||||
semantics: true
|
||||
});
|
||||
MathJax.Extension.Sre.ConfigSre();
|
||||
})();
|
||||
34
node_modules/speech-rule-engine/mjs/common/processor.d.ts
generated
vendored
Normal file
34
node_modules/speech-rule-engine/mjs/common/processor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Highlighter } from '../highlighter/highlighter.js';
|
||||
import { SpeechGenerator } from '../speech_generator/speech_generator.js';
|
||||
import { Walker } from '../walker/walker.js';
|
||||
import { KeyCode } from './event_util.js';
|
||||
export declare class Processor<T> {
|
||||
name: string;
|
||||
static LocalState: {
|
||||
walker: Walker;
|
||||
speechGenerator: SpeechGenerator;
|
||||
highlighter: Highlighter;
|
||||
};
|
||||
process: (p1: string) => T;
|
||||
postprocess: (p1: T, p2: string) => T;
|
||||
print: (p1: T) => string;
|
||||
pprint: (p1: T) => string;
|
||||
processor: (p1: string) => T;
|
||||
private static stringify_;
|
||||
constructor(name: string, methods: {
|
||||
processor: (p1: string) => T;
|
||||
postprocessor?: (p1: T, p2: string) => T;
|
||||
print?: (p1: T) => string;
|
||||
pprint?: (p1: T) => string;
|
||||
});
|
||||
}
|
||||
export declare class KeyProcessor<T> extends Processor<T> {
|
||||
key: (p1: KeyCode | string) => KeyCode;
|
||||
private static getKey_;
|
||||
constructor(name: string, methods: {
|
||||
processor: (p1: string) => T;
|
||||
key?: (p1: KeyCode | string) => KeyCode;
|
||||
print?: (p1: T) => string;
|
||||
pprint?: (p1: T) => string;
|
||||
});
|
||||
}
|
||||
32
node_modules/speech-rule-engine/mjs/common/processor.js
generated
vendored
Normal file
32
node_modules/speech-rule-engine/mjs/common/processor.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { KeyCode } from './event_util.js';
|
||||
export class Processor {
|
||||
static stringify_(x) {
|
||||
return x ? x.toString() : x;
|
||||
}
|
||||
constructor(name, methods) {
|
||||
this.name = name;
|
||||
this.process = methods.processor;
|
||||
this.postprocess =
|
||||
methods.postprocessor || ((x, _y) => x);
|
||||
this.processor = this.postprocess
|
||||
? function (x) {
|
||||
return this.postprocess(this.process(x), x);
|
||||
}
|
||||
: this.process;
|
||||
this.print = methods.print || Processor.stringify_;
|
||||
this.pprint = methods.pprint || this.print;
|
||||
}
|
||||
}
|
||||
Processor.LocalState = { walker: null, speechGenerator: null, highlighter: null };
|
||||
export class KeyProcessor extends Processor {
|
||||
static getKey_(key) {
|
||||
return typeof key === 'string'
|
||||
?
|
||||
KeyCode[key.toUpperCase()]
|
||||
: key;
|
||||
}
|
||||
constructor(name, methods) {
|
||||
super(name, methods);
|
||||
this.key = methods.key || KeyProcessor.getKey_;
|
||||
}
|
||||
}
|
||||
4
node_modules/speech-rule-engine/mjs/common/processor_factory.d.ts
generated
vendored
Normal file
4
node_modules/speech-rule-engine/mjs/common/processor_factory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { KeyCode } from './event_util.js';
|
||||
export declare function process<T>(name: string, expr: string): T;
|
||||
export declare function output(name: string, expr: string): string;
|
||||
export declare function keypress(name: string, expr: KeyCode | string): string;
|
||||
256
node_modules/speech-rule-engine/mjs/common/processor_factory.js
generated
vendored
Normal file
256
node_modules/speech-rule-engine/mjs/common/processor_factory.js
generated
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
import * as AuralRendering from '../audio/aural_rendering.js';
|
||||
import * as Enrich from '../enrich_mathml/enrich.js';
|
||||
import * as HighlighterFactory from '../highlighter/highlighter_factory.js';
|
||||
import { LOCALE } from '../l10n/locale.js';
|
||||
import * as Semantic from '../semantic_tree/semantic.js';
|
||||
import * as SpeechGeneratorFactory from '../speech_generator/speech_generator_factory.js';
|
||||
import * as SpeechGeneratorUtil from '../speech_generator/speech_generator_util.js';
|
||||
import * as WalkerFactory from '../walker/walker_factory.js';
|
||||
import * as WalkerUtil from '../walker/walker_util.js';
|
||||
import { RebuildStree } from '../walker/rebuild_stree.js';
|
||||
import * as DomUtil from './dom_util.js';
|
||||
import { Engine, SREError } from './engine.js';
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { Processor, KeyProcessor } from './processor.js';
|
||||
import * as XpathUtil from './xpath_util.js';
|
||||
const PROCESSORS = new Map();
|
||||
function set(processor) {
|
||||
PROCESSORS.set(processor.name, processor);
|
||||
}
|
||||
function get(name) {
|
||||
const processor = PROCESSORS.get(name);
|
||||
if (!processor) {
|
||||
throw new SREError('Unknown processor ' + name);
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
export function process(name, expr) {
|
||||
const processor = get(name);
|
||||
try {
|
||||
return processor.processor(expr);
|
||||
}
|
||||
catch (_e) {
|
||||
throw new SREError('Processing error for expression ' + expr);
|
||||
}
|
||||
}
|
||||
function print(name, data) {
|
||||
const processor = get(name);
|
||||
return Engine.getInstance().pprint
|
||||
? processor.pprint(data)
|
||||
: processor.print(data);
|
||||
}
|
||||
export function output(name, expr) {
|
||||
const processor = get(name);
|
||||
try {
|
||||
const data = processor.processor(expr);
|
||||
return Engine.getInstance().pprint
|
||||
? processor.pprint(data)
|
||||
: processor.print(data);
|
||||
}
|
||||
catch (_e) {
|
||||
console.log(_e);
|
||||
throw new SREError('Processing error for expression ' + expr);
|
||||
}
|
||||
}
|
||||
export function keypress(name, expr) {
|
||||
const processor = get(name);
|
||||
const key = processor instanceof KeyProcessor ? processor.key(expr) : expr;
|
||||
const data = processor.processor(key);
|
||||
return Engine.getInstance().pprint
|
||||
? processor.pprint(data)
|
||||
: processor.print(data);
|
||||
}
|
||||
set(new Processor('semantic', {
|
||||
processor: function (expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
return Semantic.xmlTree(mml);
|
||||
},
|
||||
postprocessor: function (xml, _expr) {
|
||||
const setting = Engine.getInstance().speech;
|
||||
if (setting === EngineConst.Speech.NONE) {
|
||||
return xml;
|
||||
}
|
||||
const clone = DomUtil.cloneNode(xml);
|
||||
let speech = SpeechGeneratorUtil.computeMarkup(clone);
|
||||
if (setting === EngineConst.Speech.SHALLOW) {
|
||||
xml.setAttribute('speech', AuralRendering.finalize(speech));
|
||||
return xml;
|
||||
}
|
||||
const nodesXml = XpathUtil.evalXPath('.//*[@id]', xml);
|
||||
const nodesClone = XpathUtil.evalXPath('.//*[@id]', clone);
|
||||
for (let i = 0, orig, node; (orig = nodesXml[i]), (node = nodesClone[i]); i++) {
|
||||
speech = SpeechGeneratorUtil.computeMarkup(node);
|
||||
orig.setAttribute('speech', AuralRendering.finalize(speech));
|
||||
}
|
||||
return xml;
|
||||
},
|
||||
pprint: function (tree) {
|
||||
return DomUtil.formatXml(tree.toString());
|
||||
}
|
||||
}));
|
||||
set(new Processor('speech', {
|
||||
processor: function (expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
const xml = Semantic.xmlTree(mml);
|
||||
const descrs = SpeechGeneratorUtil.computeSpeech(xml);
|
||||
return AuralRendering.finalize(AuralRendering.markup(descrs));
|
||||
},
|
||||
pprint: function (speech) {
|
||||
const str = speech.toString();
|
||||
return AuralRendering.isXml() ? DomUtil.formatXml(str) : str;
|
||||
}
|
||||
}));
|
||||
set(new Processor('json', {
|
||||
processor: function (expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
const stree = Semantic.getTree(mml);
|
||||
return stree.toJson();
|
||||
},
|
||||
postprocessor: function (json, expr) {
|
||||
const setting = Engine.getInstance().speech;
|
||||
if (setting === EngineConst.Speech.NONE) {
|
||||
return json;
|
||||
}
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
const xml = Semantic.xmlTree(mml);
|
||||
const speech = SpeechGeneratorUtil.computeMarkup(xml);
|
||||
if (setting === EngineConst.Speech.SHALLOW) {
|
||||
json.stree.speech = AuralRendering.finalize(speech);
|
||||
return json;
|
||||
}
|
||||
const addRec = (json) => {
|
||||
const node = XpathUtil.evalXPath(`.//*[@id=${json.id}]`, xml)[0];
|
||||
const speech = SpeechGeneratorUtil.computeMarkup(node);
|
||||
json.speech = AuralRendering.finalize(speech);
|
||||
if (json.children) {
|
||||
json.children.forEach(addRec);
|
||||
}
|
||||
};
|
||||
addRec(json.stree);
|
||||
return json;
|
||||
},
|
||||
print: function (json) {
|
||||
return JSON.stringify(json);
|
||||
},
|
||||
pprint: function (json) {
|
||||
return JSON.stringify(json, null, 2);
|
||||
}
|
||||
}));
|
||||
set(new Processor('description', {
|
||||
processor: function (expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
const xml = Semantic.xmlTree(mml);
|
||||
const descrs = SpeechGeneratorUtil.computeSpeech(xml);
|
||||
return descrs;
|
||||
},
|
||||
print: function (descrs) {
|
||||
return JSON.stringify(descrs);
|
||||
},
|
||||
pprint: function (descrs) {
|
||||
return JSON.stringify(descrs, null, 2);
|
||||
}
|
||||
}));
|
||||
set(new Processor('enriched', {
|
||||
processor: function (expr) {
|
||||
return Enrich.semanticMathmlSync(expr);
|
||||
},
|
||||
postprocessor: function (enr, _expr) {
|
||||
const root = WalkerUtil.getSemanticRoot(enr);
|
||||
let generator;
|
||||
switch (Engine.getInstance().speech) {
|
||||
case EngineConst.Speech.NONE:
|
||||
break;
|
||||
case EngineConst.Speech.SHALLOW:
|
||||
generator = SpeechGeneratorFactory.generator('Adhoc');
|
||||
generator.getSpeech(root, enr);
|
||||
break;
|
||||
case EngineConst.Speech.DEEP:
|
||||
generator = SpeechGeneratorFactory.generator('Tree');
|
||||
generator.getSpeech(enr, enr);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return enr;
|
||||
},
|
||||
pprint: function (tree) {
|
||||
return DomUtil.formatXml(tree.toString());
|
||||
}
|
||||
}));
|
||||
set(new Processor('rebuild', {
|
||||
processor: function (expr) {
|
||||
const rebuilt = new RebuildStree(DomUtil.parseInput(expr));
|
||||
return rebuilt.stree.xml();
|
||||
},
|
||||
pprint: function (tree) {
|
||||
return DomUtil.formatXml(tree.toString());
|
||||
}
|
||||
}));
|
||||
set(new Processor('walker', {
|
||||
processor: function (expr) {
|
||||
const generator = SpeechGeneratorFactory.generator('Node');
|
||||
Processor.LocalState.speechGenerator = generator;
|
||||
generator.setOptions({
|
||||
modality: Engine.getInstance().modality,
|
||||
locale: Engine.getInstance().locale,
|
||||
domain: Engine.getInstance().domain,
|
||||
style: Engine.getInstance().style
|
||||
});
|
||||
Processor.LocalState.highlighter = HighlighterFactory.highlighter({ color: 'black' }, { color: 'white' }, { renderer: 'NativeMML' });
|
||||
const node = process('enriched', expr);
|
||||
const eml = print('enriched', node);
|
||||
Processor.LocalState.walker = WalkerFactory.walker(Engine.getInstance().walker, node, generator, Processor.LocalState.highlighter, eml);
|
||||
return Processor.LocalState.walker;
|
||||
},
|
||||
print: function (_walker) {
|
||||
return Processor.LocalState.walker.speech();
|
||||
}
|
||||
}));
|
||||
set(new KeyProcessor('move', {
|
||||
processor: function (direction) {
|
||||
if (!Processor.LocalState.walker) {
|
||||
return null;
|
||||
}
|
||||
const move = Processor.LocalState.walker.move(direction);
|
||||
return move === false
|
||||
? AuralRendering.error(direction)
|
||||
: Processor.LocalState.walker.speech();
|
||||
}
|
||||
}));
|
||||
set(new Processor('number', {
|
||||
processor: function (numb) {
|
||||
const num = parseInt(numb, 10);
|
||||
return isNaN(num) ? '' : LOCALE.NUMBERS.numberToWords(num);
|
||||
}
|
||||
}));
|
||||
set(new Processor('ordinal', {
|
||||
processor: function (numb) {
|
||||
const num = parseInt(numb, 10);
|
||||
return isNaN(num) ? '' : LOCALE.NUMBERS.wordOrdinal(num);
|
||||
}
|
||||
}));
|
||||
set(new Processor('numericOrdinal', {
|
||||
processor: function (numb) {
|
||||
const num = parseInt(numb, 10);
|
||||
return isNaN(num) ? '' : LOCALE.NUMBERS.numericOrdinal(num);
|
||||
}
|
||||
}));
|
||||
set(new Processor('vulgar', {
|
||||
processor: function (numb) {
|
||||
const [en, den] = numb.split('/').map((x) => parseInt(x, 10));
|
||||
return isNaN(en) || isNaN(den)
|
||||
? ''
|
||||
: process('speech', `<mfrac><mn>${en}</mn><mn>${den}</mn></mfrac>`);
|
||||
}
|
||||
}));
|
||||
set(new Processor('latex', {
|
||||
processor: function (ltx) {
|
||||
if (Engine.getInstance().modality !== 'braille' ||
|
||||
Engine.getInstance().locale !== 'euro') {
|
||||
console.info('LaTeX input currently only works for Euro Braille output.' +
|
||||
' Please use the latex-to-speech package from npm for general' +
|
||||
' LaTeX input to SRE.');
|
||||
}
|
||||
return process('speech', `<math data-latex="${ltx}"></math>`);
|
||||
}
|
||||
}));
|
||||
28
node_modules/speech-rule-engine/mjs/common/system.d.ts
generated
vendored
Normal file
28
node_modules/speech-rule-engine/mjs/common/system.d.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { AuditoryDescription } from '../audio/auditory_description.js';
|
||||
import { KeyCode } from './event_util.js';
|
||||
import * as FileUtil from './file_util.js';
|
||||
import { standardLoader } from '../speech_rules/math_map.js';
|
||||
export declare const version: string;
|
||||
export declare function setupEngine(feature: {
|
||||
[key: string]: boolean | string;
|
||||
}): Promise<string>;
|
||||
export declare function engineSetup(): {
|
||||
[key: string]: boolean | string;
|
||||
};
|
||||
export declare function engineReady(): Promise<any>;
|
||||
export declare const localeLoader: typeof standardLoader;
|
||||
export declare function toSpeech(expr: string): string;
|
||||
export declare function toSemantic(expr: string): Node;
|
||||
export declare function toJson(expr: string): any;
|
||||
export declare function toDescription(expr: string): AuditoryDescription[];
|
||||
export declare function toEnriched(expr: string): Element;
|
||||
export declare function number(expr: string): string;
|
||||
export declare function ordinal(expr: string): string;
|
||||
export declare function numericOrdinal(expr: string): string;
|
||||
export declare function vulgar(expr: string): string;
|
||||
export declare const file: Record<string, (input: string, output?: string) => any>;
|
||||
export declare function processFile(processor: string, input: string, opt_output?: string): string | Promise<string>;
|
||||
export declare function walk(expr: string): string;
|
||||
export declare function move(direction: KeyCode | string): string | null;
|
||||
export declare function exit(opt_value?: number): void;
|
||||
export declare const localePath: typeof FileUtil.localePath;
|
||||
154
node_modules/speech-rule-engine/mjs/common/system.js
generated
vendored
Normal file
154
node_modules/speech-rule-engine/mjs/common/system.js
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { Engine, EnginePromise, SREError } from './engine.js';
|
||||
import { setup } from './engine_setup.js';
|
||||
import * as EngineConst from './engine_const.js';
|
||||
import * as FileUtil from './file_util.js';
|
||||
import * as ProcessorFactory from './processor_factory.js';
|
||||
import { SystemExternal } from './system_external.js';
|
||||
import { Variables } from './variables.js';
|
||||
import { standardLoader } from '../speech_rules/math_map.js';
|
||||
export const version = Variables.VERSION;
|
||||
export function setupEngine(feature) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return setup(feature);
|
||||
});
|
||||
}
|
||||
export function engineSetup() {
|
||||
const engineFeatures = ['mode'].concat(Engine.STRING_FEATURES, Engine.BINARY_FEATURES);
|
||||
const engine = Engine.getInstance();
|
||||
const features = {};
|
||||
engineFeatures.forEach(function (x) {
|
||||
features[x] = engine[x];
|
||||
});
|
||||
features.json = SystemExternal.jsonPath;
|
||||
features.xpath = SystemExternal.WGXpath;
|
||||
features.rules = engine.ruleSets.slice();
|
||||
return features;
|
||||
}
|
||||
export function engineReady() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return setupEngine({}).then(() => EnginePromise.getall());
|
||||
});
|
||||
}
|
||||
export const localeLoader = standardLoader;
|
||||
export function toSpeech(expr) {
|
||||
return processString('speech', expr);
|
||||
}
|
||||
export function toSemantic(expr) {
|
||||
return processString('semantic', expr);
|
||||
}
|
||||
export function toJson(expr) {
|
||||
return processString('json', expr);
|
||||
}
|
||||
export function toDescription(expr) {
|
||||
return processString('description', expr);
|
||||
}
|
||||
export function toEnriched(expr) {
|
||||
return processString('enriched', expr);
|
||||
}
|
||||
export function number(expr) {
|
||||
return processString('number', expr);
|
||||
}
|
||||
export function ordinal(expr) {
|
||||
return processString('ordinal', expr);
|
||||
}
|
||||
export function numericOrdinal(expr) {
|
||||
return processString('numericOrdinal', expr);
|
||||
}
|
||||
export function vulgar(expr) {
|
||||
return processString('vulgar', expr);
|
||||
}
|
||||
function processString(processor, input) {
|
||||
return ProcessorFactory.process(processor, input);
|
||||
}
|
||||
export const file = {};
|
||||
file.toSpeech = function (input, opt_output) {
|
||||
return processFile('speech', input, opt_output);
|
||||
};
|
||||
file.toSemantic = function (input, opt_output) {
|
||||
return processFile('semantic', input, opt_output);
|
||||
};
|
||||
file.toJson = function (input, opt_output) {
|
||||
return processFile('json', input, opt_output);
|
||||
};
|
||||
file.toDescription = function (input, opt_output) {
|
||||
return processFile('description', input, opt_output);
|
||||
};
|
||||
file.toEnriched = function (input, opt_output) {
|
||||
return processFile('enriched', input, opt_output);
|
||||
};
|
||||
export function processFile(processor, input, opt_output) {
|
||||
switch (Engine.getInstance().mode) {
|
||||
case EngineConst.Mode.ASYNC:
|
||||
return processFileAsync(processor, input, opt_output);
|
||||
case EngineConst.Mode.SYNC:
|
||||
return processFileSync(processor, input, opt_output);
|
||||
default:
|
||||
throw new SREError(`Can process files in ${Engine.getInstance().mode} mode`);
|
||||
}
|
||||
}
|
||||
function processFileSync(processor, input, opt_output) {
|
||||
const expr = inputFileSync_(input);
|
||||
const result = ProcessorFactory.output(processor, expr);
|
||||
if (opt_output) {
|
||||
try {
|
||||
SystemExternal.fs.writeFileSync(opt_output, result);
|
||||
}
|
||||
catch (_err) {
|
||||
throw new SREError('Can not write to file: ' + opt_output);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function inputFileSync_(file) {
|
||||
let expr;
|
||||
try {
|
||||
expr = SystemExternal.fs.readFileSync(file, { encoding: 'utf8' });
|
||||
}
|
||||
catch (_err) {
|
||||
throw new SREError('Can not open file: ' + file);
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
function processFileAsync(processor, file, output) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const expr = yield SystemExternal.fs.promises.readFile(file, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
const result = ProcessorFactory.output(processor, expr);
|
||||
if (output) {
|
||||
try {
|
||||
SystemExternal.fs.promises.writeFile(output, result);
|
||||
}
|
||||
catch (_err) {
|
||||
throw new SREError('Can not write to file: ' + output);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
export function walk(expr) {
|
||||
return ProcessorFactory.output('walker', expr);
|
||||
}
|
||||
export function move(direction) {
|
||||
return ProcessorFactory.keypress('move', direction);
|
||||
}
|
||||
export function exit(opt_value) {
|
||||
const value = opt_value || 0;
|
||||
EnginePromise.getall().then(() => process.exit(value));
|
||||
}
|
||||
export const localePath = FileUtil.localePath;
|
||||
if (SystemExternal.documentSupported) {
|
||||
setupEngine({ mode: EngineConst.Mode.HTTP }).then(() => setupEngine({}));
|
||||
}
|
||||
else {
|
||||
setupEngine({ mode: EngineConst.Mode.SYNC }).then(() => setupEngine({ mode: EngineConst.Mode.ASYNC }));
|
||||
}
|
||||
16
node_modules/speech-rule-engine/mjs/common/system_external.d.ts
generated
vendored
Normal file
16
node_modules/speech-rule-engine/mjs/common/system_external.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
export declare class SystemExternal {
|
||||
static nodeRequire(): any;
|
||||
static extRequire(library: string): any;
|
||||
static windowSupported: boolean;
|
||||
static documentSupported: boolean;
|
||||
static xmldom: any;
|
||||
static document: Document;
|
||||
static xpath: any;
|
||||
static mathmapsIePath: string;
|
||||
static fs: any;
|
||||
static url: string;
|
||||
static jsonPath: any;
|
||||
static WGXpath: string;
|
||||
static wgxpath: any;
|
||||
}
|
||||
export default SystemExternal;
|
||||
63
node_modules/speech-rule-engine/mjs/common/system_external.js
generated
vendored
Normal file
63
node_modules/speech-rule-engine/mjs/common/system_external.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Variables } from './variables.js';
|
||||
export class SystemExternal {
|
||||
static nodeRequire() {
|
||||
return eval('require');
|
||||
}
|
||||
static extRequire(library) {
|
||||
if (typeof process !== 'undefined' && typeof require !== 'undefined') {
|
||||
return SystemExternal.nodeRequire()(library);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
SystemExternal.windowSupported = (() => !(typeof window === 'undefined'))();
|
||||
SystemExternal.documentSupported = (() => SystemExternal.windowSupported &&
|
||||
!(typeof window.document === 'undefined'))();
|
||||
SystemExternal.xmldom = SystemExternal.documentSupported
|
||||
? window
|
||||
: SystemExternal.extRequire('@xmldom/xmldom');
|
||||
SystemExternal.document = SystemExternal.documentSupported
|
||||
? window.document
|
||||
: new SystemExternal.xmldom.DOMImplementation().createDocument('', '', 0);
|
||||
SystemExternal.xpath = SystemExternal.documentSupported
|
||||
? document
|
||||
: (function () {
|
||||
const window = { document: {}, XPathResult: {} };
|
||||
const wgx = SystemExternal.extRequire('wicked-good-xpath');
|
||||
wgx.install(window);
|
||||
window.document.XPathResult = window.XPathResult;
|
||||
return window.document;
|
||||
})();
|
||||
SystemExternal.mathmapsIePath = 'https://cdn.jsdelivr.net/npm/sre-mathmaps-ie@' +
|
||||
Variables.VERSION +
|
||||
'mathmaps_ie.js';
|
||||
SystemExternal.fs = SystemExternal.documentSupported
|
||||
? null
|
||||
: SystemExternal.extRequire('fs');
|
||||
SystemExternal.url = Variables.url;
|
||||
SystemExternal.jsonPath = (function () {
|
||||
if (SystemExternal.documentSupported) {
|
||||
return SystemExternal.url;
|
||||
}
|
||||
if (process.env.SRE_JSON_PATH || global.SRE_JSON_PATH) {
|
||||
return process.env.SRE_JSON_PATH || global.SRE_JSON_PATH;
|
||||
}
|
||||
try {
|
||||
const path = SystemExternal.nodeRequire().resolve('speech-rule-engine');
|
||||
return path.replace(/sre\.js$/, '') + 'mathmaps';
|
||||
}
|
||||
catch (_err) {
|
||||
}
|
||||
try {
|
||||
const path = SystemExternal.nodeRequire().resolve('.');
|
||||
return path.replace(/sre\.js$/, '') + 'mathmaps';
|
||||
}
|
||||
catch (_err) {
|
||||
}
|
||||
return typeof __dirname !== 'undefined'
|
||||
? __dirname + (__dirname.match(/lib?$/) ? '/mathmaps' : '/lib/mathmaps')
|
||||
: process.cwd() + '/lib/mathmaps';
|
||||
})();
|
||||
SystemExternal.WGXpath = Variables.WGXpath;
|
||||
SystemExternal.wgxpath = null;
|
||||
export default SystemExternal;
|
||||
8
node_modules/speech-rule-engine/mjs/common/variables.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/mjs/common/variables.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export declare class Variables {
|
||||
static readonly VERSION: string;
|
||||
static readonly LOCALES: Map<string, string>;
|
||||
static ensureLocale(loc: string, def: string): string;
|
||||
static readonly mathjaxVersion: string;
|
||||
static readonly url: string;
|
||||
static readonly WGXpath: string;
|
||||
}
|
||||
33
node_modules/speech-rule-engine/mjs/common/variables.js
generated
vendored
Normal file
33
node_modules/speech-rule-engine/mjs/common/variables.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
export class Variables {
|
||||
static ensureLocale(loc, def) {
|
||||
if (!Variables.LOCALES.get(loc)) {
|
||||
console.error(`Locale ${loc} does not exist! Using` +
|
||||
` ${Variables.LOCALES.get(def)} instead.`);
|
||||
return def;
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
Variables.VERSION = '4.1.2';
|
||||
Variables.LOCALES = new Map([
|
||||
['af', 'Africaans'],
|
||||
['ca', 'Catalan'],
|
||||
['da', 'Danish'],
|
||||
['de', 'German'],
|
||||
['en', 'English'],
|
||||
['es', 'Spanish'],
|
||||
['euro', 'Euro'],
|
||||
['fr', 'French'],
|
||||
['hi', 'Hindi'],
|
||||
['it', 'Italian'],
|
||||
['ko', 'Korean'],
|
||||
['nb', 'Bokmål'],
|
||||
['nn', 'Nynorsk'],
|
||||
['sv', 'Swedish'],
|
||||
['nemeth', 'Nemeth']
|
||||
]);
|
||||
Variables.mathjaxVersion = '4.0.0-beta.5';
|
||||
Variables.url = 'https://cdn.jsdelivr.net/npm/speech-rule-engine@' +
|
||||
Variables.VERSION +
|
||||
'/lib/mathmaps';
|
||||
Variables.WGXpath = 'https://cdn.jsdelivr.net/npm/wicked-good-xpath@1.3.0/dist/wgxpath.install.js';
|
||||
16
node_modules/speech-rule-engine/mjs/common/xpath_util.d.ts
generated
vendored
Normal file
16
node_modules/speech-rule-engine/mjs/common/xpath_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
export declare const xpath: {
|
||||
currentDocument: Document;
|
||||
evaluate: (x: string, node: Element, nsr: Resolver, rt: number, result: XPathResult) => XPathResult;
|
||||
result: any;
|
||||
createNSResolver: (nodeResolver: Element) => XPathNSResolver;
|
||||
};
|
||||
export declare function resolveNameSpace(prefix: string): string;
|
||||
declare class Resolver {
|
||||
lookupNamespaceURI: any;
|
||||
constructor();
|
||||
}
|
||||
export declare function evalXPath(expression: string, rootNode: Element): Element[];
|
||||
export declare function evaluateBoolean(expression: string, rootNode: Element): boolean;
|
||||
export declare function evaluateString(expression: string, rootNode: Element): string;
|
||||
export declare function updateEvaluator(node: Element): void;
|
||||
export {};
|
||||
88
node_modules/speech-rule-engine/mjs/common/xpath_util.js
generated
vendored
Normal file
88
node_modules/speech-rule-engine/mjs/common/xpath_util.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
import { Engine } from './engine.js';
|
||||
import * as EngineConst from '../common/engine_const.js';
|
||||
import { SystemExternal } from './system_external.js';
|
||||
function xpathSupported() {
|
||||
if (typeof XPathResult === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
export const xpath = {
|
||||
currentDocument: null,
|
||||
evaluate: xpathSupported()
|
||||
? document.evaluate
|
||||
: SystemExternal.xpath.evaluate,
|
||||
result: xpathSupported() ? XPathResult : SystemExternal.xpath.XPathResult,
|
||||
createNSResolver: xpathSupported()
|
||||
? document.createNSResolver
|
||||
: SystemExternal.xpath.createNSResolver
|
||||
};
|
||||
const nameSpaces = {
|
||||
xhtml: 'http://www.w3.org/1999/xhtml',
|
||||
mathml: 'http://www.w3.org/1998/Math/MathML',
|
||||
mml: 'http://www.w3.org/1998/Math/MathML',
|
||||
svg: 'http://www.w3.org/2000/svg'
|
||||
};
|
||||
export function resolveNameSpace(prefix) {
|
||||
return nameSpaces[prefix] || null;
|
||||
}
|
||||
class Resolver {
|
||||
constructor() {
|
||||
this.lookupNamespaceURI = resolveNameSpace;
|
||||
}
|
||||
}
|
||||
function evaluateXpath(expression, rootNode, type) {
|
||||
return Engine.getInstance().mode === EngineConst.Mode.HTTP &&
|
||||
!Engine.getInstance().isIE &&
|
||||
!Engine.getInstance().isEdge
|
||||
? xpath.currentDocument.evaluate(expression, rootNode, resolveNameSpace, type, null)
|
||||
: xpath.evaluate(expression, rootNode, new Resolver(), type, null);
|
||||
}
|
||||
export function evalXPath(expression, rootNode) {
|
||||
let iterator;
|
||||
try {
|
||||
iterator = evaluateXpath(expression, rootNode, xpath.result.ORDERED_NODE_ITERATOR_TYPE);
|
||||
}
|
||||
catch (_err) {
|
||||
return [];
|
||||
}
|
||||
const results = [];
|
||||
for (let xpathNode = iterator.iterateNext(); xpathNode; xpathNode = iterator.iterateNext()) {
|
||||
results.push(xpathNode);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
export function evaluateBoolean(expression, rootNode) {
|
||||
let result;
|
||||
try {
|
||||
result = evaluateXpath(expression, rootNode, xpath.result.BOOLEAN_TYPE);
|
||||
}
|
||||
catch (_err) {
|
||||
return false;
|
||||
}
|
||||
return result.booleanValue;
|
||||
}
|
||||
export function evaluateString(expression, rootNode) {
|
||||
let result;
|
||||
try {
|
||||
result = evaluateXpath(expression, rootNode, xpath.result.STRING_TYPE);
|
||||
}
|
||||
catch (_err) {
|
||||
return '';
|
||||
}
|
||||
return result.stringValue;
|
||||
}
|
||||
export function updateEvaluator(node) {
|
||||
if (Engine.getInstance().mode !== EngineConst.Mode.HTTP)
|
||||
return;
|
||||
let parent = node;
|
||||
while (parent && !parent.evaluate) {
|
||||
parent = parent.parentNode;
|
||||
}
|
||||
if (parent && parent.evaluate) {
|
||||
xpath.currentDocument = parent;
|
||||
}
|
||||
else if (node.ownerDocument) {
|
||||
xpath.currentDocument = node.ownerDocument;
|
||||
}
|
||||
}
|
||||
7
node_modules/speech-rule-engine/mjs/enrich_mathml/abstract_enrich_case.d.ts
generated
vendored
Normal file
7
node_modules/speech-rule-engine/mjs/enrich_mathml/abstract_enrich_case.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { EnrichCase } from './enrich_case.js';
|
||||
export declare abstract class AbstractEnrichCase implements EnrichCase {
|
||||
semantic: SemanticNode;
|
||||
abstract getMathml(): Element;
|
||||
constructor(semantic: SemanticNode);
|
||||
}
|
||||
5
node_modules/speech-rule-engine/mjs/enrich_mathml/abstract_enrich_case.js
generated
vendored
Normal file
5
node_modules/speech-rule-engine/mjs/enrich_mathml/abstract_enrich_case.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export class AbstractEnrichCase {
|
||||
constructor(semantic) {
|
||||
this.semantic = semantic;
|
||||
}
|
||||
}
|
||||
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_binomial.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_binomial.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseBinomial extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
31
node_modules/speech-rule-engine/mjs/enrich_mathml/case_binomial.js
generated
vendored
Normal file
31
node_modules/speech-rule-engine/mjs/enrich_mathml/case_binomial.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import { walkTree } from './enrich_mathml.js';
|
||||
import { addMrow, setAttributes, Attribute } from './enrich_attr.js';
|
||||
export class CaseBinomial extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return (!semantic.mathmlTree &&
|
||||
semantic.type === SemanticType.LINE &&
|
||||
semantic.role === SemanticRole.BINOMIAL);
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
getMathml() {
|
||||
if (!this.semantic.childNodes.length) {
|
||||
return this.mml;
|
||||
}
|
||||
const child = this.semantic.childNodes[0];
|
||||
this.mml = walkTree(child);
|
||||
if (this.mml.hasAttribute(Attribute.TYPE)) {
|
||||
const mrow = addMrow();
|
||||
DomUtil.replaceNode(this.mml, mrow);
|
||||
mrow.appendChild(this.mml);
|
||||
this.mml = mrow;
|
||||
}
|
||||
setAttributes(this.mml, this.semantic);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_double_script.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_double_script.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseDoubleScript extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
40
node_modules/speech-rule-engine/mjs/enrich_mathml/case_double_script.js
generated
vendored
Normal file
40
node_modules/speech-rule-engine/mjs/enrich_mathml/case_double_script.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { SemanticRole } from '../semantic_tree/semantic_meaning.js';
|
||||
import { MMLTAGS } from '../semantic_tree/semantic_util.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { makeIdList, setAttributes, Attribute } from './enrich_attr.js';
|
||||
export class CaseDoubleScript extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
if (!semantic.mathmlTree || !semantic.childNodes.length) {
|
||||
return false;
|
||||
}
|
||||
const mmlTag = DomUtil.tagName(semantic.mathmlTree);
|
||||
const role = semantic.childNodes[0].role;
|
||||
return ((mmlTag === MMLTAGS.MSUBSUP && role === SemanticRole.SUBSUP) ||
|
||||
(mmlTag === MMLTAGS.MUNDEROVER && role === SemanticRole.UNDEROVER));
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
getMathml() {
|
||||
const ignore = this.semantic.childNodes[0];
|
||||
const baseSem = ignore.childNodes[0];
|
||||
const supSem = this.semantic.childNodes[1];
|
||||
const subSem = ignore.childNodes[1];
|
||||
const supMml = EnrichMathml.walkTree(supSem);
|
||||
const baseMml = EnrichMathml.walkTree(baseSem);
|
||||
const subMml = EnrichMathml.walkTree(subSem);
|
||||
setAttributes(this.mml, this.semantic);
|
||||
this.mml.setAttribute(Attribute.CHILDREN, makeIdList([baseSem, subSem, supSem]));
|
||||
[baseMml, subMml, supMml].forEach((child) => EnrichMathml.getInnerNode(child).setAttribute(Attribute.PARENT, this.mml.getAttribute(Attribute.ID)));
|
||||
this.mml.setAttribute(Attribute.TYPE, ignore.role);
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, [
|
||||
this.semantic.id,
|
||||
[ignore.id, baseSem.id, subSem.id],
|
||||
supSem.id
|
||||
]);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
32
node_modules/speech-rule-engine/mjs/enrich_mathml/case_embellished.d.ts
generated
vendored
Normal file
32
node_modules/speech-rule-engine/mjs/enrich_mathml/case_embellished.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseEmbellished extends AbstractEnrichCase {
|
||||
fenced: SemanticNode;
|
||||
fencedMml: Element;
|
||||
fencedMmlNodes: Element[];
|
||||
ofence: SemanticNode;
|
||||
ofenceMml: Element;
|
||||
ofenceMap: {
|
||||
[key: number]: Element;
|
||||
};
|
||||
cfence: SemanticNode;
|
||||
cfenceMml: Element;
|
||||
cfenceMap: {
|
||||
[key: number]: Element;
|
||||
};
|
||||
parentCleanup: Element[];
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
private static makeEmptyNode_;
|
||||
private static fencedMap_;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
private fencedElement;
|
||||
private getFenced_;
|
||||
private getFencedMml_;
|
||||
private getFencesMml_;
|
||||
private rewrite_;
|
||||
private specialCase_;
|
||||
private introduceNewLayer_;
|
||||
private fullFence;
|
||||
private cleanupParents_;
|
||||
}
|
||||
211
node_modules/speech-rule-engine/mjs/enrich_mathml/case_embellished.js
generated
vendored
Normal file
211
node_modules/speech-rule-engine/mjs/enrich_mathml/case_embellished.js
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { MMLTAGS } from '../semantic_tree/semantic_util.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import { CaseDoubleScript } from './case_double_script.js';
|
||||
import { CaseMultiscripts } from './case_multiscripts.js';
|
||||
import { CaseTensor } from './case_tensor.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { addMrow, setAttributes, Attribute } from './enrich_attr.js';
|
||||
export class CaseEmbellished extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return !!(semantic.mathmlTree &&
|
||||
semantic.fencePointer &&
|
||||
!semantic.mathmlTree.getAttribute('data-semantic-type'));
|
||||
}
|
||||
static makeEmptyNode_(id) {
|
||||
const mrow = addMrow();
|
||||
const empty = new SemanticNode(id);
|
||||
empty.type = SemanticType.EMPTY;
|
||||
empty.mathmlTree = mrow;
|
||||
return empty;
|
||||
}
|
||||
static fencedMap_(fence, ids) {
|
||||
ids[fence.id] = fence.mathmlTree;
|
||||
if (!fence.embellished) {
|
||||
return;
|
||||
}
|
||||
CaseEmbellished.fencedMap_(fence.childNodes[0], ids);
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.fenced = null;
|
||||
this.fencedMml = null;
|
||||
this.fencedMmlNodes = [];
|
||||
this.ofence = null;
|
||||
this.ofenceMml = null;
|
||||
this.ofenceMap = {};
|
||||
this.cfence = null;
|
||||
this.cfenceMml = null;
|
||||
this.cfenceMap = {};
|
||||
this.parentCleanup = [];
|
||||
}
|
||||
getMathml() {
|
||||
this.getFenced_();
|
||||
this.fencedMml = EnrichMathml.walkTree(this.fenced);
|
||||
this.getFencesMml_();
|
||||
if (this.fenced.type === SemanticType.EMPTY && !this.fencedMml.parentNode) {
|
||||
this.fencedMml.setAttribute(Attribute.ADDED, 'true');
|
||||
this.cfenceMml.parentNode.insertBefore(this.fencedMml, this.cfenceMml);
|
||||
}
|
||||
this.getFencedMml_();
|
||||
const rewrite = this.rewrite_();
|
||||
return rewrite;
|
||||
}
|
||||
fencedElement(node) {
|
||||
return (node.type === SemanticType.FENCED ||
|
||||
node.type === SemanticType.MATRIX ||
|
||||
node.type === SemanticType.VECTOR);
|
||||
}
|
||||
getFenced_() {
|
||||
let currentNode = this.semantic;
|
||||
while (!this.fencedElement(currentNode)) {
|
||||
currentNode = currentNode.childNodes[0];
|
||||
}
|
||||
this.fenced = currentNode.childNodes[0];
|
||||
this.ofence = currentNode.contentNodes[0];
|
||||
this.cfence = currentNode.contentNodes[1];
|
||||
CaseEmbellished.fencedMap_(this.ofence, this.ofenceMap);
|
||||
CaseEmbellished.fencedMap_(this.cfence, this.cfenceMap);
|
||||
}
|
||||
getFencedMml_() {
|
||||
let sibling = this.ofenceMml.nextSibling;
|
||||
sibling = sibling === this.fencedMml ? sibling : this.fencedMml;
|
||||
while (sibling && sibling !== this.cfenceMml) {
|
||||
this.fencedMmlNodes.push(sibling);
|
||||
sibling = sibling.nextSibling;
|
||||
}
|
||||
}
|
||||
getFencesMml_() {
|
||||
let currentNode = this.semantic;
|
||||
const ofenceIds = Object.keys(this.ofenceMap);
|
||||
const cfenceIds = Object.keys(this.cfenceMap);
|
||||
while ((!this.ofenceMml || !this.cfenceMml) &&
|
||||
currentNode !== this.fenced) {
|
||||
if (ofenceIds.indexOf(currentNode.fencePointer) !== -1 &&
|
||||
!this.ofenceMml) {
|
||||
this.ofenceMml = currentNode.mathmlTree;
|
||||
}
|
||||
if (cfenceIds.indexOf(currentNode.fencePointer) !== -1 &&
|
||||
!this.cfenceMml) {
|
||||
this.cfenceMml = currentNode.mathmlTree;
|
||||
}
|
||||
currentNode = currentNode.childNodes[0];
|
||||
}
|
||||
if (!this.ofenceMml) {
|
||||
this.ofenceMml = this.ofence.mathmlTree;
|
||||
}
|
||||
if (!this.cfenceMml) {
|
||||
this.cfenceMml = this.cfence.mathmlTree;
|
||||
}
|
||||
if (this.ofenceMml) {
|
||||
this.ofenceMml = EnrichMathml.ascendNewNode(this.ofenceMml);
|
||||
}
|
||||
if (this.cfenceMml) {
|
||||
this.cfenceMml = EnrichMathml.ascendNewNode(this.cfenceMml);
|
||||
}
|
||||
}
|
||||
rewrite_() {
|
||||
let currentNode = this.semantic;
|
||||
let result = null;
|
||||
const newNode = this.introduceNewLayer_();
|
||||
setAttributes(newNode, this.fenced.parent);
|
||||
while (!this.fencedElement(currentNode)) {
|
||||
const mml = currentNode.mathmlTree;
|
||||
const specialCase = this.specialCase_(currentNode, mml);
|
||||
if (specialCase) {
|
||||
currentNode = specialCase;
|
||||
}
|
||||
else {
|
||||
setAttributes(mml, currentNode);
|
||||
const mmlChildren = [];
|
||||
for (let i = 1, child; (child = currentNode.childNodes[i]); i++) {
|
||||
mmlChildren.push(EnrichMathml.walkTree(child));
|
||||
}
|
||||
currentNode = currentNode.childNodes[0];
|
||||
}
|
||||
const dummy = DomUtil.createElement('dummy');
|
||||
const saveChild = mml.childNodes[0];
|
||||
DomUtil.replaceNode(mml, dummy);
|
||||
DomUtil.replaceNode(newNode, mml);
|
||||
DomUtil.replaceNode(mml.childNodes[0], newNode);
|
||||
DomUtil.replaceNode(dummy, saveChild);
|
||||
if (!result) {
|
||||
result = mml;
|
||||
}
|
||||
}
|
||||
EnrichMathml.walkTree(this.ofence);
|
||||
EnrichMathml.walkTree(this.cfence);
|
||||
this.cleanupParents_();
|
||||
return result || newNode;
|
||||
}
|
||||
specialCase_(semantic, mml) {
|
||||
const mmlTag = DomUtil.tagName(mml);
|
||||
let parent = null;
|
||||
let caller;
|
||||
if (mmlTag === MMLTAGS.MSUBSUP) {
|
||||
parent = semantic.childNodes[0];
|
||||
caller = CaseDoubleScript;
|
||||
}
|
||||
else if (mmlTag === MMLTAGS.MMULTISCRIPTS) {
|
||||
if (semantic.type === SemanticType.SUPERSCRIPT ||
|
||||
semantic.type === SemanticType.SUBSCRIPT) {
|
||||
caller = CaseMultiscripts;
|
||||
}
|
||||
else if (semantic.type === SemanticType.TENSOR) {
|
||||
caller = CaseTensor;
|
||||
}
|
||||
if (caller &&
|
||||
semantic.childNodes[0] &&
|
||||
semantic.childNodes[0].role === SemanticRole.SUBSUP) {
|
||||
parent = semantic.childNodes[0];
|
||||
}
|
||||
else {
|
||||
parent = semantic;
|
||||
}
|
||||
}
|
||||
if (!parent) {
|
||||
return null;
|
||||
}
|
||||
const base = parent.childNodes[0];
|
||||
const empty = CaseEmbellished.makeEmptyNode_(base.id);
|
||||
parent.childNodes[0] = empty;
|
||||
mml = new caller(semantic).getMathml();
|
||||
parent.childNodes[0] = base;
|
||||
this.parentCleanup.push(mml);
|
||||
return parent.childNodes[0];
|
||||
}
|
||||
introduceNewLayer_() {
|
||||
const fullOfence = this.fullFence(this.ofenceMml);
|
||||
const fullCfence = this.fullFence(this.cfenceMml);
|
||||
let newNode = addMrow();
|
||||
DomUtil.replaceNode(this.fencedMml, newNode);
|
||||
this.fencedMmlNodes.forEach((node) => newNode.appendChild(node));
|
||||
newNode.insertBefore(fullOfence, this.fencedMml);
|
||||
newNode.appendChild(fullCfence);
|
||||
if (!newNode.parentNode) {
|
||||
const mrow = addMrow();
|
||||
while (newNode.childNodes.length > 0) {
|
||||
mrow.appendChild(newNode.childNodes[0]);
|
||||
}
|
||||
newNode.appendChild(mrow);
|
||||
newNode = mrow;
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
fullFence(fence) {
|
||||
const parent = this.fencedMml.parentNode;
|
||||
let currentFence = fence;
|
||||
while (currentFence.parentNode && currentFence.parentNode !== parent) {
|
||||
currentFence = currentFence.parentNode;
|
||||
}
|
||||
return currentFence;
|
||||
}
|
||||
cleanupParents_() {
|
||||
this.parentCleanup.forEach(function (x) {
|
||||
const parent = x.childNodes[1].getAttribute(Attribute.PARENT);
|
||||
x.childNodes[0].setAttribute(Attribute.PARENT, parent);
|
||||
});
|
||||
}
|
||||
}
|
||||
11
node_modules/speech-rule-engine/mjs/enrich_mathml/case_empheq.d.ts
generated
vendored
Normal file
11
node_modules/speech-rule-engine/mjs/enrich_mathml/case_empheq.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseEmpheq extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
private mrows;
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
private recurseToTable;
|
||||
private finalizeTable;
|
||||
}
|
||||
79
node_modules/speech-rule-engine/mjs/enrich_mathml/case_empheq.js
generated
vendored
Normal file
79
node_modules/speech-rule-engine/mjs/enrich_mathml/case_empheq.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
import { MMLTAGS } from '../semantic_tree/semantic_util.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { addMrow, setAttributes } from './enrich_attr.js';
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
export class CaseEmpheq extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return !!semantic.mathmlTree && semantic.hasAnnotation('Emph', 'top');
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.mrows = [];
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
getMathml() {
|
||||
this.recurseToTable(this.semantic);
|
||||
if (this.mrows.length) {
|
||||
const newRow = addMrow();
|
||||
const parent = this.mml.parentNode;
|
||||
parent.insertBefore(newRow, this.mml);
|
||||
for (const mrow of this.mrows) {
|
||||
newRow.appendChild(mrow);
|
||||
}
|
||||
newRow.appendChild(this.mml);
|
||||
}
|
||||
return this.mml;
|
||||
}
|
||||
recurseToTable(node) {
|
||||
var _a, _b;
|
||||
if (!(node.hasAnnotation('Emph', 'top') || node.hasAnnotation('Emph', 'fence')) &&
|
||||
(node.hasAnnotation('Emph', 'left') ||
|
||||
node.hasAnnotation('Emph', 'right'))) {
|
||||
EnrichMathml.walkTree(node);
|
||||
return;
|
||||
}
|
||||
if (!node.mathmlTree ||
|
||||
(DomUtil.tagName(node.mathmlTree) === MMLTAGS.MTABLE &&
|
||||
((_a = node.annotation['Emph']) === null || _a === void 0 ? void 0 : _a.length) &&
|
||||
node.annotation['Emph'][0] !== 'table')) {
|
||||
const newNode = addMrow();
|
||||
setAttributes(newNode, node);
|
||||
this.mrows.unshift(newNode);
|
||||
}
|
||||
else {
|
||||
if (DomUtil.tagName(node.mathmlTree) === MMLTAGS.MTABLE &&
|
||||
((_b = node.annotation['Emph']) === null || _b === void 0 ? void 0 : _b.length) &&
|
||||
node.annotation['Emph'][0] === 'table') {
|
||||
this.finalizeTable(node);
|
||||
return;
|
||||
}
|
||||
setAttributes(node.mathmlTree, node);
|
||||
}
|
||||
node.childNodes.forEach(this.recurseToTable.bind(this));
|
||||
if (node.textContent || node.type === 'punctuated') {
|
||||
const newContent = node.contentNodes.map((x) => {
|
||||
const newNode = EnrichMathml.cloneContentNode(x);
|
||||
if (newNode.hasAttribute('data-semantic-added')) {
|
||||
this.mrows.unshift(newNode);
|
||||
}
|
||||
else {
|
||||
this.recurseToTable(x);
|
||||
}
|
||||
return newNode;
|
||||
});
|
||||
EnrichMathml.setOperatorAttribute(node, newContent);
|
||||
return;
|
||||
}
|
||||
node.contentNodes.forEach(this.recurseToTable.bind(this));
|
||||
}
|
||||
finalizeTable(node) {
|
||||
setAttributes(node.mathmlTree, node);
|
||||
node.contentNodes.forEach((x) => {
|
||||
EnrichMathml.walkTree(x);
|
||||
});
|
||||
node.childNodes.forEach((x) => {
|
||||
EnrichMathml.walkTree(x);
|
||||
});
|
||||
}
|
||||
}
|
||||
9
node_modules/speech-rule-engine/mjs/enrich_mathml/case_limit.d.ts
generated
vendored
Normal file
9
node_modules/speech-rule-engine/mjs/enrich_mathml/case_limit.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseLimit extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
private static walkTree_;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
44
node_modules/speech-rule-engine/mjs/enrich_mathml/case_limit.js
generated
vendored
Normal file
44
node_modules/speech-rule-engine/mjs/enrich_mathml/case_limit.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { MMLTAGS } from '../semantic_tree/semantic_util.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { setAttributes } from './enrich_attr.js';
|
||||
export class CaseLimit extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
if (!semantic.mathmlTree || !semantic.childNodes.length) {
|
||||
return false;
|
||||
}
|
||||
const mmlTag = DomUtil.tagName(semantic.mathmlTree);
|
||||
const type = semantic.type;
|
||||
return (((type === SemanticType.LIMUPPER || type === SemanticType.LIMLOWER) &&
|
||||
(mmlTag === MMLTAGS.MSUBSUP || mmlTag === MMLTAGS.MUNDEROVER)) ||
|
||||
(type === SemanticType.LIMBOTH &&
|
||||
(mmlTag === MMLTAGS.MSUB ||
|
||||
mmlTag === MMLTAGS.MUNDER ||
|
||||
mmlTag === MMLTAGS.MSUP ||
|
||||
mmlTag === MMLTAGS.MOVER)));
|
||||
}
|
||||
static walkTree_(node) {
|
||||
if (node) {
|
||||
EnrichMathml.walkTree(node);
|
||||
}
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
getMathml() {
|
||||
const children = this.semantic.childNodes;
|
||||
if (this.semantic.type !== SemanticType.LIMBOTH &&
|
||||
this.mml.childNodes.length >= 3) {
|
||||
this.mml = EnrichMathml.introduceNewLayer([this.mml], this.semantic);
|
||||
}
|
||||
setAttributes(this.mml, this.semantic);
|
||||
if (!children[0].mathmlTree) {
|
||||
children[0].mathmlTree = this.semantic.mathmlTree;
|
||||
}
|
||||
children.forEach(CaseLimit.walkTree_);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_line.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_line.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseLine extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
23
node_modules/speech-rule-engine/mjs/enrich_mathml/case_line.js
generated
vendored
Normal file
23
node_modules/speech-rule-engine/mjs/enrich_mathml/case_line.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { setAttributes } from './enrich_attr.js';
|
||||
export class CaseLine extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return !!semantic.mathmlTree && semantic.type === SemanticType.LINE;
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
getMathml() {
|
||||
if (this.semantic.contentNodes.length) {
|
||||
EnrichMathml.walkTree(this.semantic.contentNodes[0]);
|
||||
}
|
||||
if (this.semantic.childNodes.length) {
|
||||
EnrichMathml.walkTree(this.semantic.childNodes[0]);
|
||||
}
|
||||
setAttributes(this.mml, this.semantic);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
10
node_modules/speech-rule-engine/mjs/enrich_mathml/case_multiindex.d.ts
generated
vendored
Normal file
10
node_modules/speech-rule-engine/mjs/enrich_mathml/case_multiindex.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { Sexp } from '../semantic_tree/semantic_skeleton.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare abstract class CaseMultiindex extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
static multiscriptIndex(index: SemanticNode): Sexp;
|
||||
private static createNone_;
|
||||
constructor(semantic: SemanticNode);
|
||||
protected completeMultiscript(rightIndices: Sexp, leftIndices: Sexp): void;
|
||||
}
|
||||
60
node_modules/speech-rule-engine/mjs/enrich_mathml/case_multiindex.js
generated
vendored
Normal file
60
node_modules/speech-rule-engine/mjs/enrich_mathml/case_multiindex.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { MMLTAGS } from '../semantic_tree/semantic_util.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { setAttributes, Attribute } from './enrich_attr.js';
|
||||
export class CaseMultiindex extends AbstractEnrichCase {
|
||||
static multiscriptIndex(index) {
|
||||
if (index.type === SemanticType.PUNCTUATED &&
|
||||
index.contentNodes[0].role === SemanticRole.DUMMY) {
|
||||
return EnrichMathml.collapsePunctuated(index);
|
||||
}
|
||||
EnrichMathml.walkTree(index);
|
||||
return index.id;
|
||||
}
|
||||
static createNone_(semantic) {
|
||||
const newNode = DomUtil.createElement('none');
|
||||
if (semantic) {
|
||||
setAttributes(newNode, semantic);
|
||||
}
|
||||
newNode.setAttribute(Attribute.ADDED, 'true');
|
||||
return newNode;
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
completeMultiscript(rightIndices, leftIndices) {
|
||||
const children = DomUtil.toArray(this.mml.childNodes).slice(1);
|
||||
let childCounter = 0;
|
||||
const completeIndices = (indices) => {
|
||||
for (const index of indices) {
|
||||
const child = children[childCounter];
|
||||
if (child && index === parseInt(child.getAttribute(Attribute.ID))) {
|
||||
child.setAttribute(Attribute.PARENT, this.semantic.id.toString());
|
||||
childCounter++;
|
||||
}
|
||||
else if (!child ||
|
||||
index !==
|
||||
parseInt(EnrichMathml.getInnerNode(child).getAttribute(Attribute.ID))) {
|
||||
const query = this.semantic.querySelectorAll((x) => x.id === index);
|
||||
this.mml.insertBefore(CaseMultiindex.createNone_(query[0]), child || null);
|
||||
}
|
||||
else {
|
||||
EnrichMathml.getInnerNode(child).setAttribute(Attribute.PARENT, this.semantic.id.toString());
|
||||
childCounter++;
|
||||
}
|
||||
}
|
||||
};
|
||||
completeIndices(rightIndices);
|
||||
if (children[childCounter] &&
|
||||
DomUtil.tagName(children[childCounter]) !== MMLTAGS.MPRESCRIPTS) {
|
||||
this.mml.insertBefore(children[childCounter], DomUtil.createElement('mprescripts'));
|
||||
}
|
||||
else {
|
||||
childCounter++;
|
||||
}
|
||||
completeIndices(leftIndices);
|
||||
}
|
||||
}
|
||||
7
node_modules/speech-rule-engine/mjs/enrich_mathml/case_multiscripts.d.ts
generated
vendored
Normal file
7
node_modules/speech-rule-engine/mjs/enrich_mathml/case_multiscripts.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { CaseMultiindex } from './case_multiindex.js';
|
||||
export declare class CaseMultiscripts extends CaseMultiindex {
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
48
node_modules/speech-rule-engine/mjs/enrich_mathml/case_multiscripts.js
generated
vendored
Normal file
48
node_modules/speech-rule-engine/mjs/enrich_mathml/case_multiscripts.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { SemanticSkeleton } from '../semantic_tree/semantic_skeleton.js';
|
||||
import { MMLTAGS } from '../semantic_tree/semantic_util.js';
|
||||
import { CaseMultiindex } from './case_multiindex.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { setAttributes, Attribute } from './enrich_attr.js';
|
||||
export class CaseMultiscripts extends CaseMultiindex {
|
||||
static test(semantic) {
|
||||
if (!semantic.mathmlTree) {
|
||||
return false;
|
||||
}
|
||||
const mmlTag = DomUtil.tagName(semantic.mathmlTree);
|
||||
return (mmlTag === MMLTAGS.MMULTISCRIPTS &&
|
||||
(semantic.type === SemanticType.SUPERSCRIPT ||
|
||||
semantic.type === SemanticType.SUBSCRIPT));
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
}
|
||||
getMathml() {
|
||||
setAttributes(this.mml, this.semantic);
|
||||
let baseSem, rsup, rsub;
|
||||
if (this.semantic.childNodes[0] &&
|
||||
this.semantic.childNodes[0].role === SemanticRole.SUBSUP) {
|
||||
const ignore = this.semantic.childNodes[0];
|
||||
baseSem = ignore.childNodes[0];
|
||||
rsup = CaseMultiindex.multiscriptIndex(this.semantic.childNodes[1]);
|
||||
rsub = CaseMultiindex.multiscriptIndex(ignore.childNodes[1]);
|
||||
const collapsed = [this.semantic.id, [ignore.id, baseSem.id, rsub], rsup];
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, collapsed);
|
||||
this.mml.setAttribute(Attribute.TYPE, ignore.role);
|
||||
this.completeMultiscript(SemanticSkeleton.interleaveIds(rsub, rsup), []);
|
||||
}
|
||||
else {
|
||||
baseSem = this.semantic.childNodes[0];
|
||||
rsup = CaseMultiindex.multiscriptIndex(this.semantic.childNodes[1]);
|
||||
const collapsed = [this.semantic.id, baseSem.id, rsup];
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, collapsed);
|
||||
}
|
||||
const childIds = SemanticSkeleton.collapsedLeafs(rsub || [], rsup);
|
||||
const base = EnrichMathml.walkTree(baseSem);
|
||||
EnrichMathml.getInnerNode(base).setAttribute(Attribute.PARENT, this.semantic.id.toString());
|
||||
childIds.unshift(baseSem.id);
|
||||
this.mml.setAttribute(Attribute.CHILDREN, childIds.join(','));
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_proof.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_proof.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseProof extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
33
node_modules/speech-rule-engine/mjs/enrich_mathml/case_proof.js
generated
vendored
Normal file
33
node_modules/speech-rule-engine/mjs/enrich_mathml/case_proof.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { setAttributes } from './enrich_attr.js';
|
||||
export class CaseProof extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return (!!semantic.mathmlTree &&
|
||||
(semantic.type === SemanticType.INFERENCE ||
|
||||
semantic.type === SemanticType.PREMISES));
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
getMathml() {
|
||||
if (!this.semantic.childNodes.length) {
|
||||
return this.mml;
|
||||
}
|
||||
this.semantic.contentNodes.forEach(function (x) {
|
||||
EnrichMathml.walkTree(x);
|
||||
setAttributes(x.mathmlTree, x);
|
||||
});
|
||||
this.semantic.childNodes.forEach(function (x) {
|
||||
EnrichMathml.walkTree(x);
|
||||
});
|
||||
setAttributes(this.mml, this.semantic);
|
||||
if (this.mml.getAttribute('data-semantic-id') ===
|
||||
this.mml.getAttribute('data-semantic-parent')) {
|
||||
this.mml.removeAttribute('data-semantic-parent');
|
||||
}
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
9
node_modules/speech-rule-engine/mjs/enrich_mathml/case_table.d.ts
generated
vendored
Normal file
9
node_modules/speech-rule-engine/mjs/enrich_mathml/case_table.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseTable extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
inner: Element[];
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
45
node_modules/speech-rule-engine/mjs/enrich_mathml/case_table.js
generated
vendored
Normal file
45
node_modules/speech-rule-engine/mjs/enrich_mathml/case_table.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { MMLTAGS } from '../semantic_tree/semantic_util.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { setAttributes } from './enrich_attr.js';
|
||||
export class CaseTable extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return (semantic.type === SemanticType.MATRIX ||
|
||||
semantic.type === SemanticType.VECTOR ||
|
||||
semantic.type === SemanticType.CASES);
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.inner = [];
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
getMathml() {
|
||||
const lfence = EnrichMathml.cloneContentNode(this.semantic.contentNodes[0]);
|
||||
const rfence = this.semantic.contentNodes[1]
|
||||
? EnrichMathml.cloneContentNode(this.semantic.contentNodes[1])
|
||||
: null;
|
||||
this.inner = this.semantic.childNodes.map(EnrichMathml.walkTree);
|
||||
if (!this.mml) {
|
||||
this.mml = EnrichMathml.introduceNewLayer([lfence].concat(this.inner, [rfence]), this.semantic);
|
||||
}
|
||||
else if (DomUtil.tagName(this.mml) === MMLTAGS.MFENCED) {
|
||||
const children = this.mml.childNodes;
|
||||
this.mml.insertBefore(lfence, children[0] || null);
|
||||
if (rfence) {
|
||||
this.mml.appendChild(rfence);
|
||||
}
|
||||
this.mml = EnrichMathml.rewriteMfenced(this.mml);
|
||||
}
|
||||
else {
|
||||
const newChildren = [lfence, this.mml];
|
||||
if (rfence) {
|
||||
newChildren.push(rfence);
|
||||
}
|
||||
this.mml = EnrichMathml.introduceNewLayer(newChildren, this.semantic);
|
||||
}
|
||||
setAttributes(this.mml, this.semantic);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
7
node_modules/speech-rule-engine/mjs/enrich_mathml/case_tensor.d.ts
generated
vendored
Normal file
7
node_modules/speech-rule-engine/mjs/enrich_mathml/case_tensor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { CaseMultiindex } from './case_multiindex.js';
|
||||
export declare class CaseTensor extends CaseMultiindex {
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
35
node_modules/speech-rule-engine/mjs/enrich_mathml/case_tensor.js
generated
vendored
Normal file
35
node_modules/speech-rule-engine/mjs/enrich_mathml/case_tensor.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import { SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { SemanticSkeleton } from '../semantic_tree/semantic_skeleton.js';
|
||||
import { CaseMultiindex } from './case_multiindex.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { setAttributes, Attribute } from './enrich_attr.js';
|
||||
export class CaseTensor extends CaseMultiindex {
|
||||
static test(semantic) {
|
||||
return !!semantic.mathmlTree && semantic.type === SemanticType.TENSOR;
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
}
|
||||
getMathml() {
|
||||
EnrichMathml.walkTree(this.semantic.childNodes[0]);
|
||||
const lsub = CaseMultiindex.multiscriptIndex(this.semantic.childNodes[1]);
|
||||
const lsup = CaseMultiindex.multiscriptIndex(this.semantic.childNodes[2]);
|
||||
const rsub = CaseMultiindex.multiscriptIndex(this.semantic.childNodes[3]);
|
||||
const rsup = CaseMultiindex.multiscriptIndex(this.semantic.childNodes[4]);
|
||||
setAttributes(this.mml, this.semantic);
|
||||
const collapsed = [
|
||||
this.semantic.id,
|
||||
this.semantic.childNodes[0].id,
|
||||
lsub,
|
||||
lsup,
|
||||
rsub,
|
||||
rsup
|
||||
];
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, collapsed);
|
||||
const childIds = SemanticSkeleton.collapsedLeafs(lsub, lsup, rsub, rsup);
|
||||
childIds.unshift(this.semantic.childNodes[0].id);
|
||||
this.mml.setAttribute(Attribute.CHILDREN, childIds.join(','));
|
||||
this.completeMultiscript(SemanticSkeleton.interleaveIds(rsub, rsup), SemanticSkeleton.interleaveIds(lsub, lsup));
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_text.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/mjs/enrich_mathml/case_text.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
export declare class CaseText extends AbstractEnrichCase {
|
||||
mml: Element;
|
||||
static test(semantic: SemanticNode): boolean;
|
||||
constructor(semantic: SemanticNode);
|
||||
getMathml(): Element;
|
||||
}
|
||||
24
node_modules/speech-rule-engine/mjs/enrich_mathml/case_text.js
generated
vendored
Normal file
24
node_modules/speech-rule-engine/mjs/enrich_mathml/case_text.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { AbstractEnrichCase } from './abstract_enrich_case.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import { setAttributes, Attribute } from './enrich_attr.js';
|
||||
export class CaseText extends AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return (semantic.type === SemanticType.PUNCTUATED &&
|
||||
(semantic.role === SemanticRole.TEXT ||
|
||||
semantic.contentNodes.every((x) => x.role === SemanticRole.DUMMY)));
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
this.mml = semantic.mathmlTree;
|
||||
}
|
||||
getMathml() {
|
||||
const children = [];
|
||||
const collapsed = EnrichMathml.collapsePunctuated(this.semantic, children);
|
||||
this.mml = EnrichMathml.introduceNewLayer(children, this.semantic);
|
||||
setAttributes(this.mml, this.semantic);
|
||||
this.mml.removeAttribute(Attribute.CONTENT);
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, collapsed);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
6
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich.d.ts
generated
vendored
Normal file
6
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import './enrich_case_factory.js';
|
||||
export declare function semanticMathmlNode(mml: Element): Element;
|
||||
export declare function semanticMathmlSync(expr: string): Element;
|
||||
export declare function semanticMathml(expr: string, callback: (p1: Element) => any): void;
|
||||
export declare function testTranslation(expr: string): Element;
|
||||
export declare function prepareMmlString(expr: string): string;
|
||||
36
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich.js
generated
vendored
Normal file
36
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Debugger } from '../common/debugger.js';
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { EnginePromise } from '../common/engine.js';
|
||||
import * as Semantic from '../semantic_tree/semantic.js';
|
||||
import * as EnrichMathml from './enrich_mathml.js';
|
||||
import './enrich_case_factory.js';
|
||||
export function semanticMathmlNode(mml) {
|
||||
const clone = DomUtil.cloneNode(mml);
|
||||
const tree = Semantic.getTree(clone);
|
||||
return EnrichMathml.enrich(clone, tree);
|
||||
}
|
||||
export function semanticMathmlSync(expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
return semanticMathmlNode(mml);
|
||||
}
|
||||
export function semanticMathml(expr, callback) {
|
||||
EnginePromise.getall().then(() => {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
callback(semanticMathmlNode(mml));
|
||||
});
|
||||
}
|
||||
export function testTranslation(expr) {
|
||||
Debugger.getInstance().init();
|
||||
const mml = semanticMathmlSync(prepareMmlString(expr));
|
||||
Debugger.getInstance().exit();
|
||||
return mml;
|
||||
}
|
||||
export function prepareMmlString(expr) {
|
||||
if (!expr.match(/^<math/)) {
|
||||
expr = '<math>' + expr;
|
||||
}
|
||||
if (!expr.match(/\/math>$/)) {
|
||||
expr += '</math>';
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
30
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_attr.d.ts
generated
vendored
Normal file
30
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_attr.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
export declare enum Attribute {
|
||||
ADDED = "data-semantic-added",
|
||||
ALTERNATIVE = "data-semantic-alternative",
|
||||
CHILDREN = "data-semantic-children",
|
||||
COLLAPSED = "data-semantic-collapsed",
|
||||
CONTENT = "data-semantic-content",
|
||||
EMBELLISHED = "data-semantic-embellished",
|
||||
FENCEPOINTER = "data-semantic-fencepointer",
|
||||
FONT = "data-semantic-font",
|
||||
ID = "data-semantic-id",
|
||||
ANNOTATION = "data-semantic-annotation",
|
||||
ATTRIBUTES = "data-semantic-attributes",
|
||||
OPERATOR = "data-semantic-operator",
|
||||
OWNS = "data-semantic-owns",
|
||||
PARENT = "data-semantic-parent",
|
||||
POSTFIX = "data-semantic-postfix",
|
||||
PREFIX = "data-semantic-prefix",
|
||||
ROLE = "data-semantic-role",
|
||||
SPEECH = "data-semantic-speech",
|
||||
STRUCTURE = "data-semantic-structure",
|
||||
SUMMARY = "data-semantic-summary",
|
||||
TYPE = "data-semantic-type"
|
||||
}
|
||||
export declare const EnrichAttributes: string[];
|
||||
export declare function makeIdList(nodes: SemanticNode[]): string;
|
||||
export declare function setAttributes(mml: Element, semantic: SemanticNode): void;
|
||||
export declare function removeAttributePrefix(mml: string): string;
|
||||
export declare function addPrefix(attr: string): Attribute;
|
||||
export declare function addMrow(): Element;
|
||||
101
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_attr.js
generated
vendored
Normal file
101
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_attr.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { SemanticRole } from '../semantic_tree/semantic_meaning.js';
|
||||
const Prefix = 'data-semantic-';
|
||||
export 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 || (Attribute = {}));
|
||||
export const 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
|
||||
];
|
||||
export function makeIdList(nodes) {
|
||||
return nodes
|
||||
.map(function (node) {
|
||||
return node.id;
|
||||
})
|
||||
.join(',');
|
||||
}
|
||||
export 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 === SemanticRole.MGLYPH) {
|
||||
postfix.push('image');
|
||||
}
|
||||
if (semantic.attributes['href']) {
|
||||
postfix.push('link');
|
||||
}
|
||||
if (postfix.length) {
|
||||
mml.setAttribute(Attribute.POSTFIX, postfix.join(' '));
|
||||
}
|
||||
}
|
||||
export function removeAttributePrefix(mml) {
|
||||
return mml.toString().replace(new RegExp(Prefix, 'g'), '');
|
||||
}
|
||||
export function addPrefix(attr) {
|
||||
return (Prefix + attr);
|
||||
}
|
||||
export function addMrow() {
|
||||
const mrow = DomUtil.createElement('mrow');
|
||||
mrow.setAttribute(Attribute.ADDED, 'true');
|
||||
return mrow;
|
||||
}
|
||||
11
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_case.d.ts
generated
vendored
Normal file
11
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_case.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
export interface EnrichCase {
|
||||
getMathml(): Element;
|
||||
}
|
||||
interface Case {
|
||||
test: (p1: SemanticNode) => boolean;
|
||||
constr: (p1: SemanticNode) => EnrichCase;
|
||||
}
|
||||
export declare function getCase(node: SemanticNode): EnrichCase;
|
||||
export declare const factory: Case[];
|
||||
export {};
|
||||
9
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_case.js
generated
vendored
Normal file
9
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_case.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export function getCase(node) {
|
||||
for (let i = 0, enrich; (enrich = factory[i]); i++) {
|
||||
if (enrich.test(node)) {
|
||||
return enrich.constr(node);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export const factory = [];
|
||||
1
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_case_factory.d.ts
generated
vendored
Normal file
1
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_case_factory.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
52
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_case_factory.js
generated
vendored
Normal file
52
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_case_factory.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { CaseBinomial } from './case_binomial.js';
|
||||
import { CaseDoubleScript } from './case_double_script.js';
|
||||
import { CaseEmbellished } from './case_embellished.js';
|
||||
import { CaseEmpheq } from './case_empheq.js';
|
||||
import { CaseLimit } from './case_limit.js';
|
||||
import { CaseLine } from './case_line.js';
|
||||
import { CaseMultiscripts } from './case_multiscripts.js';
|
||||
import { CaseProof } from './case_proof.js';
|
||||
import { CaseTable } from './case_table.js';
|
||||
import { CaseTensor } from './case_tensor.js';
|
||||
import { CaseText } from './case_text.js';
|
||||
import { factory } from './enrich_case.js';
|
||||
factory.push(...[
|
||||
{
|
||||
test: CaseLimit.test,
|
||||
constr: (node) => new CaseLimit(node)
|
||||
},
|
||||
{
|
||||
test: CaseEmbellished.test,
|
||||
constr: (node) => new CaseEmbellished(node)
|
||||
},
|
||||
{
|
||||
test: CaseDoubleScript.test,
|
||||
constr: (node) => new CaseDoubleScript(node)
|
||||
},
|
||||
{
|
||||
test: CaseTensor.test,
|
||||
constr: (node) => new CaseTensor(node)
|
||||
},
|
||||
{
|
||||
test: CaseMultiscripts.test,
|
||||
constr: (node) => new CaseMultiscripts(node)
|
||||
},
|
||||
{ test: CaseLine.test, constr: (node) => new CaseLine(node) },
|
||||
{
|
||||
test: CaseBinomial.test,
|
||||
constr: (node) => new CaseBinomial(node)
|
||||
},
|
||||
{
|
||||
test: CaseProof.test,
|
||||
constr: (node) => new CaseProof(node)
|
||||
},
|
||||
{
|
||||
test: CaseEmpheq.test,
|
||||
constr: (node) => new CaseEmpheq(node)
|
||||
},
|
||||
{
|
||||
test: CaseTable.test,
|
||||
constr: (node) => new CaseTable(node)
|
||||
},
|
||||
{ test: CaseText.test, constr: (node) => new CaseText(node) }
|
||||
]);
|
||||
13
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_mathml.d.ts
generated
vendored
Normal file
13
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_mathml.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { SemanticNode } from '../semantic_tree/semantic_node.js';
|
||||
import { Sexp } from '../semantic_tree/semantic_skeleton.js';
|
||||
import { SemanticTree } from '../semantic_tree/semantic_tree.js';
|
||||
export declare function enrich(mml: Element, semantic: SemanticTree): Element;
|
||||
export declare function walkTree(semantic: SemanticNode): Element;
|
||||
export declare function introduceNewLayer(children: Element[], semantic: SemanticNode): Element;
|
||||
export declare function ascendNewNode(newNode: Element): Element;
|
||||
export declare function addCollapsedAttribute(node: Element, collapsed: Sexp): void;
|
||||
export declare function cloneContentNode(content: SemanticNode): Element;
|
||||
export declare function rewriteMfenced(mml: Element): Element;
|
||||
export declare function setOperatorAttribute(semantic: SemanticNode, content: Element[]): void;
|
||||
export declare function getInnerNode(node: Element): Element;
|
||||
export declare function collapsePunctuated(semantic: SemanticNode, opt_children?: Element[]): Sexp;
|
||||
543
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_mathml.js
generated
vendored
Normal file
543
node_modules/speech-rule-engine/mjs/enrich_mathml/enrich_mathml.js
generated
vendored
Normal file
@@ -0,0 +1,543 @@
|
||||
import { Debugger } from '../common/debugger.js';
|
||||
import * as DomUtil from '../common/dom_util.js';
|
||||
import { Engine } from '../common/engine.js';
|
||||
import { NamedSymbol } from '../semantic_tree/semantic_attr.js';
|
||||
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
|
||||
import { SemanticHeuristics } from '../semantic_tree/semantic_heuristic_factory.js';
|
||||
import { SemanticSkeleton } from '../semantic_tree/semantic_skeleton.js';
|
||||
import * as SemanticUtil from '../semantic_tree/semantic_util.js';
|
||||
import { MMLTAGS } from '../semantic_tree/semantic_util.js';
|
||||
import * as EnrichAttr from './enrich_attr.js';
|
||||
import { getCase } from './enrich_case.js';
|
||||
const SETTINGS = {
|
||||
collapsed: true,
|
||||
implicit: true,
|
||||
wiki: true
|
||||
};
|
||||
const IDS = new Map();
|
||||
export function enrich(mml, semantic) {
|
||||
IDS.clear();
|
||||
const oldMml = DomUtil.cloneNode(mml);
|
||||
walkTree(semantic.root);
|
||||
if (Engine.getInstance().structure) {
|
||||
mml.setAttribute(EnrichAttr.Attribute.STRUCTURE, SemanticSkeleton.fromStructure(mml, semantic).toString());
|
||||
}
|
||||
Debugger.getInstance().generateOutput(() => [
|
||||
formattedOutput(oldMml, 'Original MathML', SETTINGS.wiki),
|
||||
formattedOutput(semantic, 'Semantic Tree', SETTINGS.wiki),
|
||||
formattedOutput(mml, 'Semantically enriched MathML', SETTINGS.wiki)
|
||||
]);
|
||||
return mml;
|
||||
}
|
||||
export function walkTree(semantic) {
|
||||
Debugger.getInstance().output('WALKING START: ' + semantic.toString());
|
||||
const specialCase = getCase(semantic);
|
||||
let newNode;
|
||||
if (specialCase) {
|
||||
newNode = specialCase.getMathml();
|
||||
Debugger.getInstance().output('WALKING END: ' + semantic.toString());
|
||||
return ascendNewNode(newNode);
|
||||
}
|
||||
if (semantic.mathml.length === 1) {
|
||||
Debugger.getInstance().output('Walktree Case 0');
|
||||
if (!semantic.childNodes.length) {
|
||||
Debugger.getInstance().output('Walktree Case 0.1');
|
||||
newNode = semantic.mathml[0];
|
||||
EnrichAttr.setAttributes(newNode, semantic);
|
||||
Debugger.getInstance().output('WALKING END: ' + semantic.toString());
|
||||
return ascendNewNode(newNode);
|
||||
}
|
||||
const fchild = semantic.childNodes[0];
|
||||
if (semantic.childNodes.length === 1 &&
|
||||
fchild.type === SemanticType.EMPTY) {
|
||||
Debugger.getInstance().output('Walktree Case 0.2');
|
||||
newNode = semantic.mathml[0];
|
||||
EnrichAttr.setAttributes(newNode, semantic);
|
||||
newNode.appendChild(walkTree(fchild));
|
||||
Debugger.getInstance().output('WALKING END: ' + semantic.toString());
|
||||
return ascendNewNode(newNode);
|
||||
}
|
||||
semantic.childNodes.forEach((child) => {
|
||||
if (!child.mathml.length) {
|
||||
child.mathml = [createInvisibleOperator(child)];
|
||||
}
|
||||
});
|
||||
}
|
||||
const newContent = semantic.contentNodes.map(cloneContentNode);
|
||||
setOperatorAttribute(semantic, newContent);
|
||||
const newChildren = semantic.childNodes.map(walkTree);
|
||||
const childrenList = SemanticSkeleton.combineContentChildren(semantic.type, semantic.role, newContent, newChildren);
|
||||
newNode = semantic.mathmlTree;
|
||||
if (newNode === null) {
|
||||
Debugger.getInstance().output('Walktree Case 1');
|
||||
newNode = introduceNewLayer(childrenList, semantic);
|
||||
}
|
||||
else {
|
||||
const attached = attachedElement(childrenList);
|
||||
Debugger.getInstance().output('Walktree Case 2');
|
||||
if (attached) {
|
||||
Debugger.getInstance().output('Walktree Case 2.1');
|
||||
newNode = parentNode(attached);
|
||||
}
|
||||
else {
|
||||
Debugger.getInstance().output('Walktree Case 2.2');
|
||||
newNode = getInnerNode(newNode);
|
||||
}
|
||||
}
|
||||
newNode = rewriteMfenced(newNode);
|
||||
mergeChildren(newNode, childrenList, semantic);
|
||||
if (!IDS.has(semantic.id)) {
|
||||
IDS.set(semantic.id, true);
|
||||
EnrichAttr.setAttributes(newNode, semantic);
|
||||
}
|
||||
Debugger.getInstance().output('WALKING END: ' + semantic.toString());
|
||||
return ascendNewNode(newNode);
|
||||
}
|
||||
export function introduceNewLayer(children, semantic) {
|
||||
const lca = mathmlLca(children);
|
||||
let newNode = lca.node;
|
||||
const info = lca.type;
|
||||
if (info !== lcaType.VALID ||
|
||||
!SemanticUtil.hasEmptyTag(newNode) ||
|
||||
(!newNode.parentNode && semantic.parent)) {
|
||||
Debugger.getInstance().output('Walktree Case 1.1');
|
||||
newNode = EnrichAttr.addMrow();
|
||||
if (info === lcaType.PRUNED) {
|
||||
Debugger.getInstance().output('Walktree Case 1.1.0');
|
||||
newNode = introduceLayerAboveLca(newNode, lca.node, children);
|
||||
}
|
||||
else if (children[0]) {
|
||||
Debugger.getInstance().output('Walktree Case 1.1.1');
|
||||
const node = attachedElement(children);
|
||||
if (node) {
|
||||
const oldChildren = childrenSubset(parentNode(node), children);
|
||||
DomUtil.replaceNode(node, newNode);
|
||||
oldChildren.forEach(function (x) {
|
||||
newNode.appendChild(x);
|
||||
});
|
||||
}
|
||||
else {
|
||||
moveSemanticAttributes(newNode, children[0]);
|
||||
newNode = children[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!semantic.mathmlTree) {
|
||||
semantic.mathmlTree = newNode;
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
function introduceLayerAboveLca(mrow, lca, children) {
|
||||
let innerNode = descendNode(lca);
|
||||
if (SemanticUtil.hasMathTag(innerNode)) {
|
||||
Debugger.getInstance().output('Walktree Case 1.1.0.0');
|
||||
moveSemanticAttributes(innerNode, mrow);
|
||||
DomUtil.toArray(innerNode.childNodes).forEach(function (x) {
|
||||
mrow.appendChild(x);
|
||||
});
|
||||
const auxNode = mrow;
|
||||
mrow = innerNode;
|
||||
innerNode = auxNode;
|
||||
}
|
||||
const index = children.indexOf(lca);
|
||||
children[index] = innerNode;
|
||||
DomUtil.replaceNode(innerNode, mrow);
|
||||
mrow.appendChild(innerNode);
|
||||
children.forEach(function (x) {
|
||||
mrow.appendChild(x);
|
||||
});
|
||||
return mrow;
|
||||
}
|
||||
function moveSemanticAttributes(oldNode, newNode) {
|
||||
for (const attr of EnrichAttr.EnrichAttributes) {
|
||||
if (oldNode.hasAttribute(attr)) {
|
||||
newNode.setAttribute(attr, oldNode.getAttribute(attr));
|
||||
oldNode.removeAttribute(attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
function childrenSubset(node, newChildren) {
|
||||
const oldChildren = DomUtil.toArray(node.childNodes);
|
||||
let leftIndex = +Infinity;
|
||||
let rightIndex = -Infinity;
|
||||
newChildren.forEach(function (child) {
|
||||
const index = oldChildren.indexOf(child);
|
||||
if (index !== -1) {
|
||||
leftIndex = Math.min(leftIndex, index);
|
||||
rightIndex = Math.max(rightIndex, index);
|
||||
}
|
||||
});
|
||||
return oldChildren.slice(leftIndex, rightIndex + 1);
|
||||
}
|
||||
function collateChildNodes(node, children, semantic) {
|
||||
const oldChildren = [];
|
||||
let newChildren = DomUtil.toArray(node.childNodes);
|
||||
let notFirst = false;
|
||||
while (newChildren.length) {
|
||||
const child = newChildren.shift();
|
||||
if (child.hasAttribute(EnrichAttr.Attribute.TYPE)) {
|
||||
oldChildren.push(child);
|
||||
continue;
|
||||
}
|
||||
const collect = collectChildNodes(child, children);
|
||||
if (collect.length === 0) {
|
||||
continue;
|
||||
}
|
||||
if (collect.length === 1) {
|
||||
oldChildren.push(child);
|
||||
continue;
|
||||
}
|
||||
if (notFirst) {
|
||||
child.setAttribute('AuxiliaryImplicit', true);
|
||||
}
|
||||
else {
|
||||
notFirst = true;
|
||||
}
|
||||
newChildren = collect.concat(newChildren);
|
||||
}
|
||||
const rear = [];
|
||||
const semChildren = semantic.childNodes.map(function (x) {
|
||||
return x.mathmlTree;
|
||||
});
|
||||
while (semChildren.length) {
|
||||
const schild = semChildren.pop();
|
||||
if (!schild) {
|
||||
continue;
|
||||
}
|
||||
if (oldChildren.indexOf(schild) !== -1) {
|
||||
break;
|
||||
}
|
||||
if (children.indexOf(schild) !== -1) {
|
||||
rear.unshift(schild);
|
||||
}
|
||||
}
|
||||
return oldChildren.concat(rear);
|
||||
}
|
||||
function collectChildNodes(node, children) {
|
||||
const collect = [];
|
||||
let newChildren = DomUtil.toArray(node.childNodes);
|
||||
while (newChildren.length) {
|
||||
const child = newChildren.shift();
|
||||
if (child.nodeType !== DomUtil.NodeType.ELEMENT_NODE) {
|
||||
continue;
|
||||
}
|
||||
if (child.hasAttribute(EnrichAttr.Attribute.TYPE) ||
|
||||
children.indexOf(child) !== -1) {
|
||||
collect.push(child);
|
||||
continue;
|
||||
}
|
||||
newChildren = DomUtil.toArray(child.childNodes).concat(newChildren);
|
||||
}
|
||||
return collect;
|
||||
}
|
||||
function mergeChildren(node, newChildren, semantic) {
|
||||
if (!newChildren.length)
|
||||
return;
|
||||
if (newChildren.length === 1 && node === newChildren[0])
|
||||
return;
|
||||
const oldChildren = semantic.role === SemanticRole.IMPLICIT &&
|
||||
SemanticHeuristics.flags.combine_juxtaposition
|
||||
? collateChildNodes(node, newChildren, semantic)
|
||||
: DomUtil.toArray(node.childNodes);
|
||||
if (!oldChildren.length) {
|
||||
newChildren.forEach(function (x) {
|
||||
node.appendChild(x);
|
||||
});
|
||||
return;
|
||||
}
|
||||
let oldCounter = 0;
|
||||
while (newChildren.length) {
|
||||
const newChild = newChildren[0];
|
||||
if (oldChildren[oldCounter] === newChild ||
|
||||
functionApplication(oldChildren[oldCounter], newChild)) {
|
||||
newChildren.shift();
|
||||
oldCounter++;
|
||||
continue;
|
||||
}
|
||||
if (oldChildren[oldCounter] &&
|
||||
newChildren.indexOf(oldChildren[oldCounter]) === -1) {
|
||||
oldCounter++;
|
||||
continue;
|
||||
}
|
||||
if (isDescendant(newChild, node)) {
|
||||
newChildren.shift();
|
||||
continue;
|
||||
}
|
||||
const oldChild = oldChildren[oldCounter];
|
||||
if (!oldChild) {
|
||||
if (newChild.parentNode) {
|
||||
node = parentNode(newChild);
|
||||
newChildren.shift();
|
||||
continue;
|
||||
}
|
||||
const nextChild = newChildren[1];
|
||||
if (nextChild && nextChild.parentNode) {
|
||||
node = parentNode(nextChild);
|
||||
node.insertBefore(newChild, nextChild);
|
||||
newChildren.shift();
|
||||
newChildren.shift();
|
||||
continue;
|
||||
}
|
||||
node.insertBefore(newChild, null);
|
||||
newChildren.shift();
|
||||
continue;
|
||||
}
|
||||
insertNewChild(node, oldChild, newChild);
|
||||
newChildren.shift();
|
||||
}
|
||||
}
|
||||
function insertNewChild(node, oldChild, newChild) {
|
||||
let parent = oldChild;
|
||||
let next = parentNode(parent);
|
||||
while (next &&
|
||||
next.firstChild === parent &&
|
||||
!parent.hasAttribute('AuxiliaryImplicit') &&
|
||||
next !== node) {
|
||||
parent = next;
|
||||
next = parentNode(parent);
|
||||
}
|
||||
if (next) {
|
||||
next.insertBefore(newChild, parent);
|
||||
parent.removeAttribute('AuxiliaryImplicit');
|
||||
}
|
||||
}
|
||||
function isDescendant(child, node) {
|
||||
if (!child) {
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
child = parentNode(child);
|
||||
if (child === node) {
|
||||
return true;
|
||||
}
|
||||
} while (child);
|
||||
return false;
|
||||
}
|
||||
function functionApplication(oldNode, newNode) {
|
||||
const appl = NamedSymbol.functionApplication;
|
||||
if (oldNode &&
|
||||
newNode &&
|
||||
oldNode.textContent &&
|
||||
newNode.textContent &&
|
||||
oldNode.textContent === appl &&
|
||||
newNode.textContent === appl &&
|
||||
newNode.getAttribute(EnrichAttr.Attribute.ADDED) === 'true') {
|
||||
for (let i = 0, attr; (attr = oldNode.attributes[i]); i++) {
|
||||
if (!newNode.hasAttribute(attr.nodeName)) {
|
||||
newNode.setAttribute(attr.nodeName, attr.nodeValue);
|
||||
}
|
||||
}
|
||||
DomUtil.replaceNode(oldNode, newNode);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
var lcaType;
|
||||
(function (lcaType) {
|
||||
lcaType["VALID"] = "valid";
|
||||
lcaType["INVALID"] = "invalid";
|
||||
lcaType["PRUNED"] = "pruned";
|
||||
})(lcaType || (lcaType = {}));
|
||||
function mathmlLca(children) {
|
||||
const leftMost = attachedElement(children);
|
||||
if (!leftMost) {
|
||||
return { type: lcaType.INVALID, node: null };
|
||||
}
|
||||
const rightMost = attachedElement(children.slice().reverse());
|
||||
if (leftMost === rightMost) {
|
||||
return { type: lcaType.VALID, node: leftMost };
|
||||
}
|
||||
const leftPath = pathToRoot(leftMost);
|
||||
const newLeftPath = prunePath(leftPath, children);
|
||||
const rightPath = pathToRoot(rightMost, function (x) {
|
||||
return newLeftPath.indexOf(x) !== -1;
|
||||
});
|
||||
const lca = rightPath[0];
|
||||
const lIndex = newLeftPath.indexOf(lca);
|
||||
if (lIndex === -1) {
|
||||
return { type: lcaType.INVALID, node: null };
|
||||
}
|
||||
return {
|
||||
type: newLeftPath.length !== leftPath.length
|
||||
? lcaType.PRUNED
|
||||
: validLca(newLeftPath[lIndex + 1], rightPath[1])
|
||||
? lcaType.VALID
|
||||
: lcaType.INVALID,
|
||||
node: lca
|
||||
};
|
||||
}
|
||||
function prunePath(path, children) {
|
||||
let i = 0;
|
||||
while (path[i] && children.indexOf(path[i]) === -1) {
|
||||
i++;
|
||||
}
|
||||
return path.slice(0, i + 1);
|
||||
}
|
||||
function attachedElement(nodes) {
|
||||
let count = 0;
|
||||
let attached = null;
|
||||
while (!attached && count < nodes.length) {
|
||||
if (nodes[count].parentNode) {
|
||||
attached = nodes[count];
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return attached;
|
||||
}
|
||||
function pathToRoot(node, opt_test) {
|
||||
const test = opt_test || ((_x) => false);
|
||||
const path = [node];
|
||||
while (!test(node) && !SemanticUtil.hasMathTag(node) && node.parentNode) {
|
||||
node = parentNode(node);
|
||||
path.unshift(node);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
function validLca(left, right) {
|
||||
return !!(left && right && !left.previousSibling && !right.nextSibling);
|
||||
}
|
||||
export function ascendNewNode(newNode) {
|
||||
while (!SemanticUtil.hasMathTag(newNode) && unitChild(newNode)) {
|
||||
newNode = parentNode(newNode);
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
function descendNode(node) {
|
||||
const children = DomUtil.toArray(node.childNodes);
|
||||
if (!children) {
|
||||
return node;
|
||||
}
|
||||
const remainder = children.filter(function (child) {
|
||||
return (child.nodeType === DomUtil.NodeType.ELEMENT_NODE &&
|
||||
!SemanticUtil.hasIgnoreTag(child));
|
||||
});
|
||||
if (remainder.length === 1 &&
|
||||
SemanticUtil.hasEmptyTag(remainder[0]) &&
|
||||
!remainder[0].hasAttribute(EnrichAttr.Attribute.TYPE)) {
|
||||
return descendNode(remainder[0]);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
function unitChild(node) {
|
||||
const parent = parentNode(node);
|
||||
if (!parent || !SemanticUtil.hasEmptyTag(parent)) {
|
||||
return false;
|
||||
}
|
||||
return DomUtil.toArray(parent.childNodes).every(function (child) {
|
||||
return child === node || isIgnorable(child);
|
||||
});
|
||||
}
|
||||
function isIgnorable(node) {
|
||||
if (node.nodeType !== DomUtil.NodeType.ELEMENT_NODE) {
|
||||
return true;
|
||||
}
|
||||
if (!node || SemanticUtil.hasIgnoreTag(node)) {
|
||||
return true;
|
||||
}
|
||||
const children = DomUtil.toArray(node.childNodes);
|
||||
if ((!SemanticUtil.hasEmptyTag(node) && children.length) ||
|
||||
SemanticUtil.hasDisplayTag(node) ||
|
||||
node.hasAttribute(EnrichAttr.Attribute.TYPE) ||
|
||||
SemanticUtil.isOrphanedGlyph(node)) {
|
||||
return false;
|
||||
}
|
||||
return DomUtil.toArray(node.childNodes).every(isIgnorable);
|
||||
}
|
||||
function parentNode(element) {
|
||||
return element.parentNode;
|
||||
}
|
||||
export function addCollapsedAttribute(node, collapsed) {
|
||||
const skeleton = new SemanticSkeleton(collapsed);
|
||||
node.setAttribute(EnrichAttr.Attribute.COLLAPSED, skeleton.toString());
|
||||
}
|
||||
export function cloneContentNode(content) {
|
||||
if (content.mathml.length) {
|
||||
return walkTree(content);
|
||||
}
|
||||
const clone = SETTINGS.implicit
|
||||
? createInvisibleOperator(content)
|
||||
: EnrichAttr.addMrow();
|
||||
content.mathml = [clone];
|
||||
return clone;
|
||||
}
|
||||
export function rewriteMfenced(mml) {
|
||||
if (DomUtil.tagName(mml) !== MMLTAGS.MFENCED) {
|
||||
return mml;
|
||||
}
|
||||
const newNode = EnrichAttr.addMrow();
|
||||
for (let i = 0, attr; (attr = mml.attributes[i]); i++) {
|
||||
if (['open', 'close', 'separators'].indexOf(attr.name) === -1) {
|
||||
newNode.setAttribute(attr.name, attr.value);
|
||||
}
|
||||
}
|
||||
DomUtil.toArray(mml.childNodes).forEach(function (x) {
|
||||
newNode.appendChild(x);
|
||||
});
|
||||
DomUtil.replaceNode(mml, newNode);
|
||||
return newNode;
|
||||
}
|
||||
function createInvisibleOperator(operator) {
|
||||
const moNode = DomUtil.createElement('mo');
|
||||
const text = DomUtil.createTextNode(operator.textContent);
|
||||
moNode.appendChild(text);
|
||||
EnrichAttr.setAttributes(moNode, operator);
|
||||
moNode.setAttribute(EnrichAttr.Attribute.ADDED, 'true');
|
||||
return moNode;
|
||||
}
|
||||
export function setOperatorAttribute(semantic, content) {
|
||||
const operator = semantic.type + (semantic.textContent ? ',' + semantic.textContent : '');
|
||||
content.forEach(function (c) {
|
||||
getInnerNode(c).setAttribute(EnrichAttr.Attribute.OPERATOR, operator);
|
||||
});
|
||||
}
|
||||
export function getInnerNode(node) {
|
||||
const children = DomUtil.toArray(node.childNodes);
|
||||
if (!children) {
|
||||
return node;
|
||||
}
|
||||
const remainder = children.filter(function (child) {
|
||||
return !isIgnorable(child);
|
||||
});
|
||||
const result = [];
|
||||
for (let i = 0, remain; (remain = remainder[i]); i++) {
|
||||
if (SemanticUtil.hasEmptyTag(remain) &&
|
||||
remain.getAttribute(EnrichAttr.Attribute.TYPE) !==
|
||||
SemanticType.PUNCTUATION) {
|
||||
const nextInner = getInnerNode(remain);
|
||||
if (nextInner && nextInner !== remain) {
|
||||
result.push(nextInner);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.push(remain);
|
||||
}
|
||||
}
|
||||
if (result.length === 1) {
|
||||
return result[0];
|
||||
}
|
||||
return node;
|
||||
}
|
||||
function formattedOutput(element, name, wiki = false) {
|
||||
const output = EnrichAttr.removeAttributePrefix(DomUtil.formatXml(element.toString()));
|
||||
return wiki ? name + ':\n```html\n' + output + '\n```\n' : output;
|
||||
}
|
||||
export function collapsePunctuated(semantic, opt_children) {
|
||||
const optional = !!opt_children;
|
||||
const children = opt_children || [];
|
||||
const parent = semantic.parent;
|
||||
const contentIds = semantic.contentNodes.map(function (x) {
|
||||
return x.id;
|
||||
});
|
||||
contentIds.unshift('c');
|
||||
const childIds = [semantic.id, contentIds];
|
||||
for (let i = 0, child; (child = semantic.childNodes[i]); i++) {
|
||||
const mmlChild = walkTree(child);
|
||||
children.push(mmlChild);
|
||||
const innerNode = getInnerNode(mmlChild);
|
||||
if (parent && !optional) {
|
||||
innerNode.setAttribute(EnrichAttr.Attribute.PARENT, parent.id.toString());
|
||||
}
|
||||
childIds.push(child.id);
|
||||
}
|
||||
return childIds;
|
||||
}
|
||||
37
node_modules/speech-rule-engine/mjs/highlighter/abstract_highlighter.d.ts
generated
vendored
Normal file
37
node_modules/speech-rule-engine/mjs/highlighter/abstract_highlighter.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { ColorPicker, StringColor } from './color_picker.js';
|
||||
import { Highlighter } from './highlighter.js';
|
||||
export interface Highlight {
|
||||
node: HTMLElement;
|
||||
opacity?: string;
|
||||
background?: string;
|
||||
foreground?: string;
|
||||
box?: HTMLElement;
|
||||
position?: string;
|
||||
}
|
||||
export declare abstract class AbstractHighlighter implements Highlighter {
|
||||
counter: number;
|
||||
protected ATTR: string;
|
||||
protected color: ColorPicker;
|
||||
protected mactionName: string;
|
||||
private currentHighlights;
|
||||
protected abstract highlightNode(node: HTMLElement): Highlight;
|
||||
protected abstract unhighlightNode(highlight: Highlight): void;
|
||||
highlight(nodes: HTMLElement[]): void;
|
||||
highlightAll(node: HTMLElement): void;
|
||||
unhighlight(): void;
|
||||
unhighlightAll(): void;
|
||||
setColor(color: ColorPicker): void;
|
||||
colorString(): StringColor;
|
||||
addEvents(node: HTMLElement, events: {
|
||||
[key: string]: EventListener;
|
||||
}): void;
|
||||
getMactionNodes(node: HTMLElement): HTMLElement[];
|
||||
isMactionNode(node: Element): boolean;
|
||||
isHighlighted(node: HTMLElement): boolean;
|
||||
setHighlighted(node: HTMLElement): void;
|
||||
unsetHighlighted(node: HTMLElement): void;
|
||||
colorizeAll(node: HTMLElement): void;
|
||||
uncolorizeAll(node: HTMLElement): void;
|
||||
colorize(node: HTMLElement): void;
|
||||
uncolorize(node: HTMLElement): void;
|
||||
}
|
||||
94
node_modules/speech-rule-engine/mjs/highlighter/abstract_highlighter.js
generated
vendored
Normal file
94
node_modules/speech-rule-engine/mjs/highlighter/abstract_highlighter.js
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
import * as XpathUtil from '../common/xpath_util.js';
|
||||
import { addPrefix, Attribute } from '../enrich_mathml/enrich_attr.js';
|
||||
let counter = 0;
|
||||
export class AbstractHighlighter {
|
||||
constructor() {
|
||||
this.counter = counter++;
|
||||
this.ATTR = 'sre-highlight-' + this.counter.toString();
|
||||
this.color = null;
|
||||
this.mactionName = '';
|
||||
this.currentHighlights = [];
|
||||
}
|
||||
highlight(nodes) {
|
||||
this.currentHighlights.push(nodes.map((node) => {
|
||||
const info = this.highlightNode(node);
|
||||
this.setHighlighted(node);
|
||||
return info;
|
||||
}));
|
||||
}
|
||||
highlightAll(node) {
|
||||
const mactions = this.getMactionNodes(node);
|
||||
for (let i = 0, maction; (maction = mactions[i]); i++) {
|
||||
this.highlight([maction]);
|
||||
}
|
||||
}
|
||||
unhighlight() {
|
||||
const nodes = this.currentHighlights.pop();
|
||||
if (!nodes) {
|
||||
return;
|
||||
}
|
||||
nodes.forEach((highlight) => {
|
||||
if (this.isHighlighted(highlight.node)) {
|
||||
this.unhighlightNode(highlight);
|
||||
this.unsetHighlighted(highlight.node);
|
||||
}
|
||||
});
|
||||
}
|
||||
unhighlightAll() {
|
||||
while (this.currentHighlights.length > 0) {
|
||||
this.unhighlight();
|
||||
}
|
||||
}
|
||||
setColor(color) {
|
||||
this.color = color;
|
||||
}
|
||||
colorString() {
|
||||
return this.color.rgba();
|
||||
}
|
||||
addEvents(node, events) {
|
||||
const mactions = this.getMactionNodes(node);
|
||||
for (let i = 0, maction; (maction = mactions[i]); i++) {
|
||||
for (const [key, event] of Object.entries(events)) {
|
||||
maction.addEventListener(key, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
getMactionNodes(node) {
|
||||
return Array.from(node.getElementsByClassName(this.mactionName));
|
||||
}
|
||||
isMactionNode(node) {
|
||||
const className = node.className || node.getAttribute('class');
|
||||
return className ? !!className.match(new RegExp(this.mactionName)) : false;
|
||||
}
|
||||
isHighlighted(node) {
|
||||
return node.hasAttribute(this.ATTR);
|
||||
}
|
||||
setHighlighted(node) {
|
||||
node.setAttribute(this.ATTR, 'true');
|
||||
}
|
||||
unsetHighlighted(node) {
|
||||
node.removeAttribute(this.ATTR);
|
||||
}
|
||||
colorizeAll(node) {
|
||||
XpathUtil.updateEvaluator(node);
|
||||
const allNodes = XpathUtil.evalXPath(`.//*[@${Attribute.ID}]`, node);
|
||||
allNodes.forEach((x) => this.colorize(x));
|
||||
}
|
||||
uncolorizeAll(node) {
|
||||
const allNodes = XpathUtil.evalXPath(`.//*[@${Attribute.ID}]`, node);
|
||||
allNodes.forEach((x) => this.uncolorize(x));
|
||||
}
|
||||
colorize(node) {
|
||||
const fore = addPrefix('foreground');
|
||||
if (node.hasAttribute(fore)) {
|
||||
node.setAttribute(fore + '-old', node.style.color);
|
||||
node.style.color = node.getAttribute(fore);
|
||||
}
|
||||
}
|
||||
uncolorize(node) {
|
||||
const fore = addPrefix('foreground') + '-old';
|
||||
if (node.hasAttribute(fore)) {
|
||||
node.style.color = node.getAttribute(fore);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user