From f85df16138a1400290291b63fcb9b3169d7335c3 Mon Sep 17 00:00:00 2001 From: Michel Dumontier Date: Tue, 27 Aug 2024 17:54:47 +0900 Subject: [PATCH] fixed formatting --- src/trapi_predict_kit/trapi.py | 7 +++++-- src/trapi_predict_kit/trapi_parser.py | 27 +++++++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/trapi_predict_kit/trapi.py b/src/trapi_predict_kit/trapi.py index 9ea33cc..5e5da94 100644 --- a/src/trapi_predict_kit/trapi.py +++ b/src/trapi_predict_kit/trapi.py @@ -1,7 +1,7 @@ +import logging import os import time from typing import Any, Callable, Dict, List, Optional -import logging from fastapi import Body, FastAPI, Request from fastapi.middleware.cors import CORSMiddleware @@ -319,8 +319,11 @@ def add_opentelemetry(app: FastAPI, service_name: str) -> None: RequestsInstrumentor().instrument() HTTPXClientInstrumentor().instrument() -# Filter out /health endpoint to stop flooding uvicorn log + +# Filter out /health endpoint to stop flooding uvicorn log class EndpointFilter(logging.Filter): def filter(self, record: logging.LogRecord) -> bool: return record.getMessage().find("/health") == -1 + + logging.getLogger("uvicorn.access").addFilter(EndpointFilter()) diff --git a/src/trapi_predict_kit/trapi_parser.py b/src/trapi_predict_kit/trapi_parser.py index 62d303c..9dc168f 100644 --- a/src/trapi_predict_kit/trapi_parser.py +++ b/src/trapi_predict_kit/trapi_parser.py @@ -275,18 +275,28 @@ def resolve_trapi_query(reasoner_query, endpoints_list, infores: str = ""): "score": association_score, # "dummy_score": 0.42, "scoring_method": "Model confidence between 0 and 1", - "edge_bindings": {edge_qg_id: [{"id": edge_kg_id, - "attributes": [],}]}, + "edge_bindings": { + edge_qg_id: [ + { + "id": edge_kg_id, + "attributes": [], + } + ] + }, } ], } result["node_bindings"][query_plan[edge_id]["qg_subject_node_id"]] = [ - {"id": association["subject"], - "attributes": [],} + { + "id": association["subject"], + "attributes": [], + } ] result["node_bindings"][query_plan[edge_id]["qg_object_node_id"]] = [ - {"id": association["object"], - "attributes": [],} + { + "id": association["object"], + "attributes": [], + } ] query_results.append(result) @@ -301,10 +311,7 @@ def resolve_trapi_query(reasoner_query, endpoints_list, infores: str = ""): node_category = "biolink:" + node_category.capitalize() if isinstance(node_category, str): node_category = [node_category] - node_to_add = { - "categories": node_category, - "attributes": [] - } + node_to_add = {"categories": node_category, "attributes": []} if "label" in properties and properties["label"]: node_to_add["name"] = properties["label"] knowledge_graph["nodes"][node_id] = node_to_add