Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/limit issue #752

Merged
merged 7 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ts/semantic_tree/semantic_annotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class SemanticAnnotator {
*/
public annotate(node: SemanticNode) {
node.childNodes.forEach(this.annotate.bind(this));
node.contentNodes.forEach(this.annotate.bind(this));
node.addAnnotation(this.domain, this.func(node));
}
}
Expand Down Expand Up @@ -81,6 +82,9 @@ export class SemanticVisitor {
for (let i = 0, child; (child = node.childNodes[i]); i++) {
result = this.visit(child, result[1] as { [key: string]: any });
}
for (let i = 0, content; (content = node.contentNodes[i]); i++) {
result = this.visit(content, result[1] as { [key: string]: any });
}
return result;
}
}
3 changes: 3 additions & 0 deletions ts/semantic_tree/semantic_mathml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ export class SemanticMathml extends SemanticAbstractParser<Element> {
}
const label = this.parse(children[0]);
label.role = SemanticRole.LABEL;
if (label.childNodes[0]?.type === SemanticType.TEXT) {
label.childNodes[0].role = SemanticRole.LABEL;
}
const newNode = this.getFactory().makeBranchNode(
SemanticType.ROW,
this.parseList(children.slice(1)),
Expand Down
4 changes: 2 additions & 2 deletions ts/semantic_tree/semantic_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class SemanticNode {
if (this.textContent === content) {
return;
}
const meaning = SemanticMap.Meaning.get(content);
const meaning = SemanticMap.Meaning.get(content.replace(/\s/g, ' '));
this.textContent = content;
this.role = meaning.role;
this.type = meaning.type;
Expand Down Expand Up @@ -667,7 +667,7 @@ export class SemanticNode {
*/
private addAnnotation_(domain: string, annotation: string) {
const content = this.annotation[domain];
if (content) {
if (content && !content.includes(annotation)) {
content.push(annotation);
} else {
this.annotation[domain] = [annotation];
Expand Down
3 changes: 2 additions & 1 deletion ts/speech_rules/clearspeak_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ export function isSmallVulgarFraction(node: Element): Element[] {
*/
function isUnitExpression(node: SemanticNode): boolean {
return (
node.type === SemanticType.TEXT ||
(node.type === SemanticType.TEXT &&
node.role !== SemanticRole.LABEL) ||
(node.type === SemanticType.PUNCTUATED &&
node.role === SemanticRole.TEXT &&
isNumber_(node.childNodes[0]) &&
Expand Down
4 changes: 2 additions & 2 deletions ts/speech_rules/nemeth_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export function relationIterator(
const childNodes = nodes.slice(0);
let first = true;
let parentNode = nodes[0].parentNode.parentNode as Element;
let match = parentNode.getAttribute('annotation').match(/depth:(\d+)/);
let match = parentNode.getAttribute('annotation')?.match(/depth:(\d+)/);
let depth = match ? match[1] : '';
let contentNodes: Element[];
if (nodes.length > 0) {
Expand Down Expand Up @@ -454,7 +454,7 @@ export function contentIterator(
) {
let func = suCI(nodes, context);
let parentNode = nodes[0].parentNode.parentNode as Element;
let match = parentNode.getAttribute('annotation').match(/depth:(\d+)/);
let match = parentNode.getAttribute('annotation')?.match(/depth:(\d+)/);
let depth = match ? match[1] : '';
return function() {
const descrs = func();
Expand Down
Loading