case_proof.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { SemanticType } from '../semantic_tree/semantic_meaning.js';
  2. import { AbstractEnrichCase } from './abstract_enrich_case.js';
  3. import * as EnrichMathml from './enrich_mathml.js';
  4. import { setAttributes } from './enrich_attr.js';
  5. export class CaseProof extends AbstractEnrichCase {
  6. static test(semantic) {
  7. return (!!semantic.mathmlTree &&
  8. (semantic.type === SemanticType.INFERENCE ||
  9. semantic.type === SemanticType.PREMISES));
  10. }
  11. constructor(semantic) {
  12. super(semantic);
  13. this.mml = semantic.mathmlTree;
  14. }
  15. getMathml() {
  16. if (!this.semantic.childNodes.length) {
  17. return this.mml;
  18. }
  19. this.semantic.contentNodes.forEach(function (x) {
  20. EnrichMathml.walkTree(x);
  21. setAttributes(x.mathmlTree, x);
  22. });
  23. this.semantic.childNodes.forEach(function (x) {
  24. EnrichMathml.walkTree(x);
  25. });
  26. setAttributes(this.mml, this.semantic);
  27. if (this.mml.getAttribute('data-semantic-id') ===
  28. this.mml.getAttribute('data-semantic-parent')) {
  29. this.mml.removeAttribute('data-semantic-parent');
  30. }
  31. return this.mml;
  32. }
  33. }