Skip to content

Commit

Permalink
Merge pull request #740 from Speech-Rule-Engine/issue_733
Browse files Browse the repository at this point in the history
Fixes issue #733. Refactors combinechildrencontent interface.
  • Loading branch information
zorkow authored Nov 29, 2023
2 parents b814520 + 6224968 commit e036563
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion ts/enrich_mathml/enrich_mathml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export function walkTree(semantic: SemanticNode): Element {
setOperatorAttribute(semantic, newContent);
const newChildren = semantic.childNodes.map(walkTree);
const childrenList = SemanticSkeleton.combineContentChildren<Element>(
semantic,
semantic.type,
semantic.role,
newContent,
newChildren
);
Expand Down
3 changes: 2 additions & 1 deletion ts/semantic_tree/semantic_heuristics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ function rewriteCell(cell: SemanticNode, left?: boolean) {
const children = cell.childNodes;
rewriteFence(children[left ? children.length - 1 : 0]);
const newNodes = SemanticSkeleton.combineContentChildren<SemanticNode>(
cell,
cell.type,
cell.role,
cell.contentNodes,
cell.childNodes
);
Expand Down
18 changes: 13 additions & 5 deletions ts/semantic_tree/semantic_skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Engine from '../common/engine.js';

import * as XpathUtil from '../common/xpath_util.js';
import { Attribute as EnrichAttribute } from '../enrich_mathml/enrich_attr.js';
import { SemanticType } from './semantic_meaning.js';
import { SemanticType, SemanticRole } from './semantic_meaning.js';
import { SemanticNode } from './semantic_node.js';
import { SemanticTree } from './semantic_tree.js';

Expand Down Expand Up @@ -155,11 +155,12 @@ export class SemanticSkeleton {
* @returns The combined list.
*/
public static combineContentChildren<T>(
semantic: SemanticNode,
type: SemanticType,
_role: SemanticRole,
content: T[],
children: T[]
): T[] {
switch (semantic.type) {
switch (type) {
case SemanticType.RELSEQ:
case SemanticType.INFIXOP:
case SemanticType.MULTIREL:
Expand All @@ -168,16 +169,22 @@ export class SemanticSkeleton {
return content.concat(children);
case SemanticType.POSTFIXOP:
return children.concat(content);
case SemanticType.MATRIX:
case SemanticType.VECTOR:
case SemanticType.FENCED:
children.unshift(content[0]);
children.push(content[1]);
return children;
case SemanticType.CASES:
children.unshift(content[0]);
return children;
case SemanticType.APPL:
return [children[0], content[0], children[1]];
case SemanticType.ROOT:
return [children[1], children[0]];
return [children[0], children[1]];
case SemanticType.ROW:
case SemanticType.LINE:
// Adding the labels to the skeleton for explorative access.
if (content.length) {
children.unshift(content[0]);
}
Expand Down Expand Up @@ -286,7 +293,8 @@ export class SemanticSkeleton {
return node.id;
}
const children = SemanticSkeleton.combineContentChildren<SemanticNode>(
node,
node.type,
node.role,
node.contentNodes.map(function (x) {
return x;
}),
Expand Down
4 changes: 2 additions & 2 deletions ts/walker/semantic_walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export class SemanticWalker extends AbstractWalker<Focus> {
];
case SemanticType.ROOT:
return [
this.singletonFocus(children[1]),
this.singletonFocus(children[0])
this.singletonFocus(children[0]),
this.singletonFocus(children[1])
];
default:
return children.map(this.singletonFocus.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion ts/walker/syntax_walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class SyntaxWalker extends AbstractWalker<string> {
case SemanticType.APPL:
return [children[0], content[0], children[1]];
case SemanticType.ROOT:
return [children[1], children[0]];
return [children[0], children[1]];
default:
return children;
}
Expand Down

0 comments on commit e036563

Please sign in to comment.