diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 236a4786..dd4081a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ jobs: papermill doc/source/user_guide/AsynchronousAPI.ipynb doc/source/user_guide/AsynchronousAPI-output.ipynb jupyter nbconvert --to html doc/source/user_guide/AsynchronousAPI-output.ipynb - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: AsynchronousAPI-output.html path: doc/source/user_guide/AsynchronousAPI-output.html diff --git a/oda_api/ontology_helper.py b/oda_api/ontology_helper.py index b0b44c2b..8b9a22a2 100644 --- a/oda_api/ontology_helper.py +++ b/oda_api/ontology_helper.py @@ -202,7 +202,7 @@ def parse_limits_annotations(self, graph, infer_datatype = True): graph.add((classuri, RDFS.subClassOf, bn)) def _get_datatype_restriction(self, param_uri): - param_uri = f"<{param_uri}>" if param_uri.startswith("http") else param_uri + param_uri = self._normalize_uri(param_uri) query = """ SELECT ?dt WHERE { { @@ -242,19 +242,19 @@ def parse_extra_triples(self, extra_triples, format='n3', parse_oda_annotations extra_triples = tmpg.serialize(format=format) self.g.parse(data = extra_triples, format = format) - - def get_parameter_hierarchy(self, param_uri): - param_uri_m = f"<{param_uri}>" if param_uri.startswith("http") else param_uri + def get_uri_hierarchy(self, uri, base_uri): + uri_m = self._normalize_uri(uri) + base_uri_m = self._normalize_uri(base_uri) query = """ select ?mid ( count(?mid2) as ?midcount ) where { %s (rdfs:subClassOf|a)* ?mid . ?mid rdfs:subClassOf* ?mid2 . - ?mid2 rdfs:subClassOf* oda:WorkflowParameter . + ?mid2 rdfs:subClassOf* %s . } group by ?mid order by desc(?midcount) - """ % ( param_uri_m ) + """ % ( uri_m, base_uri_m ) qres = self.g.query(query) @@ -262,11 +262,17 @@ def get_parameter_hierarchy(self, param_uri): if len(hierarchy) > 0: return hierarchy else: - logger.warning("%s is not in ontology or not an oda:WorkflowParameter", param_uri) - return [ param_uri ] - + logger.warning("%s is not in ontology or not an %s", uri, base_uri) + return [ uri ] + + def get_parameter_hierarchy(self, param_uri): + return self.get_uri_hierarchy(param_uri, base_uri='oda:WorkflowParameter') + + def get_product_hierarchy(self, prod_uri): + return self.get_uri_hierarchy(prod_uri, base_uri='oda:DataProduct') + def get_parameter_format(self, param_uri, return_uri = False): - if param_uri.startswith("http"): param_uri = f"<{param_uri}>" + param_uri = self._normalize_uri(param_uri) query = """ SELECT ?format_uri WHERE { %s (rdfs:subClassOf|a)* [ @@ -290,7 +296,7 @@ def get_parameter_format(self, param_uri, return_uri = False): return uri def get_parameter_unit(self, param_uri, return_uri = False): - if param_uri.startswith("http"): param_uri = f"<{param_uri}>" + param_uri = self._normalize_uri(param_uri) query = """SELECT ?unit_uri WHERE { %s (rdfs:subClassOf|a)* [ @@ -314,7 +320,7 @@ def get_parameter_unit(self, param_uri, return_uri = False): return uri def get_limits(self, param_uri): - if param_uri.startswith("http"): param_uri = f"<{param_uri}>" + param_uri = self._normalize_uri(param_uri) query = """ SELECT ?lim WHERE { @@ -346,7 +352,7 @@ def get_limits(self, param_uri): return (ll, ul) def get_allowed_values(self, param_uri): - if param_uri.startswith("http"): param_uri = f"<{param_uri}>" + param_uri = self._normalize_uri(param_uri) query = """ SELECT ?item (count(?list) as ?midcount) WHERE { @@ -392,7 +398,7 @@ def get_oda_label(self, param_uri): return self.get_direct_annotation(param_uri, "label") def get_direct_annotation(self, param_uri, metadata, predicate="oda"): - if param_uri.startswith("http"): param_uri = f"<{param_uri}>" + param_uri = self._normalize_uri(param_uri) query = f"SELECT ?{metadata} WHERE {{{param_uri} {predicate}:{metadata} ?{metadata}}}" @@ -405,7 +411,7 @@ def get_direct_annotation(self, param_uri, metadata, predicate="oda"): return metadata_value def is_data_product(self, owl_uri, include_parameter_products=True): - if owl_uri.startswith("http"): owl_uri = f"<{owl_uri}>" + owl_uri = self._normalize_uri(owl_uri) filt_param = 'MINUS{?cl rdfs:subClassOf* oda:ParameterProduct. }' if not include_parameter_products else '' query = """ @@ -464,6 +470,10 @@ def resources(): yield dict(resource=str(resource).split('#')[-1], required=required, env_vars=env_vars) def is_optional(self, uri: str) -> bool: - if uri.startswith("http"): uri = f"<{uri}>" + uri = self._normalize_uri(uri) s_qres = self.g.query("ASK {%s rdfs:subClassOf? oda:optional .}" % uri ) return cast(bool, list(s_qres)[0]) + + @staticmethod + def _normalize_uri(uri): + return f"<{uri}>" if uri.startswith("http") else uri \ No newline at end of file