Skip to content

Commit

Permalink
Merge pull request #202 from ranking-agent/fix_rules_2
Browse files Browse the repository at this point in the history
fixed some more affects rules
  • Loading branch information
cbizon authored Jul 13, 2023
2 parents 910e016 + c637a14 commit 2f9a2ab
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/rules/Notes
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ The current rules have been created through a somewhat complicated process:
* remove subclass rules
5. By hand, I went into kara_typed_rules/rules_with_types_cleaned_finalized.json and changed "biolink:correlated_with"
to "biolink:positively_correlated_with"
6. For reasons unclear to me after all this, we still have a bunch of rules of this form:
?e activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a increased_activity_biolink:affects ?b
For these I go into hand and edit the rule to be
?e activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a increased_activity_biolink:affects ?b
Changing both the "Rule" and the edge in "template" by adding the correct qualifier

This process is obviously roundabout and we are going to clarify it in the next round of rule minings.
22 changes: 22 additions & 0 deletions src/rules/kara_typed_rules/check_rule_for_direction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import json

with open("rules_with_types_cleaned_finalized.json","r") as infile:
rules = json.load(infile)

for key,ruleset in rules.items():
print(key)
for rule in ruleset:
trapi = rule["template"]
edges = trapi["query_graph"]["edges"]
for edge_id,edge in edges.items():
if edge["predicates"][0] == "biolink:affects":
try:
qualifiers = edge["qualifier_constraints"][0]["qualifier_set"]
found = False
for qualifier in qualifiers:
if qualifier["qualifier_type_id"] == "biolink:object_direction_qualifier":
found = True
if not found:
print(" ",rule["Rule"])
except:
print(" ", rule["Rule"])
24 changes: 20 additions & 4 deletions src/rules/kara_typed_rules/rules_with_types_cleaned_finalized.json
Original file line number Diff line number Diff line change
Expand Up @@ -4863,7 +4863,7 @@
}
},
{
"Rule": "?e activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a increased_activity_biolink:affects ?b",
"Rule": "?e increased_activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a increased_activity_biolink:affects ?b",
"Head Coverage": "0.000698966",
"Std Confidence": "0.192307692",
"PCA Confidence": "0.3125",
Expand Down Expand Up @@ -4909,6 +4909,10 @@
{
"qualifier_type_id": "biolink:object_aspect_qualifier",
"qualifier_value": "activity_or_abundance"
},
{
"qualifier_type_id": "biolink:object_direction_qualifier",
"qualifier_value": "increased"
}
]
}
Expand Down Expand Up @@ -7751,7 +7755,7 @@
}
},
{
"Rule": "?e activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a decreased_activity_biolink:affects ?b",
"Rule": "?e decreased_activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a decreased_activity_biolink:affects ?b",
"Head Coverage": "0.000052801",
"Std Confidence": "0.104395604",
"PCA Confidence": "0.154471545",
Expand Down Expand Up @@ -7797,6 +7801,10 @@
{
"qualifier_type_id": "biolink:object_aspect_qualifier",
"qualifier_value": "activity_or_abundance"
},
{
"qualifier_type_id": "biolink:object_direction_qualifier",
"qualifier_value": "decreased"
}
]
}
Expand Down Expand Up @@ -8832,7 +8840,7 @@
}
},
{
"Rule": "?e activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a increased_activity_or_abundance_biolink:affects ?b",
"Rule": "?e increased_activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a increased_activity_or_abundance_biolink:affects ?b",
"Head Coverage": "0.000584971",
"Std Confidence": "0.192307692",
"PCA Confidence": "0.3125",
Expand Down Expand Up @@ -8878,6 +8886,10 @@
{
"qualifier_type_id": "biolink:object_aspect_qualifier",
"qualifier_value": "activity_or_abundance"
},
{
"qualifier_type_id": "biolink:object_direction_qualifier",
"qualifier_value": "increased"
}
]
}
Expand Down Expand Up @@ -11779,7 +11791,7 @@
}
},
{
"Rule": "?e activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a decreased_activity_or_abundance_biolink:affects ?b",
"Rule": "?e decreased_activity_or_abundance_biolink:affects ?b ?e biolink:similar_to ?a => ?a decreased_activity_or_abundance_biolink:affects ?b",
"Head Coverage": "0.000051974",
"Std Confidence": "0.104395604",
"PCA Confidence": "0.154471545",
Expand Down Expand Up @@ -11825,6 +11837,10 @@
{
"qualifier_type_id": "biolink:object_aspect_qualifier",
"qualifier_value": "activity_or_abundance"
},
{
"qualifier_type_id": "biolink:object_direction_qualifier",
"qualifier_value": "decreased"
}
]
}
Expand Down
19 changes: 17 additions & 2 deletions src/service_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def post_with_callback(host_url, query, guid, params=None):
# check the response status.
if post_response.status_code != 200:
# queue isn't needed for failed service call
logger.warning(f"Deleting unneeded queue for {guid}")
logger.warning(f"{guid} POST status: {post_response.status_code}. Deleting unneeded queue.")
await delete_queue(guid)
# if there is an error this will return a <requests.models.Response> type
return post_response
Expand Down Expand Up @@ -337,6 +337,8 @@ async def check_for_messages(guid, num_queries, num_previously_received=0):
num_responses += 1
logger.info(f"{guid}: Strider returned {num_responses} out of {num_queries}.")
jr = process_message(message)
with open(f"{guid}_{num_responses}.json","w") as outf:
json.dump(jr,outf,indent=2)
if is_end_message(jr):
logger.info(f"{guid}: Received complete message from multistrider")
complete = True
Expand Down Expand Up @@ -467,7 +469,6 @@ async def subservice_post(name, url, message, guid, asyncquery=False, params=Non
if len(response.json()):
#pass it through pydantic for validation and cleaning
ret_val = await to_jsonable_dict(PDResponse.parse_obj(response.json()).dict(exclude_none = True))

except Exception as e:
status_code = 500
logger.exception(f"{guid}: ARAGORN Exception {e} translating json from post to {name}")
Expand Down Expand Up @@ -913,6 +914,10 @@ async def robokop_infer(input_message, guid, question_qnode, answer_qnode):
max_conns = os.environ.get("MAX_CONNECTIONS", 5)
nrules = int(os.environ.get("MAXIMUM_ROBOKOPKG_RULES", 101))
messages = expand_query(input_message, {}, guid)
with open('robokop_infer.txt', 'w') as logfile:
json.dump(input_message, logfile, indent=2)
logfile.write("------\n")
json.dump(messages, logfile, indent=2)
lookup_query_graph = messages[0]["message"]["query_graph"]
logger.info(f"{guid}: {len(messages)} to send to {automat_url}")
result_messages = []
Expand All @@ -926,6 +931,7 @@ async def robokop_infer(input_message, guid, question_qnode, answer_qnode):

responses = await asyncio.gather(*tasks)

nr = 0
for response in responses:
if response.status_code == 200:
#Validate and clean
Expand All @@ -934,6 +940,9 @@ async def robokop_infer(input_message, guid, question_qnode, answer_qnode):
num_results = len(rmessage["message"].get("results",[]))
logger.info(f"Returned {num_results} results")
if num_results > 0 and num_results < 10000: #more than this number of results and you're into noise.
with (open(f"{guid}_r_{nr}.json", 'w')) as outf:
json.dump(rmessage, outf, indent=2)
nr += 1
result_messages.append(rmessage)
else:
logger.error(f"{guid}: {response.status_code} returned.")
Expand Down Expand Up @@ -1032,6 +1041,9 @@ async def omnicorp(message, params, guid) -> (dict, int):
"""
url = f'{os.environ.get("RANKER_URL", "https://aragorn-ranker.renci.org/1.4/")}omnicorp_overlay'

with open("to_corp.json","w") as f:
f.write(json.dumps(message,indent=2))

rval, omni_status = await subservice_post("omnicorp", url, message, guid)

# Omnicorp is not strictly necessary. When we get something other than a 200,
Expand All @@ -1048,6 +1060,9 @@ async def score(message, params, guid) -> (dict, int):
:param guid:
:return:
"""
with open("to_score.json","w") as f:
f.write(json.dumps(message,indent=2))

ranker_url = os.environ.get("RANKER_URL", "https://aragorn-ranker.renci.org/1.4/")

score_url = f"{ranker_url}score"
Expand Down

0 comments on commit 2f9a2ab

Please sign in to comment.