Skip to content

Commit

Permalink
Merge pull request #2105 from RTXteam/master
Browse files Browse the repository at this point in the history
for KG2.8.4 deployment
  • Loading branch information
saramsey authored Aug 17, 2023
2 parents 16b3a03 + ba93dbd commit 4fc58b1
Show file tree
Hide file tree
Showing 19 changed files with 7,188 additions and 7,847 deletions.
76 changes: 40 additions & 36 deletions code/ARAX/ARAXQuery/ARAX_expander.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ def describe_me(self):
f"google distance (NGD) database to expand "
"a query graph; it returns edges between nodes with an NGD value below a certain "
"threshold. This threshold is currently hardcoded as 0.5, though this will be made "
"configurable/smarter in the future.\n"
"2. DTD: The 'infores:arax-drug-treats-disease' KP uses ARAX's in-house drug-treats-disease (DTD) database (built from GraphSage model) to expand "
"a query graph; it returns edges between nodes with a DTD probability above a certain "
"threshold. The default threshold is currently set to 0.8. If you set this threshold below 0.8, you should also "
"set DTD_slow_mode=True otherwise a warninig will occur. This is because the current DTD database only stores the pre-calcualted "
"DTD probability above or equal to 0.8. Therefore, if an user set threshold below 0.8, it will automatically switch to call DTD model "
"to do a real-time calculation and this will be quite time-consuming. In addition, if you call DTD database, your query node type would be checked. "
"In other words, the query node has to have a sysnonym which is drug or disease. If you don't want to check node type, set DTD_slow_mode=true "
"to call DTD model to do a real-time calculation.",
"configurable/smarter in the future.\n",
# "2. DTD: The 'infores:arax-drug-treats-disease' KP uses ARAX's in-house drug-treats-disease (DTD) database (built from GraphSage model) to expand "
# "a query graph; it returns edges between nodes with a DTD probability above a certain "
# "threshold. The default threshold is currently set to 0.8. If you set this threshold below 0.8, you should also "
# "set DTD_slow_mode=True otherwise a warninig will occur. This is because the current DTD database only stores the pre-calcualted "
# "DTD probability above or equal to 0.8. Therefore, if an user set threshold below 0.8, it will automatically switch to call DTD model "
# "to do a real-time calculation and this will be quite time-consuming. In addition, if you call DTD database, your query node type would be checked. "
# "In other words, the query node has to have a sysnonym which is drug or disease. If you don't want to check node type, set DTD_slow_mode=true "
# "to call DTD model to do a real-time calculation.",
"parameters": self.get_parameter_info_dict()
}
return [command_definition]
Expand Down Expand Up @@ -152,26 +152,26 @@ def get_parameter_info_dict():
"description": "Whether to omit supporting data on nodes/edges in the results (e.g., publications, "
"description, etc.)."
},
"DTD_threshold": {
"is_required": False,
"examples": [0.8, 0.5],
"min": 0,
"max": 1,
"default": 0.8,
"type": "float",
"description": "Applicable only when the 'infores:arax-drug-treats-disease' KP is used. "
"Defines what cut-off/threshold to use for expanding the DTD virtual edges."
},
"DTD_slow_mode": {
"is_required": False,
"examples": ["true", "false"],
"enum": ["true", "false", "True", "False", "t", "f", "T", "F"],
"default": "false",
"type": "boolean",
"description": "Applicable only when the 'infores:arax-drug-treats-disease' KP is used. "
"Specifies whether to call DTD model rather than DTD database to do a real-time "
"calculation for DTD probability."
}
# "DTD_threshold": {
# "is_required": False,
# "examples": [0.8, 0.5],
# "min": 0,
# "max": 1,
# "default": 0.8,
# "type": "float",
# "description": "Applicable only when the 'infores:arax-drug-treats-disease' KP is used. "
# "Defines what cut-off/threshold to use for expanding the DTD virtual edges."
# },
# "DTD_slow_mode": {
# "is_required": False,
# "examples": ["true", "false"],
# "enum": ["true", "false", "True", "False", "t", "f", "T", "F"],
# "default": "false",
# "type": "boolean",
# "description": "Applicable only when the 'infores:arax-drug-treats-disease' KP is used. "
# "Specifies whether to call DTD model rather than DTD database to do a real-time "
# "calculation for DTD probability."
# }
}
return parameter_info_dict

Expand Down Expand Up @@ -724,7 +724,7 @@ def apply(self, response, input_parameters, mode: str = "ARAX"):
kg = message.knowledge_graph
log.info(f"After Expand, the KG has {len(kg.nodes)} nodes and {len(kg.edges)} edges "
f"({eu.get_printable_counts_by_qg_id(overarching_kg)})")

return response

async def _expand_edge_async(self, edge_qg: QueryGraph, kp_to_use: str, input_parameters: Dict[str, any],
Expand Down Expand Up @@ -756,8 +756,10 @@ async def _expand_edge_async(self, edge_qg: QueryGraph, kp_to_use: str, input_pa
log.update_query_plan(qedge_key, kp_to_use, "Waiting", waiting_message)
start = time.time()
if kp_to_use == 'infores:arax-drug-treats-disease':
from Expand.DTD_querier import DTDQuerier
kp_querier = DTDQuerier(log)
# from Expand.DTD_querier import DTDQuerier
# kp_querier = DTDQuerier(log)
log.warning(f"DTD KP has been replaced with xDTD and thus is currently disabled.")
return answer_kg, log
else:
from Expand.ngd_querier import NGDQuerier
kp_querier = NGDQuerier(log)
Expand Down Expand Up @@ -806,6 +808,8 @@ async def _expand_edge_async(self, edge_qg: QueryGraph, kp_to_use: str, input_pa
answer_kg = self._remove_self_edges(answer_kg, kp_to_use, log)

return answer_kg, log



def _expand_edge_kg2_local(self, one_hop_qg: QueryGraph, log: ARAXResponse) -> Tuple[QGOrganizedKnowledgeGraph, ARAXResponse]:
qedge_key = next(qedge_key for qedge_key in one_hop_qg.edges)
Expand Down Expand Up @@ -855,10 +859,10 @@ def _expand_edge(self, edge_qg: QueryGraph, kp_to_use: str, input_parameters: Di

# Route this query to the proper place depending on the KP
try:
if kp_to_use == 'infores:arax-drug-treats-disease':
from Expand.DTD_querier import DTDQuerier
kp_querier = DTDQuerier(log)
elif kp_to_use == 'infores:arax-normalized-google-distance':
# if kp_to_use == 'infores:arax-drug-treats-disease':
# from Expand.DTD_querier import DTDQuerier
# kp_querier = DTDQuerier(log)
if kp_to_use == 'infores:arax-normalized-google-distance':
from Expand.ngd_querier import NGDQuerier
kp_querier = NGDQuerier(log)
else:
Expand Down
Loading

0 comments on commit 4fc58b1

Please sign in to comment.