def query(request_body, bypass_cache=None): # noqa: E501 """Query reasoner via one of several inputs # noqa: E501 :param request_body: Query information to be submitted :type request_body: dict | bytes :param bypass_cache: Set to true in order to bypass any possible cached response and try to answer the query over again :type bypass_cache: bool :rtype: Response """ # Note that we never even get here if the request_body is not schema-valid JSON query = connexion.request.get_json() araxq = ARAXQuery() if "asynchronous" in query and query['asynchronous'].lower() == 'stream': # Return a stream of data to let the client know what's going on return Response(araxq.query_return_stream(query), mimetype='text/plain') # Else perform the query and return the result else: envelope = araxq.query_return_message(query) return envelope
def asyncquery(request_body): # noqa: E501 """Query reasoner via one of several inputs # noqa: E501 :param request_body: Query information to be submitted :type request_body: Dict[str, ] :rtype: Response """ # Note that we never even get here if the request_body is not schema-valid JSON query = connexion.request.get_json() #### Record the remote IP address in the query for now so it is available downstream try: query['remote_address'] = connexion.request.headers['x-forwarded-for'] except: query['remote_address'] = '???' araxq = ARAXQuery() envelope = araxq.query_return_message(query, mode='asynchronous') http_status = 200 if hasattr(envelope, 'http_status'): http_status = envelope.http_status return (envelope, http_status)
def query(body): # noqa: E501 """Query ARAX via one of several inputs # noqa: E501 :param body: Query information to be submitted :type body: dict | bytes :rtype: Message """ if connexion.request.is_json: query = connexion.request.get_json() araxq = ARAXQuery() if "asynchronous" in query and query['asynchronous'].lower() == 'stream': # Return a stream of data to let the client know what's going on return Response(araxq.query_return_stream(query),mimetype='text/plain') else: message = araxq.query_return_message(query) return message
def main(): #### Create an RTXQuery object araxq = ARAXQuery() #### Fill out a one hop query acetaminophen to proteins query = { "previous_message_processing_plan": { "previous_message_uris": ["https://arax.ncats.io/api/rtx/v1/message/2"], "processing_actions": [ "filter(maximum_results=10)", "return(message=false,store=false)" ] } } #### Run the query and print the result message = araxq.query_return_message(query) print(json.dumps(message.to_dict(), sort_keys=True, indent=2))