Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Equations] Support the mixed LaTeX and MathML in eqns2met #813

Merged
merged 16 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading