add initial marp implementation with sample content and build configuration
This commit is contained in:
7
node_modules/speech-rule-engine/js/enrich_mathml/abstract_enrich_case.d.ts
generated
vendored
Normal file
7
node_modules/speech-rule-engine/js/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);
|
||||
}
|
||||
9
node_modules/speech-rule-engine/js/enrich_mathml/abstract_enrich_case.js
generated
vendored
Normal file
9
node_modules/speech-rule-engine/js/enrich_mathml/abstract_enrich_case.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AbstractEnrichCase = void 0;
|
||||
class AbstractEnrichCase {
|
||||
constructor(semantic) {
|
||||
this.semantic = semantic;
|
||||
}
|
||||
}
|
||||
exports.AbstractEnrichCase = AbstractEnrichCase;
|
||||
8
node_modules/speech-rule-engine/js/enrich_mathml/case_binomial.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
35
node_modules/speech-rule-engine/js/enrich_mathml/case_binomial.js
generated
vendored
Normal file
35
node_modules/speech-rule-engine/js/enrich_mathml/case_binomial.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseBinomial = void 0;
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const enrich_mathml_js_1 = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseBinomial extends abstract_enrich_case_js_1.AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return (!semantic.mathmlTree &&
|
||||
semantic.type === semantic_meaning_js_1.SemanticType.LINE &&
|
||||
semantic.role === semantic_meaning_js_1.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 = (0, enrich_mathml_js_1.walkTree)(child);
|
||||
if (this.mml.hasAttribute(enrich_attr_js_1.Attribute.TYPE)) {
|
||||
const mrow = (0, enrich_attr_js_1.addMrow)();
|
||||
DomUtil.replaceNode(this.mml, mrow);
|
||||
mrow.appendChild(this.mml);
|
||||
this.mml = mrow;
|
||||
}
|
||||
(0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
exports.CaseBinomial = CaseBinomial;
|
||||
8
node_modules/speech-rule-engine/js/enrich_mathml/case_double_script.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
44
node_modules/speech-rule-engine/js/enrich_mathml/case_double_script.js
generated
vendored
Normal file
44
node_modules/speech-rule-engine/js/enrich_mathml/case_double_script.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseDoubleScript = void 0;
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseDoubleScript extends abstract_enrich_case_js_1.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 === semantic_util_js_1.MMLTAGS.MSUBSUP && role === semantic_meaning_js_1.SemanticRole.SUBSUP) ||
|
||||
(mmlTag === semantic_util_js_1.MMLTAGS.MUNDEROVER && role === semantic_meaning_js_1.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);
|
||||
(0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
|
||||
this.mml.setAttribute(enrich_attr_js_1.Attribute.CHILDREN, (0, enrich_attr_js_1.makeIdList)([baseSem, subSem, supSem]));
|
||||
[baseMml, subMml, supMml].forEach((child) => EnrichMathml.getInnerNode(child).setAttribute(enrich_attr_js_1.Attribute.PARENT, this.mml.getAttribute(enrich_attr_js_1.Attribute.ID)));
|
||||
this.mml.setAttribute(enrich_attr_js_1.Attribute.TYPE, ignore.role);
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, [
|
||||
this.semantic.id,
|
||||
[ignore.id, baseSem.id, subSem.id],
|
||||
supSem.id
|
||||
]);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
exports.CaseDoubleScript = CaseDoubleScript;
|
||||
32
node_modules/speech-rule-engine/js/enrich_mathml/case_embellished.d.ts
generated
vendored
Normal file
32
node_modules/speech-rule-engine/js/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_;
|
||||
}
|
||||
215
node_modules/speech-rule-engine/js/enrich_mathml/case_embellished.js
generated
vendored
Normal file
215
node_modules/speech-rule-engine/js/enrich_mathml/case_embellished.js
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseEmbellished = void 0;
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const semantic_node_js_1 = require("../semantic_tree/semantic_node.js");
|
||||
const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const case_double_script_js_1 = require("./case_double_script.js");
|
||||
const case_multiscripts_js_1 = require("./case_multiscripts.js");
|
||||
const case_tensor_js_1 = require("./case_tensor.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseEmbellished extends abstract_enrich_case_js_1.AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return !!(semantic.mathmlTree &&
|
||||
semantic.fencePointer &&
|
||||
!semantic.mathmlTree.getAttribute('data-semantic-type'));
|
||||
}
|
||||
static makeEmptyNode_(id) {
|
||||
const mrow = (0, enrich_attr_js_1.addMrow)();
|
||||
const empty = new semantic_node_js_1.SemanticNode(id);
|
||||
empty.type = semantic_meaning_js_1.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 === semantic_meaning_js_1.SemanticType.EMPTY && !this.fencedMml.parentNode) {
|
||||
this.fencedMml.setAttribute(enrich_attr_js_1.Attribute.ADDED, 'true');
|
||||
this.cfenceMml.parentNode.insertBefore(this.fencedMml, this.cfenceMml);
|
||||
}
|
||||
this.getFencedMml_();
|
||||
const rewrite = this.rewrite_();
|
||||
return rewrite;
|
||||
}
|
||||
fencedElement(node) {
|
||||
return (node.type === semantic_meaning_js_1.SemanticType.FENCED ||
|
||||
node.type === semantic_meaning_js_1.SemanticType.MATRIX ||
|
||||
node.type === semantic_meaning_js_1.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_();
|
||||
(0, enrich_attr_js_1.setAttributes)(newNode, this.fenced.parent);
|
||||
while (!this.fencedElement(currentNode)) {
|
||||
const mml = currentNode.mathmlTree;
|
||||
const specialCase = this.specialCase_(currentNode, mml);
|
||||
if (specialCase) {
|
||||
currentNode = specialCase;
|
||||
}
|
||||
else {
|
||||
(0, enrich_attr_js_1.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 === semantic_util_js_1.MMLTAGS.MSUBSUP) {
|
||||
parent = semantic.childNodes[0];
|
||||
caller = case_double_script_js_1.CaseDoubleScript;
|
||||
}
|
||||
else if (mmlTag === semantic_util_js_1.MMLTAGS.MMULTISCRIPTS) {
|
||||
if (semantic.type === semantic_meaning_js_1.SemanticType.SUPERSCRIPT ||
|
||||
semantic.type === semantic_meaning_js_1.SemanticType.SUBSCRIPT) {
|
||||
caller = case_multiscripts_js_1.CaseMultiscripts;
|
||||
}
|
||||
else if (semantic.type === semantic_meaning_js_1.SemanticType.TENSOR) {
|
||||
caller = case_tensor_js_1.CaseTensor;
|
||||
}
|
||||
if (caller &&
|
||||
semantic.childNodes[0] &&
|
||||
semantic.childNodes[0].role === semantic_meaning_js_1.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 = (0, enrich_attr_js_1.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 = (0, enrich_attr_js_1.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(enrich_attr_js_1.Attribute.PARENT);
|
||||
x.childNodes[0].setAttribute(enrich_attr_js_1.Attribute.PARENT, parent);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.CaseEmbellished = CaseEmbellished;
|
||||
11
node_modules/speech-rule-engine/js/enrich_mathml/case_empheq.d.ts
generated
vendored
Normal file
11
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
83
node_modules/speech-rule-engine/js/enrich_mathml/case_empheq.js
generated
vendored
Normal file
83
node_modules/speech-rule-engine/js/enrich_mathml/case_empheq.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseEmpheq = void 0;
|
||||
const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
class CaseEmpheq extends abstract_enrich_case_js_1.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 = (0, enrich_attr_js_1.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) === semantic_util_js_1.MMLTAGS.MTABLE &&
|
||||
((_a = node.annotation['Emph']) === null || _a === void 0 ? void 0 : _a.length) &&
|
||||
node.annotation['Emph'][0] !== 'table')) {
|
||||
const newNode = (0, enrich_attr_js_1.addMrow)();
|
||||
(0, enrich_attr_js_1.setAttributes)(newNode, node);
|
||||
this.mrows.unshift(newNode);
|
||||
}
|
||||
else {
|
||||
if (DomUtil.tagName(node.mathmlTree) === semantic_util_js_1.MMLTAGS.MTABLE &&
|
||||
((_b = node.annotation['Emph']) === null || _b === void 0 ? void 0 : _b.length) &&
|
||||
node.annotation['Emph'][0] === 'table') {
|
||||
this.finalizeTable(node);
|
||||
return;
|
||||
}
|
||||
(0, enrich_attr_js_1.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) {
|
||||
(0, enrich_attr_js_1.setAttributes)(node.mathmlTree, node);
|
||||
node.contentNodes.forEach((x) => {
|
||||
EnrichMathml.walkTree(x);
|
||||
});
|
||||
node.childNodes.forEach((x) => {
|
||||
EnrichMathml.walkTree(x);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.CaseEmpheq = CaseEmpheq;
|
||||
9
node_modules/speech-rule-engine/js/enrich_mathml/case_limit.d.ts
generated
vendored
Normal file
9
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
48
node_modules/speech-rule-engine/js/enrich_mathml/case_limit.js
generated
vendored
Normal file
48
node_modules/speech-rule-engine/js/enrich_mathml/case_limit.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseLimit = void 0;
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseLimit extends abstract_enrich_case_js_1.AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
if (!semantic.mathmlTree || !semantic.childNodes.length) {
|
||||
return false;
|
||||
}
|
||||
const mmlTag = DomUtil.tagName(semantic.mathmlTree);
|
||||
const type = semantic.type;
|
||||
return (((type === semantic_meaning_js_1.SemanticType.LIMUPPER || type === semantic_meaning_js_1.SemanticType.LIMLOWER) &&
|
||||
(mmlTag === semantic_util_js_1.MMLTAGS.MSUBSUP || mmlTag === semantic_util_js_1.MMLTAGS.MUNDEROVER)) ||
|
||||
(type === semantic_meaning_js_1.SemanticType.LIMBOTH &&
|
||||
(mmlTag === semantic_util_js_1.MMLTAGS.MSUB ||
|
||||
mmlTag === semantic_util_js_1.MMLTAGS.MUNDER ||
|
||||
mmlTag === semantic_util_js_1.MMLTAGS.MSUP ||
|
||||
mmlTag === semantic_util_js_1.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 !== semantic_meaning_js_1.SemanticType.LIMBOTH &&
|
||||
this.mml.childNodes.length >= 3) {
|
||||
this.mml = EnrichMathml.introduceNewLayer([this.mml], this.semantic);
|
||||
}
|
||||
(0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
|
||||
if (!children[0].mathmlTree) {
|
||||
children[0].mathmlTree = this.semantic.mathmlTree;
|
||||
}
|
||||
children.forEach(CaseLimit.walkTree_);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
exports.CaseLimit = CaseLimit;
|
||||
8
node_modules/speech-rule-engine/js/enrich_mathml/case_line.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
27
node_modules/speech-rule-engine/js/enrich_mathml/case_line.js
generated
vendored
Normal file
27
node_modules/speech-rule-engine/js/enrich_mathml/case_line.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseLine = void 0;
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseLine extends abstract_enrich_case_js_1.AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return !!semantic.mathmlTree && semantic.type === semantic_meaning_js_1.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]);
|
||||
}
|
||||
(0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
exports.CaseLine = CaseLine;
|
||||
10
node_modules/speech-rule-engine/js/enrich_mathml/case_multiindex.d.ts
generated
vendored
Normal file
10
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
64
node_modules/speech-rule-engine/js/enrich_mathml/case_multiindex.js
generated
vendored
Normal file
64
node_modules/speech-rule-engine/js/enrich_mathml/case_multiindex.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseMultiindex = void 0;
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseMultiindex extends abstract_enrich_case_js_1.AbstractEnrichCase {
|
||||
static multiscriptIndex(index) {
|
||||
if (index.type === semantic_meaning_js_1.SemanticType.PUNCTUATED &&
|
||||
index.contentNodes[0].role === semantic_meaning_js_1.SemanticRole.DUMMY) {
|
||||
return EnrichMathml.collapsePunctuated(index);
|
||||
}
|
||||
EnrichMathml.walkTree(index);
|
||||
return index.id;
|
||||
}
|
||||
static createNone_(semantic) {
|
||||
const newNode = DomUtil.createElement('none');
|
||||
if (semantic) {
|
||||
(0, enrich_attr_js_1.setAttributes)(newNode, semantic);
|
||||
}
|
||||
newNode.setAttribute(enrich_attr_js_1.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(enrich_attr_js_1.Attribute.ID))) {
|
||||
child.setAttribute(enrich_attr_js_1.Attribute.PARENT, this.semantic.id.toString());
|
||||
childCounter++;
|
||||
}
|
||||
else if (!child ||
|
||||
index !==
|
||||
parseInt(EnrichMathml.getInnerNode(child).getAttribute(enrich_attr_js_1.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(enrich_attr_js_1.Attribute.PARENT, this.semantic.id.toString());
|
||||
childCounter++;
|
||||
}
|
||||
}
|
||||
};
|
||||
completeIndices(rightIndices);
|
||||
if (children[childCounter] &&
|
||||
DomUtil.tagName(children[childCounter]) !== semantic_util_js_1.MMLTAGS.MPRESCRIPTS) {
|
||||
this.mml.insertBefore(children[childCounter], DomUtil.createElement('mprescripts'));
|
||||
}
|
||||
else {
|
||||
childCounter++;
|
||||
}
|
||||
completeIndices(leftIndices);
|
||||
}
|
||||
}
|
||||
exports.CaseMultiindex = CaseMultiindex;
|
||||
7
node_modules/speech-rule-engine/js/enrich_mathml/case_multiscripts.d.ts
generated
vendored
Normal file
7
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
52
node_modules/speech-rule-engine/js/enrich_mathml/case_multiscripts.js
generated
vendored
Normal file
52
node_modules/speech-rule-engine/js/enrich_mathml/case_multiscripts.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseMultiscripts = void 0;
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const semantic_skeleton_js_1 = require("../semantic_tree/semantic_skeleton.js");
|
||||
const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
|
||||
const case_multiindex_js_1 = require("./case_multiindex.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseMultiscripts extends case_multiindex_js_1.CaseMultiindex {
|
||||
static test(semantic) {
|
||||
if (!semantic.mathmlTree) {
|
||||
return false;
|
||||
}
|
||||
const mmlTag = DomUtil.tagName(semantic.mathmlTree);
|
||||
return (mmlTag === semantic_util_js_1.MMLTAGS.MMULTISCRIPTS &&
|
||||
(semantic.type === semantic_meaning_js_1.SemanticType.SUPERSCRIPT ||
|
||||
semantic.type === semantic_meaning_js_1.SemanticType.SUBSCRIPT));
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
}
|
||||
getMathml() {
|
||||
(0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
|
||||
let baseSem, rsup, rsub;
|
||||
if (this.semantic.childNodes[0] &&
|
||||
this.semantic.childNodes[0].role === semantic_meaning_js_1.SemanticRole.SUBSUP) {
|
||||
const ignore = this.semantic.childNodes[0];
|
||||
baseSem = ignore.childNodes[0];
|
||||
rsup = case_multiindex_js_1.CaseMultiindex.multiscriptIndex(this.semantic.childNodes[1]);
|
||||
rsub = case_multiindex_js_1.CaseMultiindex.multiscriptIndex(ignore.childNodes[1]);
|
||||
const collapsed = [this.semantic.id, [ignore.id, baseSem.id, rsub], rsup];
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, collapsed);
|
||||
this.mml.setAttribute(enrich_attr_js_1.Attribute.TYPE, ignore.role);
|
||||
this.completeMultiscript(semantic_skeleton_js_1.SemanticSkeleton.interleaveIds(rsub, rsup), []);
|
||||
}
|
||||
else {
|
||||
baseSem = this.semantic.childNodes[0];
|
||||
rsup = case_multiindex_js_1.CaseMultiindex.multiscriptIndex(this.semantic.childNodes[1]);
|
||||
const collapsed = [this.semantic.id, baseSem.id, rsup];
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, collapsed);
|
||||
}
|
||||
const childIds = semantic_skeleton_js_1.SemanticSkeleton.collapsedLeafs(rsub || [], rsup);
|
||||
const base = EnrichMathml.walkTree(baseSem);
|
||||
EnrichMathml.getInnerNode(base).setAttribute(enrich_attr_js_1.Attribute.PARENT, this.semantic.id.toString());
|
||||
childIds.unshift(baseSem.id);
|
||||
this.mml.setAttribute(enrich_attr_js_1.Attribute.CHILDREN, childIds.join(','));
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
exports.CaseMultiscripts = CaseMultiscripts;
|
||||
8
node_modules/speech-rule-engine/js/enrich_mathml/case_proof.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
37
node_modules/speech-rule-engine/js/enrich_mathml/case_proof.js
generated
vendored
Normal file
37
node_modules/speech-rule-engine/js/enrich_mathml/case_proof.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseProof = void 0;
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseProof extends abstract_enrich_case_js_1.AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return (!!semantic.mathmlTree &&
|
||||
(semantic.type === semantic_meaning_js_1.SemanticType.INFERENCE ||
|
||||
semantic.type === semantic_meaning_js_1.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);
|
||||
(0, enrich_attr_js_1.setAttributes)(x.mathmlTree, x);
|
||||
});
|
||||
this.semantic.childNodes.forEach(function (x) {
|
||||
EnrichMathml.walkTree(x);
|
||||
});
|
||||
(0, enrich_attr_js_1.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;
|
||||
}
|
||||
}
|
||||
exports.CaseProof = CaseProof;
|
||||
9
node_modules/speech-rule-engine/js/enrich_mathml/case_table.d.ts
generated
vendored
Normal file
9
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
49
node_modules/speech-rule-engine/js/enrich_mathml/case_table.js
generated
vendored
Normal file
49
node_modules/speech-rule-engine/js/enrich_mathml/case_table.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseTable = void 0;
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseTable extends abstract_enrich_case_js_1.AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return (semantic.type === semantic_meaning_js_1.SemanticType.MATRIX ||
|
||||
semantic.type === semantic_meaning_js_1.SemanticType.VECTOR ||
|
||||
semantic.type === semantic_meaning_js_1.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) === semantic_util_js_1.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);
|
||||
}
|
||||
(0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
exports.CaseTable = CaseTable;
|
||||
7
node_modules/speech-rule-engine/js/enrich_mathml/case_tensor.d.ts
generated
vendored
Normal file
7
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
39
node_modules/speech-rule-engine/js/enrich_mathml/case_tensor.js
generated
vendored
Normal file
39
node_modules/speech-rule-engine/js/enrich_mathml/case_tensor.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseTensor = void 0;
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const semantic_skeleton_js_1 = require("../semantic_tree/semantic_skeleton.js");
|
||||
const case_multiindex_js_1 = require("./case_multiindex.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseTensor extends case_multiindex_js_1.CaseMultiindex {
|
||||
static test(semantic) {
|
||||
return !!semantic.mathmlTree && semantic.type === semantic_meaning_js_1.SemanticType.TENSOR;
|
||||
}
|
||||
constructor(semantic) {
|
||||
super(semantic);
|
||||
}
|
||||
getMathml() {
|
||||
EnrichMathml.walkTree(this.semantic.childNodes[0]);
|
||||
const lsub = case_multiindex_js_1.CaseMultiindex.multiscriptIndex(this.semantic.childNodes[1]);
|
||||
const lsup = case_multiindex_js_1.CaseMultiindex.multiscriptIndex(this.semantic.childNodes[2]);
|
||||
const rsub = case_multiindex_js_1.CaseMultiindex.multiscriptIndex(this.semantic.childNodes[3]);
|
||||
const rsup = case_multiindex_js_1.CaseMultiindex.multiscriptIndex(this.semantic.childNodes[4]);
|
||||
(0, enrich_attr_js_1.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 = semantic_skeleton_js_1.SemanticSkeleton.collapsedLeafs(lsub, lsup, rsub, rsup);
|
||||
childIds.unshift(this.semantic.childNodes[0].id);
|
||||
this.mml.setAttribute(enrich_attr_js_1.Attribute.CHILDREN, childIds.join(','));
|
||||
this.completeMultiscript(semantic_skeleton_js_1.SemanticSkeleton.interleaveIds(rsub, rsup), semantic_skeleton_js_1.SemanticSkeleton.interleaveIds(lsub, lsup));
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
exports.CaseTensor = CaseTensor;
|
||||
8
node_modules/speech-rule-engine/js/enrich_mathml/case_text.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/js/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;
|
||||
}
|
||||
28
node_modules/speech-rule-engine/js/enrich_mathml/case_text.js
generated
vendored
Normal file
28
node_modules/speech-rule-engine/js/enrich_mathml/case_text.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CaseText = void 0;
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
const enrich_attr_js_1 = require("./enrich_attr.js");
|
||||
class CaseText extends abstract_enrich_case_js_1.AbstractEnrichCase {
|
||||
static test(semantic) {
|
||||
return (semantic.type === semantic_meaning_js_1.SemanticType.PUNCTUATED &&
|
||||
(semantic.role === semantic_meaning_js_1.SemanticRole.TEXT ||
|
||||
semantic.contentNodes.every((x) => x.role === semantic_meaning_js_1.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);
|
||||
(0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
|
||||
this.mml.removeAttribute(enrich_attr_js_1.Attribute.CONTENT);
|
||||
EnrichMathml.addCollapsedAttribute(this.mml, collapsed);
|
||||
return this.mml;
|
||||
}
|
||||
}
|
||||
exports.CaseText = CaseText;
|
||||
6
node_modules/speech-rule-engine/js/enrich_mathml/enrich.d.ts
generated
vendored
Normal file
6
node_modules/speech-rule-engine/js/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;
|
||||
43
node_modules/speech-rule-engine/js/enrich_mathml/enrich.js
generated
vendored
Normal file
43
node_modules/speech-rule-engine/js/enrich_mathml/enrich.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.semanticMathmlNode = semanticMathmlNode;
|
||||
exports.semanticMathmlSync = semanticMathmlSync;
|
||||
exports.semanticMathml = semanticMathml;
|
||||
exports.testTranslation = testTranslation;
|
||||
exports.prepareMmlString = prepareMmlString;
|
||||
const debugger_js_1 = require("../common/debugger.js");
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const engine_js_1 = require("../common/engine.js");
|
||||
const Semantic = require("../semantic_tree/semantic.js");
|
||||
const EnrichMathml = require("./enrich_mathml.js");
|
||||
require("./enrich_case_factory.js");
|
||||
function semanticMathmlNode(mml) {
|
||||
const clone = DomUtil.cloneNode(mml);
|
||||
const tree = Semantic.getTree(clone);
|
||||
return EnrichMathml.enrich(clone, tree);
|
||||
}
|
||||
function semanticMathmlSync(expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
return semanticMathmlNode(mml);
|
||||
}
|
||||
function semanticMathml(expr, callback) {
|
||||
engine_js_1.EnginePromise.getall().then(() => {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
callback(semanticMathmlNode(mml));
|
||||
});
|
||||
}
|
||||
function testTranslation(expr) {
|
||||
debugger_js_1.Debugger.getInstance().init();
|
||||
const mml = semanticMathmlSync(prepareMmlString(expr));
|
||||
debugger_js_1.Debugger.getInstance().exit();
|
||||
return mml;
|
||||
}
|
||||
function prepareMmlString(expr) {
|
||||
if (!expr.match(/^<math/)) {
|
||||
expr = '<math>' + expr;
|
||||
}
|
||||
if (!expr.match(/\/math>$/)) {
|
||||
expr += '</math>';
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
30
node_modules/speech-rule-engine/js/enrich_mathml/enrich_attr.d.ts
generated
vendored
Normal file
30
node_modules/speech-rule-engine/js/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;
|
||||
109
node_modules/speech-rule-engine/js/enrich_mathml/enrich_attr.js
generated
vendored
Normal file
109
node_modules/speech-rule-engine/js/enrich_mathml/enrich_attr.js
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EnrichAttributes = exports.Attribute = void 0;
|
||||
exports.makeIdList = makeIdList;
|
||||
exports.setAttributes = setAttributes;
|
||||
exports.removeAttributePrefix = removeAttributePrefix;
|
||||
exports.addPrefix = addPrefix;
|
||||
exports.addMrow = addMrow;
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const Prefix = 'data-semantic-';
|
||||
var Attribute;
|
||||
(function (Attribute) {
|
||||
Attribute["ADDED"] = "data-semantic-added";
|
||||
Attribute["ALTERNATIVE"] = "data-semantic-alternative";
|
||||
Attribute["CHILDREN"] = "data-semantic-children";
|
||||
Attribute["COLLAPSED"] = "data-semantic-collapsed";
|
||||
Attribute["CONTENT"] = "data-semantic-content";
|
||||
Attribute["EMBELLISHED"] = "data-semantic-embellished";
|
||||
Attribute["FENCEPOINTER"] = "data-semantic-fencepointer";
|
||||
Attribute["FONT"] = "data-semantic-font";
|
||||
Attribute["ID"] = "data-semantic-id";
|
||||
Attribute["ANNOTATION"] = "data-semantic-annotation";
|
||||
Attribute["ATTRIBUTES"] = "data-semantic-attributes";
|
||||
Attribute["OPERATOR"] = "data-semantic-operator";
|
||||
Attribute["OWNS"] = "data-semantic-owns";
|
||||
Attribute["PARENT"] = "data-semantic-parent";
|
||||
Attribute["POSTFIX"] = "data-semantic-postfix";
|
||||
Attribute["PREFIX"] = "data-semantic-prefix";
|
||||
Attribute["ROLE"] = "data-semantic-role";
|
||||
Attribute["SPEECH"] = "data-semantic-speech";
|
||||
Attribute["STRUCTURE"] = "data-semantic-structure";
|
||||
Attribute["SUMMARY"] = "data-semantic-summary";
|
||||
Attribute["TYPE"] = "data-semantic-type";
|
||||
})(Attribute || (exports.Attribute = Attribute = {}));
|
||||
exports.EnrichAttributes = [
|
||||
Attribute.ADDED,
|
||||
Attribute.ALTERNATIVE,
|
||||
Attribute.CHILDREN,
|
||||
Attribute.COLLAPSED,
|
||||
Attribute.CONTENT,
|
||||
Attribute.EMBELLISHED,
|
||||
Attribute.FENCEPOINTER,
|
||||
Attribute.FONT,
|
||||
Attribute.ID,
|
||||
Attribute.ANNOTATION,
|
||||
Attribute.ATTRIBUTES,
|
||||
Attribute.OPERATOR,
|
||||
Attribute.OWNS,
|
||||
Attribute.PARENT,
|
||||
Attribute.POSTFIX,
|
||||
Attribute.PREFIX,
|
||||
Attribute.ROLE,
|
||||
Attribute.SPEECH,
|
||||
Attribute.STRUCTURE,
|
||||
Attribute.SUMMARY,
|
||||
Attribute.TYPE
|
||||
];
|
||||
function makeIdList(nodes) {
|
||||
return nodes
|
||||
.map(function (node) {
|
||||
return node.id;
|
||||
})
|
||||
.join(',');
|
||||
}
|
||||
function setAttributes(mml, semantic) {
|
||||
mml.setAttribute(Attribute.TYPE, semantic.type);
|
||||
const attributes = semantic.allAttributes();
|
||||
for (let i = 0, attr; (attr = attributes[i]); i++) {
|
||||
mml.setAttribute(Prefix + attr[0].toLowerCase(), attr[1]);
|
||||
}
|
||||
if (semantic.childNodes.length) {
|
||||
mml.setAttribute(Attribute.CHILDREN, makeIdList(semantic.childNodes));
|
||||
}
|
||||
if (semantic.contentNodes.length) {
|
||||
mml.setAttribute(Attribute.CONTENT, makeIdList(semantic.contentNodes));
|
||||
}
|
||||
if (semantic.parent) {
|
||||
mml.setAttribute(Attribute.PARENT, semantic.parent.id.toString());
|
||||
}
|
||||
const external = semantic.attributesXml();
|
||||
if (external) {
|
||||
mml.setAttribute(Attribute.ATTRIBUTES, external);
|
||||
}
|
||||
setPostfix(mml, semantic);
|
||||
}
|
||||
function setPostfix(mml, semantic) {
|
||||
const postfix = [];
|
||||
if (semantic.role === semantic_meaning_js_1.SemanticRole.MGLYPH) {
|
||||
postfix.push('image');
|
||||
}
|
||||
if (semantic.attributes['href']) {
|
||||
postfix.push('link');
|
||||
}
|
||||
if (postfix.length) {
|
||||
mml.setAttribute(Attribute.POSTFIX, postfix.join(' '));
|
||||
}
|
||||
}
|
||||
function removeAttributePrefix(mml) {
|
||||
return mml.toString().replace(new RegExp(Prefix, 'g'), '');
|
||||
}
|
||||
function addPrefix(attr) {
|
||||
return (Prefix + attr);
|
||||
}
|
||||
function addMrow() {
|
||||
const mrow = DomUtil.createElement('mrow');
|
||||
mrow.setAttribute(Attribute.ADDED, 'true');
|
||||
return mrow;
|
||||
}
|
||||
11
node_modules/speech-rule-engine/js/enrich_mathml/enrich_case.d.ts
generated
vendored
Normal file
11
node_modules/speech-rule-engine/js/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 {};
|
||||
13
node_modules/speech-rule-engine/js/enrich_mathml/enrich_case.js
generated
vendored
Normal file
13
node_modules/speech-rule-engine/js/enrich_mathml/enrich_case.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.factory = void 0;
|
||||
exports.getCase = getCase;
|
||||
function getCase(node) {
|
||||
for (let i = 0, enrich; (enrich = exports.factory[i]); i++) {
|
||||
if (enrich.test(node)) {
|
||||
return enrich.constr(node);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
exports.factory = [];
|
||||
1
node_modules/speech-rule-engine/js/enrich_mathml/enrich_case_factory.d.ts
generated
vendored
Normal file
1
node_modules/speech-rule-engine/js/enrich_mathml/enrich_case_factory.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
54
node_modules/speech-rule-engine/js/enrich_mathml/enrich_case_factory.js
generated
vendored
Normal file
54
node_modules/speech-rule-engine/js/enrich_mathml/enrich_case_factory.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const case_binomial_js_1 = require("./case_binomial.js");
|
||||
const case_double_script_js_1 = require("./case_double_script.js");
|
||||
const case_embellished_js_1 = require("./case_embellished.js");
|
||||
const case_empheq_js_1 = require("./case_empheq.js");
|
||||
const case_limit_js_1 = require("./case_limit.js");
|
||||
const case_line_js_1 = require("./case_line.js");
|
||||
const case_multiscripts_js_1 = require("./case_multiscripts.js");
|
||||
const case_proof_js_1 = require("./case_proof.js");
|
||||
const case_table_js_1 = require("./case_table.js");
|
||||
const case_tensor_js_1 = require("./case_tensor.js");
|
||||
const case_text_js_1 = require("./case_text.js");
|
||||
const enrich_case_js_1 = require("./enrich_case.js");
|
||||
enrich_case_js_1.factory.push(...[
|
||||
{
|
||||
test: case_limit_js_1.CaseLimit.test,
|
||||
constr: (node) => new case_limit_js_1.CaseLimit(node)
|
||||
},
|
||||
{
|
||||
test: case_embellished_js_1.CaseEmbellished.test,
|
||||
constr: (node) => new case_embellished_js_1.CaseEmbellished(node)
|
||||
},
|
||||
{
|
||||
test: case_double_script_js_1.CaseDoubleScript.test,
|
||||
constr: (node) => new case_double_script_js_1.CaseDoubleScript(node)
|
||||
},
|
||||
{
|
||||
test: case_tensor_js_1.CaseTensor.test,
|
||||
constr: (node) => new case_tensor_js_1.CaseTensor(node)
|
||||
},
|
||||
{
|
||||
test: case_multiscripts_js_1.CaseMultiscripts.test,
|
||||
constr: (node) => new case_multiscripts_js_1.CaseMultiscripts(node)
|
||||
},
|
||||
{ test: case_line_js_1.CaseLine.test, constr: (node) => new case_line_js_1.CaseLine(node) },
|
||||
{
|
||||
test: case_binomial_js_1.CaseBinomial.test,
|
||||
constr: (node) => new case_binomial_js_1.CaseBinomial(node)
|
||||
},
|
||||
{
|
||||
test: case_proof_js_1.CaseProof.test,
|
||||
constr: (node) => new case_proof_js_1.CaseProof(node)
|
||||
},
|
||||
{
|
||||
test: case_empheq_js_1.CaseEmpheq.test,
|
||||
constr: (node) => new case_empheq_js_1.CaseEmpheq(node)
|
||||
},
|
||||
{
|
||||
test: case_table_js_1.CaseTable.test,
|
||||
constr: (node) => new case_table_js_1.CaseTable(node)
|
||||
},
|
||||
{ test: case_text_js_1.CaseText.test, constr: (node) => new case_text_js_1.CaseText(node) }
|
||||
]);
|
||||
13
node_modules/speech-rule-engine/js/enrich_mathml/enrich_mathml.d.ts
generated
vendored
Normal file
13
node_modules/speech-rule-engine/js/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;
|
||||
555
node_modules/speech-rule-engine/js/enrich_mathml/enrich_mathml.js
generated
vendored
Normal file
555
node_modules/speech-rule-engine/js/enrich_mathml/enrich_mathml.js
generated
vendored
Normal file
@@ -0,0 +1,555 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.enrich = enrich;
|
||||
exports.walkTree = walkTree;
|
||||
exports.introduceNewLayer = introduceNewLayer;
|
||||
exports.ascendNewNode = ascendNewNode;
|
||||
exports.addCollapsedAttribute = addCollapsedAttribute;
|
||||
exports.cloneContentNode = cloneContentNode;
|
||||
exports.rewriteMfenced = rewriteMfenced;
|
||||
exports.setOperatorAttribute = setOperatorAttribute;
|
||||
exports.getInnerNode = getInnerNode;
|
||||
exports.collapsePunctuated = collapsePunctuated;
|
||||
const debugger_js_1 = require("../common/debugger.js");
|
||||
const DomUtil = require("../common/dom_util.js");
|
||||
const engine_js_1 = require("../common/engine.js");
|
||||
const semantic_attr_js_1 = require("../semantic_tree/semantic_attr.js");
|
||||
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
|
||||
const semantic_heuristic_factory_js_1 = require("../semantic_tree/semantic_heuristic_factory.js");
|
||||
const semantic_skeleton_js_1 = require("../semantic_tree/semantic_skeleton.js");
|
||||
const SemanticUtil = require("../semantic_tree/semantic_util.js");
|
||||
const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
|
||||
const EnrichAttr = require("./enrich_attr.js");
|
||||
const enrich_case_js_1 = require("./enrich_case.js");
|
||||
const SETTINGS = {
|
||||
collapsed: true,
|
||||
implicit: true,
|
||||
wiki: true
|
||||
};
|
||||
const IDS = new Map();
|
||||
function enrich(mml, semantic) {
|
||||
IDS.clear();
|
||||
const oldMml = DomUtil.cloneNode(mml);
|
||||
walkTree(semantic.root);
|
||||
if (engine_js_1.Engine.getInstance().structure) {
|
||||
mml.setAttribute(EnrichAttr.Attribute.STRUCTURE, semantic_skeleton_js_1.SemanticSkeleton.fromStructure(mml, semantic).toString());
|
||||
}
|
||||
debugger_js_1.Debugger.getInstance().generateOutput(() => [
|
||||
formattedOutput(oldMml, 'Original MathML', SETTINGS.wiki),
|
||||
formattedOutput(semantic, 'Semantic Tree', SETTINGS.wiki),
|
||||
formattedOutput(mml, 'Semantically enriched MathML', SETTINGS.wiki)
|
||||
]);
|
||||
return mml;
|
||||
}
|
||||
function walkTree(semantic) {
|
||||
debugger_js_1.Debugger.getInstance().output('WALKING START: ' + semantic.toString());
|
||||
const specialCase = (0, enrich_case_js_1.getCase)(semantic);
|
||||
let newNode;
|
||||
if (specialCase) {
|
||||
newNode = specialCase.getMathml();
|
||||
debugger_js_1.Debugger.getInstance().output('WALKING END: ' + semantic.toString());
|
||||
return ascendNewNode(newNode);
|
||||
}
|
||||
if (semantic.mathml.length === 1) {
|
||||
debugger_js_1.Debugger.getInstance().output('Walktree Case 0');
|
||||
if (!semantic.childNodes.length) {
|
||||
debugger_js_1.Debugger.getInstance().output('Walktree Case 0.1');
|
||||
newNode = semantic.mathml[0];
|
||||
EnrichAttr.setAttributes(newNode, semantic);
|
||||
debugger_js_1.Debugger.getInstance().output('WALKING END: ' + semantic.toString());
|
||||
return ascendNewNode(newNode);
|
||||
}
|
||||
const fchild = semantic.childNodes[0];
|
||||
if (semantic.childNodes.length === 1 &&
|
||||
fchild.type === semantic_meaning_js_1.SemanticType.EMPTY) {
|
||||
debugger_js_1.Debugger.getInstance().output('Walktree Case 0.2');
|
||||
newNode = semantic.mathml[0];
|
||||
EnrichAttr.setAttributes(newNode, semantic);
|
||||
newNode.appendChild(walkTree(fchild));
|
||||
debugger_js_1.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 = semantic_skeleton_js_1.SemanticSkeleton.combineContentChildren(semantic.type, semantic.role, newContent, newChildren);
|
||||
newNode = semantic.mathmlTree;
|
||||
if (newNode === null) {
|
||||
debugger_js_1.Debugger.getInstance().output('Walktree Case 1');
|
||||
newNode = introduceNewLayer(childrenList, semantic);
|
||||
}
|
||||
else {
|
||||
const attached = attachedElement(childrenList);
|
||||
debugger_js_1.Debugger.getInstance().output('Walktree Case 2');
|
||||
if (attached) {
|
||||
debugger_js_1.Debugger.getInstance().output('Walktree Case 2.1');
|
||||
newNode = parentNode(attached);
|
||||
}
|
||||
else {
|
||||
debugger_js_1.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_js_1.Debugger.getInstance().output('WALKING END: ' + semantic.toString());
|
||||
return ascendNewNode(newNode);
|
||||
}
|
||||
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_js_1.Debugger.getInstance().output('Walktree Case 1.1');
|
||||
newNode = EnrichAttr.addMrow();
|
||||
if (info === lcaType.PRUNED) {
|
||||
debugger_js_1.Debugger.getInstance().output('Walktree Case 1.1.0');
|
||||
newNode = introduceLayerAboveLca(newNode, lca.node, children);
|
||||
}
|
||||
else if (children[0]) {
|
||||
debugger_js_1.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_js_1.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 === semantic_meaning_js_1.SemanticRole.IMPLICIT &&
|
||||
semantic_heuristic_factory_js_1.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 = semantic_attr_js_1.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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
function addCollapsedAttribute(node, collapsed) {
|
||||
const skeleton = new semantic_skeleton_js_1.SemanticSkeleton(collapsed);
|
||||
node.setAttribute(EnrichAttr.Attribute.COLLAPSED, skeleton.toString());
|
||||
}
|
||||
function cloneContentNode(content) {
|
||||
if (content.mathml.length) {
|
||||
return walkTree(content);
|
||||
}
|
||||
const clone = SETTINGS.implicit
|
||||
? createInvisibleOperator(content)
|
||||
: EnrichAttr.addMrow();
|
||||
content.mathml = [clone];
|
||||
return clone;
|
||||
}
|
||||
function rewriteMfenced(mml) {
|
||||
if (DomUtil.tagName(mml) !== semantic_util_js_1.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;
|
||||
}
|
||||
function setOperatorAttribute(semantic, content) {
|
||||
const operator = semantic.type + (semantic.textContent ? ',' + semantic.textContent : '');
|
||||
content.forEach(function (c) {
|
||||
getInnerNode(c).setAttribute(EnrichAttr.Attribute.OPERATOR, operator);
|
||||
});
|
||||
}
|
||||
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) !==
|
||||
semantic_meaning_js_1.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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user