From 8ed60d22c03abcb6e3b659610444e6008d667a5c Mon Sep 17 00:00:00 2001 From: Bryan Bartley Date: Mon, 19 Apr 2021 12:38:41 -0400 Subject: [PATCH] Add option clause in get_term_by_uri --- tyto/owlet.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tyto/owlet.py b/tyto/owlet.py index e259bf2..2f5d48b 100644 --- a/tyto/owlet.py +++ b/tyto/owlet.py @@ -87,7 +87,8 @@ def _convert_ontobee_response(response): response = response.convert() # Convert http response to JSON for var, binding in zip(response['head']['vars'], response['results']['bindings']): - converted_response.append(binding[var]['value']) + if var in binding: + converted_response.append(binding[var]['value']) return converted_response def _convert_rdflib_response(response): @@ -107,8 +108,15 @@ def get_term_by_uri(self, uri): SELECT distinct ?label WHERE {{{{ - <{uri}> rdfs:label ?label . - filter langMatches(lang(?label), "en") + optional + {{{{ + <{uri}> rdfs:label ?label . + filter langMatches(lang(?label), "en") + }}}} + optional + {{{{ + <{uri}> rdfs:label ?label . + }}}} }}}} '''.format(uri=uri) error_msg = '{} not found'.format(uri) @@ -212,6 +220,9 @@ def multi_replace(target_uri, old_namespaces, new_namespace): 'http://identifiers.org/so/SO:'], 'http://purl.obolibrary.org/obo/SO_') +SBO = Ontology(path=installation_path('ontologies/SBO_OWL.owl'), + endpoint='http://sparql.hegroup.org/sparql/', + uri='http://purl.obolibrary.org/obo/sbo.owl') SBO = Ontology(path=installation_path('ontologies/SBO_OWL.owl'), endpoint='http://sparql.hegroup.org/sparql/', uri='http://purl.obolibrary.org/obo/sbo.owl')