From 09d662717a968952a11206d7a77ecf3658cafa99 Mon Sep 17 00:00:00 2001 From: cbizon Date: Thu, 1 Jun 2023 14:24:22 -0400 Subject: [PATCH] Clear results (#183) * fixed ops * op tests * bump & comment * clear results when merging * bump --------- Co-authored-by: YaphetKG <45075777+YaphetKG@users.noreply.github.com> --- openapi-config.yaml | 2 +- src/service_aggregator.py | 10 +++++----- tests/test_query_exam.py | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/openapi-config.yaml b/openapi-config.yaml index c50faba..0b51bfe 100644 --- a/openapi-config.yaml +++ b/openapi-config.yaml @@ -11,7 +11,7 @@ servers: # url: http://127.0.0.1:5000 termsOfService: http://robokop.renci.org:7055/tos?service_long=ARAGORN&provider_long=RENCI title: ARAGORN -version: 2.4.7 +version: 2.4.8 tags: - name: translator - name: ARA diff --git a/src/service_aggregator.py b/src/service_aggregator.py index f5678dd..7d39262 100644 --- a/src/service_aggregator.py +++ b/src/service_aggregator.py @@ -790,7 +790,8 @@ def merge_answer(result_message, answer, results, qnode_ids): } mergedresult["analyses"].append(analysis) - result_message["message"]["results"].append(mergedresult) + #result_message["message"]["results"].append(mergedresult) + return mergedresult # TODO move into operations? Make a translator op out of this @@ -805,7 +806,9 @@ def merge_results_by_node(result_message, merge_qnode): # TODO : I'm sure there's a better way to handle this with asyncio new_results = [] for r in grouped_results: - merge_answer(result_message, r, grouped_results[r], original_qnodes) + new_result = merge_answer(result_message, r, grouped_results[r], original_qnodes) + new_results.append(new_result) + result_message["message"]["results"] = new_results return result_message @@ -886,9 +889,6 @@ async def answercoalesce(message, params, guid, coalesce_type="all") -> (dict, i url = f'{os.environ.get("ANSWER_COALESCE_URL", "https://answercoalesce.renci.org/1.3/coalesce/")}{coalesce_type}' # url = f'{os.environ.get("ANSWER_COALESCE_URL", "https://answer-coalesce.transltr.io/1.3/coalesce/")}{coalesce_type}' - # with open("crap.json", "w") as outf: - # json.dump(message, outf) - # With the current answercoalesce, we make the result list longer, and frequently much longer. If # we've already got 10s of thousands of results, let's skip this step... if "max_input_size" in params: diff --git a/tests/test_query_exam.py b/tests/test_query_exam.py index ded27b5..7fe6c53 100644 --- a/tests/test_query_exam.py +++ b/tests/test_query_exam.py @@ -1,9 +1,8 @@ import pytest -from src.service_aggregator import merge_answer, create_aux_graph, add_knowledge_edge +from src.service_aggregator import create_aux_graph, add_knowledge_edge, merge_results_by_node from reasoner_pydantic.results import Analysis, EdgeBinding, Result, NodeBinding from reasoner_pydantic.auxgraphs import AuxiliaryGraph -from reasoner_pydantic.message import Message, Response -from reasoner_pydantic.qgraph import QueryGraph +from reasoner_pydantic.message import Response def create_result_graph(): """Create a "treats" result graph with a query graph.""" @@ -29,7 +28,9 @@ def test_merge_answer(): result1 = create_result({"input":"MONDO:1234", "output":answer, "node2": "curie:3"}, {"g":"KEDGE:1", "f":"KEDGE:2"}).to_dict() result2 = create_result({"input":"MONDO:1234", "output":answer, "nodeX": "curie:8"}, {"q":"KEDGE:4", "z":"KEDGE:8"}).to_dict() results = [result1, result2] - merge_answer(result_message,frozenset([answer]),results,qnode_ids) + #In reality the results will be in the message and we want to be sure that they get cleared out. + result_message["message"]["results"] = results + merge_results_by_node(result_message,"output") assert len(result_message["message"]["results"]) == 1 assert len(result_message["message"]["results"][0]["node_bindings"]) == 2 assert len(result_message["message"]["results"][0]["analyses"]) == 1