case_double_script.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CaseDoubleScript = void 0;
  4. const DomUtil = require("../common/dom_util.js");
  5. const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
  6. const semantic_util_js_1 = require("../semantic_tree/semantic_util.js");
  7. const abstract_enrich_case_js_1 = require("./abstract_enrich_case.js");
  8. const EnrichMathml = require("./enrich_mathml.js");
  9. const enrich_attr_js_1 = require("./enrich_attr.js");
  10. class CaseDoubleScript extends abstract_enrich_case_js_1.AbstractEnrichCase {
  11. static test(semantic) {
  12. if (!semantic.mathmlTree || !semantic.childNodes.length) {
  13. return false;
  14. }
  15. const mmlTag = DomUtil.tagName(semantic.mathmlTree);
  16. const role = semantic.childNodes[0].role;
  17. return ((mmlTag === semantic_util_js_1.MMLTAGS.MSUBSUP && role === semantic_meaning_js_1.SemanticRole.SUBSUP) ||
  18. (mmlTag === semantic_util_js_1.MMLTAGS.MUNDEROVER && role === semantic_meaning_js_1.SemanticRole.UNDEROVER));
  19. }
  20. constructor(semantic) {
  21. super(semantic);
  22. this.mml = semantic.mathmlTree;
  23. }
  24. getMathml() {
  25. const ignore = this.semantic.childNodes[0];
  26. const baseSem = ignore.childNodes[0];
  27. const supSem = this.semantic.childNodes[1];
  28. const subSem = ignore.childNodes[1];
  29. const supMml = EnrichMathml.walkTree(supSem);
  30. const baseMml = EnrichMathml.walkTree(baseSem);
  31. const subMml = EnrichMathml.walkTree(subSem);
  32. (0, enrich_attr_js_1.setAttributes)(this.mml, this.semantic);
  33. this.mml.setAttribute(enrich_attr_js_1.Attribute.CHILDREN, (0, enrich_attr_js_1.makeIdList)([baseSem, subSem, supSem]));
  34. [baseMml, subMml, supMml].forEach((child) => EnrichMathml.getInnerNode(child).setAttribute(enrich_attr_js_1.Attribute.PARENT, this.mml.getAttribute(enrich_attr_js_1.Attribute.ID)));
  35. this.mml.setAttribute(enrich_attr_js_1.Attribute.TYPE, ignore.role);
  36. EnrichMathml.addCollapsedAttribute(this.mml, [
  37. this.semantic.id,
  38. [ignore.id, baseSem.id, subSem.id],
  39. supSem.id
  40. ]);
  41. return this.mml;
  42. }
  43. }
  44. exports.CaseDoubleScript = CaseDoubleScript;