Skip to content

Commit

Permalink
[Equations] Support the mixed LaTeX and MathML in eqns2met (#813)
Browse files Browse the repository at this point in the history
## Summary of Changes
Support the mixed LaTeX and MathML in eqns2met

---------

Co-authored-by: Deepsana Shahi <[email protected]>
  • Loading branch information
ualiangzhang and Deepsana Shahi authored Feb 22, 2024
1 parent ed3660a commit f1482c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
31 changes: 17 additions & 14 deletions skema/rest/tests/test_eqns_to_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@

@pytest.mark.ci_only
@pytest.mark.asyncio
async def test_post_eqns_to_mets_latex():
async def test_post_eqns_to_mets_mathml_latex():
"""
Test case for /equations-to-met.
"""
latex_equations = ["E=mc^2", "c=\\frac{a}{b}"]
latex_equations = [
"""
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>E</mi>
<mo>=</mo>
<mi>m</mi>
<msup>
<mi>c</mi>
<mn>2</mn>
</msup>
</math>
""",
"c=\\frac{a}{b}",
]

endpoint = "/equations-to-met"

Expand Down Expand Up @@ -125,22 +138,12 @@ async def test_post_eqns_to_mets_latex():

@pytest.mark.ci_only
@pytest.mark.asyncio
async def test_post_eqns_to_mets_mathml():
async def test_post_eqns_to_mets_latex_mathml():
"""
Test case for /equations-to-met.
"""
mathml_equations = [
"""
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>E</mi>
<mo>=</mo>
<mi>m</mi>
<msup>
<mi>c</mi>
<mn>2</mn>
</msup>
</math>
""",
"E=mc^2",
"""
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>c</mi>
Expand Down
28 changes: 12 additions & 16 deletions skema/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,12 @@ async def equations_to_met(data: schema.EquationToMET, client: httpx.AsyncClient
print(r.json())
```
"""
if "</math>" in data.equations[0]:
eqns: List[str] = [
utils.clean_mml(mml) for mml in data.equations
]
else:
eqns: List[str] = [
utils.clean_mml(eqn2mml.get_mathml_from_latex(tex)) for tex in data.equations
]
eqns: List[str] = []
for eqn in data.equations:
if "</math>" in eqn:
eqns.append(utils.clean_mml(eqn))
else:
eqns.append(utils.clean_mml(eqn2mml.get_mathml_from_latex(eqn)))

res = await client.put(f"{SKEMA_RS_ADDESS}/mathml/met", json=eqns)
if res.status_code != 200:
Expand Down Expand Up @@ -296,14 +294,12 @@ async def equations_to_gamr(data: schema.EquationToMET, client: httpx.AsyncClien
print(r.json())
```
"""
if "</math>" in data.equations[0]:
eqns: List[str] = [
utils.clean_mml(mml) for mml in data.equations
]
else:
eqns: List[str] = [
utils.clean_mml(eqn2mml.get_mathml_from_latex(tex)) for tex in data.equations
]
eqns: List[str] = []
for eqn in data.equations:
if "</math>" in eqn:
eqns.append(utils.clean_mml(eqn))
else:
eqns.append(utils.clean_mml(eqn2mml.get_mathml_from_latex(eqn)))

res = await client.put(f"{SKEMA_RS_ADDESS}/mathml/g-amr", json=eqns)
if res.status_code != 200:
Expand Down

0 comments on commit f1482c8

Please sign in to comment.