Content scanFormulaNode ( Element formulaNode ) throws Exception { // first off, try scanning for a semantic split, this indicates multiple semantics Boolean containsSemantic = XMLHelper . getElementB ( formulaNode , xPath . compile ( "//m:semantics" ) ) != null ; // check if there is an annotationNode and if so check which semantics are present Element annotationNode = ( Element ) XMLHelper . getElementB ( formulaNode , xPath . compile ( "//m:annotation-xml" ) ) ; Boolean containsCMML = annotationNode != null && annotationNode . getAttribute ( "encoding" ) . equals ( "MathML-Content" ) ; Boolean containsPMML = annotationNode != null && annotationNode . getAttribute ( "encoding" ) . equals ( "MathML-Presentation" ) ; // if apply are present, the content semantics is used somewhere NonWhitespaceNodeList applyNodes = new NonWhitespaceNodeList ( XMLHelper . getElementsB ( formulaNode , xPath . compile ( "//m:apply" ) ) ) ; containsCMML |= applyNodes . getLength ( ) > 0 ; // if mrow nodes are present, the presentation semantic is used somewhere NonWhitespaceNodeList mrowNodes = new NonWhitespaceNodeList ( XMLHelper . getElementsB ( formulaNode , xPath . compile ( "//m:mrow" ) ) ) ; containsPMML |= mrowNodes . getLength ( ) > 0 ; // TODO the containCMML and -PMML can be more specific, e.g. check if identifiers of each semantics is present if ( containsSemantic ) { // if semantic separator is present plus one opposite semantic, we assume a LaTeXML produced content return containsCMML || containsPMML ? Content . mathml : Content . unknown ; } else { if ( containsCMML && containsPMML ) { // both semantics without semantic separator suggests broken syntax return Content . unknown ; } else if ( containsCMML ) { return Content . cmml ; } else if ( containsPMML ) { return Content . pmml ; } } // next, try to identify latex Element child = ( Element ) XMLHelper . getElementB ( formulaNode , "./*[1]" ) ; // if there is no child node, we currently anticipate some form of latex formula if ( child == null && StringUtils . isNotEmpty ( formulaNode . getTextContent ( ) ) ) { return Content . latex ; } // found nothing comprehensible return Content . unknown ; }
Tries to scan and interpret a formula node and guess its content format .