Skip to content

Commit

Permalink
Ensure only prez related profiles are loaded from remote stores; type…
Browse files Browse the repository at this point in the history
… profiles used to declare default profiles as prez:IndexProfiles.

Fix count query bug.
Improve performance of annotations retrieval.
  • Loading branch information
recalcitrantsupplant committed Oct 16, 2024
1 parent 71798f8 commit 5844669
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 38 deletions.
2 changes: 1 addition & 1 deletion prez/reference_data/profiles/ogc_features.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@prefix shext: <http://example.com/shacl-extension#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

prez:OGCFeaturesProfile a prof:Profile ;
prez:OGCFeaturesProfile a prof:Profile , prez:IndexProfile ;
dcterms:description "A system profile for OGC Features conformant API" ;
dcterms:identifier "ogcfeat"^^xsd:token ;
dcterms:title "OGC Features Profile" ;
Expand Down
5 changes: 2 additions & 3 deletions prez/reference_data/profiles/ogc_records_profile.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PREFIX shext: <http://example.com/shacl-extension#>


prez:OGCRecordsProfile
a prof:Profile ;
a prof:Profile , prez:IndexProfile ;
dcterms:identifier "ogc"^^xsd:token ;
dcterms:description "A system profile for OGC Records conformant API" ;
dcterms:title "OGC Profile" ;
Expand Down Expand Up @@ -57,8 +57,7 @@ prez:OGCRecordsProfile
sh:targetClass
dcat:Catalog,
dcat:Resource,
skos:Concept
,
skos:Concept ,
skos:Collection,
rdf:Resource ;
altr-ext:hasDefaultProfile prez:OGCItemProfile
Expand Down
2 changes: 1 addition & 1 deletion prez/reference_data/profiles/prez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>


<https://prez.dev/profile/prez>
a prof:Profile ;
a prof:Profile , prez:IndexProfile ;
dcterms:identifier "prez"^^xsd:token ;
dcterms:description "A profile for the Prez Linked Data API" ;
dcterms:title "Prez profile" ;
Expand Down
5 changes: 4 additions & 1 deletion prez/services/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ async def process_uncached_terms(
rdf_queries=[annotations_query], tabular_queries=[]
)

all_results = context_results[0] + repo_results[0] + system_results[0]
all_results = Graph()
all_results += context_results[0]
all_results += repo_results[0]
all_results += system_results[0]

# Initialize subjects_map with each term having an empty set to start with
subjects_map = {term: set() for term in terms}
Expand Down
33 changes: 5 additions & 28 deletions prez/services/generate_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,12 @@ async def create_profiles_graph(repo) -> Graph:
profiles_graph_cache.parse(f)
log.info("Prez default profiles loaded")
remote_profiles_query = """
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX prof: <http://www.w3.org/ns/dx/prof/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {?s ?p ?o .
?o ?p2 ?o2 .
?o2 ?p3 ?o3 .
?class ?cp ?co}
WHERE {?s a prof:Profile ;
?p ?o
OPTIONAL {?o ?p2 ?o2
FILTER(ISBLANK(?o))
OPTIONAL {?o2 ?p3 ?o3
FILTER(ISBLANK(?o2))}
}
OPTIONAL {
?class rdfs:subClassOf dcat:Resource ;
?cp ?co .
}
OPTIONAL {
?class rdfs:subClassOf geo:Feature ;
?cp ?co .
}
OPTIONAL {
?class rdfs:subClassOf skos:Concept ;
?cp ?co .
}
PREFIX prez: <https://prez.dev/>
DESCRIBE ?prof {
VALUES ?prof_class { prez:ListingProfile prez:ObjectProfile prez:IndexProfile }
?prof a ?prof_class
}
"""
g, _ = await repo.send_queries([remote_profiles_query], [])
Expand Down
10 changes: 6 additions & 4 deletions prez/services/query_generation/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class CountQuery(ConstructQuery):
}
WHERE {
{
SELECT (COUNT(DISTINCT ?focus_node) AS ?count)
SELECT (COUNT(?focus_node) AS ?count)
WHERE {
SELECT ?focus_node
SELECT DISTINCT ?focus_node
WHERE {
<<< original where clause >>>
} LIMIT 101
Expand All @@ -64,7 +64,10 @@ def __init__(self, original_subselect: SubSelect):
limit = settings.listing_count_limit
limit_plus_one = limit + 1
inner_ss = SubSelect(
select_clause=SelectClause(variables_or_all=[Var(value="focus_node")]),
select_clause=SelectClause(
variables_or_all=[Var(value="focus_node")],
distinct=True,
),
where_clause=original_subselect.where_clause,
solution_modifier=SolutionModifier(
limit_offset=LimitOffsetClauses(
Expand All @@ -78,7 +81,6 @@ def __init__(self, original_subselect: SubSelect):
content=BuiltInCall(
other_expressions=Aggregate(
function_name="COUNT",
distinct=True,
expression=Expression.from_primary_expression(
PrimaryExpression(content=Var(value="focus_node"))
),
Expand Down

0 comments on commit 5844669

Please sign in to comment.