Coverage for skema/isa/isa_service.py: 90%
21 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
1# -*- coding: utf-8 -*-
3from fastapi import Depends, FastAPI, APIRouter, status
4from skema.isa.lib import align_mathml_eqs
5import skema.isa.data as isa_data
6from skema.rest import utils
7from pydantic import BaseModel
8import httpx
10from skema.rest.proxies import SKEMA_RS_ADDESS
12router = APIRouter()
15# Model for ISA_Result
16class ISA_Result(BaseModel):
17 matching_ratio: float = None
18 union_graph: str = None
21@router.get(
22 "/healthcheck",
23 summary="Status of ISA service",
24 response_model=int,
25 status_code=status.HTTP_200_OK
26)
27async def healthcheck(client: httpx.AsyncClient = Depends(utils.get_client)) -> int:
28 res = await client.get(f"{SKEMA_RS_ADDESS}/ping")
29 return res.status_code
32@router.post(
33 "/align-eqns",
34 summary="Align two MathML equations"
35)
36async def align_eqns(
37 mml1: str, mml2: str, mention_json1: str = "", mention_json2: str = ""
38) -> ISA_Result:
39 f"""
40 Endpoint for align two MathML equations.
42 ### Python example
44 ```
45 import requests
47 request = {{
48 "mml1": {isa_data.mml},
49 "mml2": {isa_data.mml}
50 }}
52 response=requests.post("/isa/align-eqns", json=request)
53 res = response.json()
54 """
55 (
56 matching_ratio,
57 num_diff_edges,
58 node_labels1,
59 node_labels2,
60 aligned_indices1,
61 aligned_indices2,
62 union_graph,
63 perfectly_matched_indices1,
64 ) = align_mathml_eqs(mml1, mml2, mention_json1, mention_json2)
65 return ISA_Result(
66 matching_ratio = matching_ratio,
67 union_graph = union_graph.to_string()
68 )
71app = FastAPI()
72app.include_router(
73 router,
74 prefix="/isa",
75 tags=["isa"],
76)