예제 #1
0
 def _answer_query_using_plover(
     qg: QueryGraph, log: ARAXResponse
 ) -> Tuple[Dict[str, Dict[str, Set[Union[str, int]]]], int]:
     rtxc = RTXConfiguration()
     rtxc.live = "Production"
     log.debug(f"Sending query to Plover")
     response = requests.post(f"{rtxc.plover_url}/query",
                              json=qg.to_dict(),
                              headers={'accept': 'application/json'})
     if response.status_code == 200:
         log.debug(f"Got response back from Plover")
         return response.json(), response.status_code
     else:
         log.warning(
             f"Plover returned a status code of {response.status_code}. Response was: {response.text}"
         )
         return dict(), response.status_code
예제 #2
0
파일: kg2_querier.py 프로젝트: RTXteam/RTX
 def _answer_query_using_plover(qg: QueryGraph, log: ARAXResponse) -> Tuple[Dict[str, Dict[str, Union[set, dict]]], int]:
     rtxc = RTXConfiguration()
     rtxc.live = "Production"
     # First prep the query graph (requires some minor additions for Plover)
     dict_qg = qg.to_dict()
     dict_qg["include_metadata"] = True  # Ask plover to return node/edge objects (not just IDs)
     dict_qg["respect_predicate_symmetry"] = True  # Ignore direction for symmetric predicate, enforce for asymmetric
     # Allow subclass_of reasoning for qnodes with a small number of curies
     for qnode in dict_qg["nodes"].values():
         if qnode.get("ids") and len(qnode["ids"]) < 5:
             if "allow_subclasses" not in qnode or qnode["allow_subclasses"] is None:
                 qnode["allow_subclasses"] = True
     # Then send the actual query
     response = requests.post(f"{rtxc.plover_url}/query", json=dict_qg, timeout=60,
                              headers={'accept': 'application/json'})
     if response.status_code == 200:
         log.debug(f"Got response back from Plover")
         return response.json(), response.status_code
     else:
         log.warning(f"Plover returned a status code of {response.status_code}. Response was: {response.text}")
         return dict(), response.status_code