Skip to content

Commit

Permalink
optimisations in ontology queries
Browse files Browse the repository at this point in the history
  • Loading branch information
dsavchenko committed Jan 14, 2025
1 parent 7f2eac3 commit 944d065
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions oda_api/ontology_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,13 @@ 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 {
SELECT DISTINCT ?mid ( count(?mid2) as ?midcount ) WHERE {
%s (rdfs:subClassOf|a)* ?mid .
?mid rdfs:subClassOf* ?mid2 .
?mid2 rdfs:subClassOf* %s .
}
group by ?mid
order by desc(?midcount)
ORDER BY DESC(?midcount)
""" % ( uri_m, base_uri_m )

qres = self.g.query(query)
Expand Down Expand Up @@ -354,7 +353,7 @@ def get_limits(self, param_uri):
def get_allowed_values(self, param_uri):
param_uri = self._normalize_uri(param_uri)

query = """ SELECT ?item (count(?list) as ?midcount) WHERE {
query = """ SELECT DISTINCT ?item (count(?list) as ?midcount) WHERE {

Check warning on line 356 in oda_api/ontology_helper.py

View check run for this annotation

Codecov / codecov/patch

oda_api/ontology_helper.py#L356

Added line #L356 was not covered by tests
?list rdf:rest*/rdf:first ?item .
Expand All @@ -367,7 +366,6 @@ def get_allowed_values(self, param_uri):
]
]
}
GROUP BY ?item
ORDER BY DESC(?midcount)
""" % param_uri

Expand All @@ -381,14 +379,10 @@ def get_allowed_values(self, param_uri):

def get_parprod_terms(self):
query = """
SELECT ?s WHERE {
SELECT DISTINCT ?s WHERE {
?s (rdfs:subClassOf|a)* ?mid0.
?mid0 rdfs:subClassOf* oda:DataProduct.
?s (rdfs:subClassOf|a)* ?mid1.
?mid1 rdfs:subClassOf* oda:WorkflowParameter .
?mid0 rdfs:subClassOf* oda:ParameterProduct .
}
GROUP BY ?s
"""
qres = self.g.query(query)
return [str(row[0]) for row in qres]
Expand Down

0 comments on commit 944d065

Please sign in to comment.