Skip to content

Commit

Permalink
Merge pull request #264 from oda-hub/get_oda_metadata-functionality
Browse files Browse the repository at this point in the history
Get direct annotation functionality
  • Loading branch information
burnout87 authored Jul 30, 2024
2 parents e62d541 + 7b56052 commit 0cfe213
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build:
tools:
python: "3.11"


# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: doc/source/conf.py
Expand Down
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ pyjwt==2.4.0
astroquery==0.4.4

rdflib

18 changes: 11 additions & 7 deletions oda_api/ontology_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,21 @@ def get_parprod_terms(self):
return [str(row[0]) for row in qres]

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}>"

query = "SELECT ?label WHERE {%s oda:label ?label}" % (param_uri)
query = f"SELECT ?{metadata} WHERE {{{param_uri} {predicate}:{metadata} ?{metadata}}}"

qres = self.g.query(query)

if len(qres) == 0: return None
label = " ".join([str(x[0]) for x in qres])
return label

metadata_value = " ".join([str(x[0]) for x in qres])

return metadata_value

def is_data_product(self, owl_uri, include_parameter_products=True):
if owl_uri.startswith("http"): owl_uri = f"<{owl_uri}>"
Expand Down
18 changes: 18 additions & 0 deletions tests/test_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ def test_ontology_limits(onto, owl_uri, expected, extra_ttl):
onto.parse_extra_triples(extra_ttl)
limits = onto.get_limits(owl_uri)
assert limits == expected

@pytest.mark.parametrize("owl_uri, expected, extra_ttl",
[('http://odahub.io/ontology#Unknown', (None, None), ""),
('oda:Flux_FluxmicroJyorABMagnitude_Magnitude_String_label_description', ("Flux [microJy] or AB Magnitude", "Test description"),
"""@prefix oda: <http://odahub.io/ontology#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
oda:Flux_FluxmicroJyorABMagnitude_Magnitude_String_label_description
rdfs:subClassOf oda:String ;
oda:label "Flux [microJy] or AB Magnitude" ;
oda:description "Test description" .""")
])
def test_ontology_extra_metadata(onto, owl_uri, expected, extra_ttl):
if extra_ttl is not None:
onto.parse_extra_triples(extra_ttl)
label = onto.get_direct_annotation(owl_uri, "label", predicate="oda")
assert label == expected[0]
description = onto.get_direct_annotation(owl_uri, "description", predicate="oda")
assert description == expected[1]

@pytest.mark.parametrize(
"owl_uri, expected, extra_ttl",
Expand Down

0 comments on commit 0cfe213

Please sign in to comment.