Skip to content

Commit

Permalink
Merge branch 'main' into dshahi-parsers
Browse files Browse the repository at this point in the history
# Conflicts:
#	skema/skema-rs/mathml/src/parsers/generic_mathml.rs
  • Loading branch information
ualiangzhang committed Feb 26, 2024
2 parents affe864 + 2004566 commit 14a5eee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion skema/rest/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class EquationsToAMRs(BaseModel):
]],
)
model: Literal["regnet", "petrinet", "met", "gamr", "decapode"] = Field(
description="The model type", examples=[["gamr"], ["regnet"], ["petrinet"], ["met"], ["decapode"]]
description="The model type", examples=["gamr"]
)

class MmlToAMR(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion skema/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import List
from pathlib import Path
import httpx
import requests

from fastapi import APIRouter, Depends, File, UploadFile, FastAPI, Request
from starlette.responses import JSONResponse
Expand Down Expand Up @@ -79,7 +80,7 @@ async def equation_to_amrs(data: schema.EquationsToAMRs, client: httpx.AsyncClie
"""
eqns = utils.parse_equations(data.equations)
if data.model == "petrinet" or data.model == "regnet":
payload = {"mathml": data.equations, "model": data.model}
payload = {"mathml": eqns, "model": data.model}
res = await client.put(f"{SKEMA_RS_ADDESS}/mathml/amr", json=payload)
if res.status_code != 200:
res_new = await client.put(f"{SKEMA_RS_ADDESS}/mathml/g-amr", json=eqns)
Expand Down
39 changes: 35 additions & 4 deletions skema/skema-rs/mathml/src/parsers/generic_mathml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,30 @@ pub fn rparen(input: Span) -> IResult<Operator> {
Ok((s, op))
}

pub fn comma(input: Span) -> IResult<Operator> {
let (s, op) = value(Operator::Comma, ws(tag(",")))(input)?;
Ok((s, op))
}

pub fn period(input: Span) -> IResult<Operator> {
let (s, op) = value(Operator::Period, ws(tag(".")))(input)?;
Ok((s, op))
}

pub fn mean(input: Span) -> IResult<Operator> {
let (s, op) = value(Operator::Mean, ws(tag("¯")))(input)?;
Ok((s, op))
}

pub fn hat(input: Span) -> IResult<Operator> {
let (s, op) = value(Operator::Hat, alt((ws(tag("^")), ws(tag("&#x5E;")))))(input)?;
Ok((s, op))
}

pub fn grad(input: Span) -> IResult<Operator> {
let (s, op) = value(Operator::Grad, alt((ws(tag("∇")), ws(tag("&#x2207;")))))(input)?;
Ok((s, op))
}
pub fn dot(input: Span) -> IResult<Operator> {
let (s, op) = value(Operator::Dot, alt((ws(tag("⋅")), ws(tag("&#x22c5;")))))(input)?;
Ok((s, op))
Expand All @@ -236,12 +255,20 @@ pub fn cross(input: Span) -> IResult<Operator> {
Ok((s, op))
}

pub fn vector(input: Span) -> IResult<Operator> {
let (s, op) = value(Operator::Vector, alt((ws(tag("→")), ws(tag("&#x2192;")))))(input)?;
pub fn down_arrow(input: Span) -> IResult<Operator> {
let (s, op) = value(
Operator::DownArrow,
alt((ws(tag("↓")), ws(tag("&#x2193;")))),
)(input)?;
Ok((s, op))
}

pub fn int(input: Span) -> IResult<Operator> {
let (s, op) = value(Operator::Int, alt((ws(tag("∫")), ws(tag("&#x222b;")))))(input)?;
Ok((s, op))
}

pub fn operator_other(input: Span) -> IResult<Operator> {
fn operator_other(input: Span) -> IResult<Operator> {
let (s, consumed) = ws(recognize(not_line_ending))(input)?;
let op = Operator::Other(consumed.to_string());
Ok((s, op))
Expand All @@ -255,11 +282,15 @@ pub fn operator(input: Span) -> IResult<Operator> {
lparen,
rparen,
mean,
hat,
multiply,
divide,
grad,
dot,
cross,
vector,
period,
down_arrow,
int,
operator_other,
))(input)?;
Ok((s, op))
Expand Down

0 comments on commit 14a5eee

Please sign in to comment.