Skip to content

Commit

Permalink
failing gracefully for failed sapbert or name res calls
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDietzMorris committed Oct 24, 2024
1 parent 6b6f999 commit 4c831e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion parsers/LitCoin/src/NER/nameres.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def annotate(self, text, props, limit=1):
response = self.requests_session.get(NAMERES_ENDPOINT, params=nameres_options, timeout=timeout)
logging.debug(f"Response from NameRes: {response.content}")
if not response.ok:
raise RuntimeError(f"Could not contact NameRes: {response}")
logging.debug(f"Could not contact NameRes: {response}")
response.raise_for_status()

results = response.json()
annotations = []
Expand Down
3 changes: 2 additions & 1 deletion parsers/LitCoin/src/NER/sapbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def annotate(self, text, props, limit=1):
response = self.requests_session.post(SAPBERT_ANNOTATE_ENDPOINT, json=request)
logging.debug(f"Response from {SAPBERT_MODEL_NAME}: {response.content}")
if not response.ok:
raise RuntimeError(f"Server error from SAPBERT for text '{text}': {response}")
logging.debug(f"Server error from SAPBERT for text '{text}': {response}")
response.raise_for_status()

results = response.json()
annotations = []
Expand Down
11 changes: 9 additions & 2 deletions parsers/LitCoin/src/bagel/bagel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@
def get_orion_bagel_results(text, term, abstract_id):
# print(f'bagelizing term {term}.')
taxon_id_to_name = {}
nr_results = nameres.annotate(term, props={}, limit=10)
sb_results = sapbert.annotate(term, props={}, limit=10)
try:
nr_results = nameres.annotate(term, props={}, limit=10)
except requests.exceptions.HTTPError:
nr_results = []
try:
sb_results = sapbert.annotate(term, props={}, limit=10)
except requests.exceptions.HTTPError:
sb_results = []

# We have results from both nr and sb. But we want to fill those out with consistent information that may
# or may not be returned from each source
# First merge the results by identifier (not label) and store in terms dict
Expand Down

0 comments on commit 4c831e6

Please sign in to comment.