Skip to content

Commit

Permalink
Bugfix - xpath for first apply node corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
vstange authored and physikerwelt committed Jul 11, 2017
1 parent fdee99f commit 3f822d1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static Node getFirstApplyNode(CMMLInfo cmmlInfo) throws XPathExpressionEx
applyRoot = getElement(cmmlInfo, "*//m:semantics/m:apply", xpath);
if (applyRoot == null) {
// 3. try to take the apply right beneath the math elements
applyRoot = getElement(cmmlInfo, "*//m:semantics/m:apply", xpath);
applyRoot = getElement(cmmlInfo, "*:math/m:apply", xpath);
}
}
return applyRoot;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
package com.formulasearchengine.mathmlsim.similarity.util;

import com.formulasearchengine.mathmltools.mml.CMMLInfo;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import org.w3c.dom.Node;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

/**
* @author Vincent Stange
*/
public class CMMLHelperTest {

@Test
public void getFirstApplyNode() throws IOException, ParserConfigurationException, XPathExpressionException {
// presentation mml with content semantics
assertThat(CMMLHelper.getFirstApplyNode(new CMMLInfo(getResourceFile("mathml_apply_1.xml"))), notNullValue());
// content mml with presentation semantics
assertThat(CMMLHelper.getFirstApplyNode(new CMMLInfo(getResourceFile("mathml_apply_2.xml"))), notNullValue());
// only content mml
assertThat(CMMLHelper.getFirstApplyNode(new CMMLInfo(getResourceFile("mathml_apply_3.xml"))), notNullValue());
// only presentation mml -> should be null
assertThat(CMMLHelper.getFirstApplyNode(new CMMLInfo(getResourceFile("mathml_apply_4.xml"))), nullValue());
}

@Test
public void getStrictCmml() throws Exception {
String mathml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" id=\"p1.1.m1.1\" class=\"ltx_Math\" alttext=\"\\EulerGamma@{z}=\\Int{0}{\\infty}@{t}{e^{-t}t^{z-1}}\" display=\"inline\">\n" +
Expand Down Expand Up @@ -102,4 +125,8 @@ public void getStrictCmml() throws Exception {
Assert.assertNotNull(CMMLHelper.getStrictCmml(mathml));
}

private String getResourceFile(String filename) throws IOException, ParserConfigurationException {
return IOUtils.toString(this.getClass().getResourceAsStream(filename), "UTF-8");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<math xmlns="http://www.w3.org/1998/Math/MathML">
<semantics id="p1.1.m1.1a">
<mrow id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml">
<mi id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi>
<mo id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo>
<mi id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi>
</mrow>
<annotation-xml encoding="MathML-Content" id="p1.1.m1.1b">
<apply id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4">
<plus id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/>
<ci id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">π‘Ž</ci>
<ci id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">𝑏</ci>
</apply>
</annotation-xml>
</semantics>
</math>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<math xmlns="http://www.w3.org/1998/Math/MathML">
<semantics id="p1.1.m1.1a">
<apply id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4">
<plus id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/>
<ci id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">π‘Ž</ci>
<ci id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">𝑏</ci>
</apply>
<annotation-xml encoding="MathML-Presentation" id="p1.1.m1.1b">
<mrow id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml">
<mi id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi>
<mo id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo>
<mi id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi>
</mrow>
</annotation-xml>
</semantics>
</math>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4">
<plus id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/>
<ci id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">π‘Ž</ci>
<ci id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">𝑏</ci>
</apply>
</math>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml">
<mi id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi>
<mo id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo>
<mi id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi>
</mrow>
</math>

0 comments on commit 3f822d1

Please sign in to comment.