Skip to content

Commit

Permalink
updating litcoin parser to receive and log api errors from the name r…
Browse files Browse the repository at this point in the history
…esolution api
  • Loading branch information
EvanDietzMorris committed Feb 7, 2024
1 parent ae5e334 commit 8b2b096
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions parsers/LitCoin/src/loadLitCoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

from Common.biolink_utils import BiolinkUtils
from Common.loader_interface import SourceDataLoader
from Common.kgxmodel import kgxnode, kgxedge
from Common.node_types import PRIMARY_KNOWLEDGE_SOURCE, PUBLICATIONS
from Common.node_types import PUBLICATIONS
from Common.utils import GetData, snakify
from Common.normalization import call_name_resolution
from Common.normalization import call_name_resolution, NAME_RESOLVER_API_ERROR
from Common.prefixes import PUBMED


Expand Down Expand Up @@ -73,7 +72,7 @@ class LitCoinLoader(SourceDataLoader):

source_id: str = 'LitCoin'
provenance_id: str = 'infores:robokop-kg' # TODO - change this to a LitCoin infores when it exists
parsing_version: str = '1.4'
parsing_version: str = '1.5'

def __init__(self, test_mode: bool = False, source_data_dir: str = None):
"""
Expand Down Expand Up @@ -123,12 +122,14 @@ def parse_data(self) -> dict:
self.logger.info(f'processing edge {records}')
subject_resolution_results = self.process_llm_node(litcoin_edge[LLM_SUBJECT_NAME],
litcoin_edge[LLM_SUBJECT_TYPE])
if not subject_resolution_results:
if not subject_resolution_results or \
NAME_RESOLVER_API_ERROR in subject_resolution_results:
skipped_records += 1
continue
object_resolution_results = self.process_llm_node(litcoin_edge[LLM_OBJECT_NAME],
litcoin_edge[LLM_OBJECT_TYPE])
if not object_resolution_results:
if not object_resolution_results or \
NAME_RESOLVER_API_ERROR in object_resolution_results:
skipped_records += 1
continue
self.output_file_writer.write_node(node_id=subject_resolution_results['curie'],
Expand Down Expand Up @@ -164,7 +165,7 @@ def parse_data(self) -> dict:
node_type_used_for_name_res = NODE_TYPE_MAPPINGS.get(self.convert_node_type_to_biolink_format(node_type),
None)
for results in node_name_to_results_dict.values():
if results:
if results and NAME_RESOLVER_API_ERROR not in results:
results['queried_type'] = node_type_used_for_name_res
json.dump(self.node_name_to_id_lookup,
name_res_results_file,
Expand Down Expand Up @@ -254,7 +255,9 @@ def name_resolution_function(self, node_name, preferred_biolink_node_type, retri

def standardize_name_resolution_results(self, name_res_json):
if not name_res_json:
return None
return {}
elif NAME_RESOLVER_API_ERROR in name_res_json:
return name_res_json
return {
"curie": name_res_json['curie'],
"name": name_res_json['label'],
Expand Down

0 comments on commit 8b2b096

Please sign in to comment.