-
Notifications
You must be signed in to change notification settings - Fork 2
Dynamic Queries
David Valentine edited this page Apr 9, 2026
·
2 revisions
We are working towards a dynamic query
My vision is that there is a set of PREFIX, then a the basic query that returns the information needed for the
PREFIX
...
SELECT ....
WHERE {
values ?sosType {
sschema:Dataset
# sschema:DataCatalog
schema:Dataset
# schema:DataCatalog
}
?subj a ?sosType .
values (?type ?resourceType_u) {
(schema:Dataset "data")
(sschema:Dataset "data")
(schema:DataCatalog "DataCatalog")
(sschema:DataCatalog "DataCatalog")
#(UNDEF "other") # assume it's data. At least we should get name.
}
?subj a ?type .
?subj ?o ?item .
# ?item is used in the filters.
GRAPH ?g {
# required elements
schema:name
schema:description
# OPTIONAL
}
}
GROUP BY ...
LIMIT {{N}}
OFFSET {{O}}
This will return records with no filters. This query needs to be performant. There are optional clauses that will kill this.
Then we add filters after the WHERE before the graph.
PREFIX
...
SELECT ....
WHERE {
values ?sosType {
sschema:Dataset
# sschema:DataCatalog
schema:Dataset
# schema:DataCatalog
}
?subj a ?sosType .
values (?type ?resourceType_u) {
(schema:Dataset "data")
(sschema:Dataset "data")
(schema:DataCatalog "DataCatalog")
(sschema:DataCatalog "DataCatalog")
#(UNDEF "other") # assume it's data. At least we should get name.
}
?subj a ?type .
?subj ?o ?item .
#FILTERS HERE
GRAPH ?g {
# required elements
schema:name
schema:description
# OPTIONAL
}
}
GROUP BY ...
LIMIT {{N}}
OFFSET {{O}}
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
prefix schema: <http://schema.org/>
prefix sschema: <https://schema.org/>
PREFIX ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/>
SELECT distinct ?g ?subj ?type ?name ?description ?pubname (GROUP_CONCAT(DISTINCT ?placename; SEPARATOR=", ") AS ?placenames)
(GROUP_CONCAT(DISTINCT ?kwu; SEPARATOR=", ") AS ?kw)
?datep (GROUP_CONCAT(DISTINCT ?url; SEPARATOR=", ") AS ?disurl)
(COUNT(?text) AS ?score) (SAMPLE(?text) AS ?example_text)
(GROUP_CONCAT(DISTINCT ?resourceType_u; SEPARATOR=", ") as ?resourceType ) (MAX(?lat) as ?maxlat) (Min(?lat) as ?minlat) (MAX(?lon) as ?maxlon) (Min(?lon) as ?minlon)
?maxDepth ?minDepth ?temporalCoverage (GROUP_CONCAT(DISTINCT ?variableMeasured_a; SEPARATOR=", ") as ?variableMeasured )
?bbox
WHERE {
values ?sosType {
sschema:Dataset
# sschema:DataCatalog
schema:Dataset
# schema:DataCatalog
}
?subj a ?sosType .
values (?type ?resourceType_u) {
(schema:Dataset "data")
(sschema:Dataset "data")
(schema:DataCatalog "DataCatalog")
(sschema:DataCatalog "DataCatalog")
#(UNDEF "other") # assume it's data. At least we should get name.
}
?subj a ?type .
?subj ?o ?item .
graph ?g {
?subj schema:name|sschema:name ?name .
?subj schema:description|sschema:description ?description .
OPTIONAL { ?subj schema:publisher/schema:legalName|sschema:publisher/sschema:legalName ?legalName . }
OPTIONAL { ?subj schema:publisher/schema:name|sschema:publisher/sschema:name ?publisher . }
bind (COALESCE(?publisher,?legalName, "No Publisher") As ?pubname)
OPTIONAL { ?subj schema:datePublished|sschema:datePublished ?datep1 . }
OPTIONAL { ?subj schema:dateCreated|sschema:dateCreated ?datec . }
OPTIONAL { ?subj schema:dateModified|sschema:dateModified ?datem . }
bind (COALESCE(?datec,?datem,?datep1) As ?datep)
OPTIONAL { ?subj schema:temporalCoverage|sschema:temporalCoverage ?temporalCoverage . }
.
OPTIONAL {
?subj schema:spatialCoverage/schema:name|sschema:spatialCoverage/sschema:name|sschema:sdPublisher
?place_name .
}
BIND (IF (BOUND(?place_name), ?place_name, "No Placenames") as ?placename) .
optional {
?subj
sschema:distribution/sschema:url|sschema:subjectOf/sschema:url|schema:distribution/schema:url|schema:subjectOf/schema:url
?url .
}
OPTIONAL { ?subj schema:keywords|sschema:keywords ?kwu . }
# OPTIONAL {?subj schema:spatialCoverage/schema:geo/schema:latitude|sschema:spatialCoverage/sschema:geo/sschema:latitude ?lat .}
# OPTIONAL {?subj sschema:spatialCoverage/sschema:geo ?geo .
# ?geo a sschema:GeoCoordinates .
# ?geo sschema:longitude ?lon .
# ?geo sschema:llatitude ?lat .}
#OPTIONAL {?subj sschema:spatialCoverage/sschema:geo ?geo .
# ?geo a sschema:GeoShape .
# ?geo sschema:box ?box .}
# bind ( COALESCE(?box) As ?bbox)
OPTIONAL {
?subj sschema:variableMeasured ?vm .
?vm a sschema:PropertyValue .
?vm sschema:name ?variableMeasured_a .
}
# if there is more than one location, then coallese to get the versions.
OPTIONAL {
?subj sschema:variableMeasured ?vmd .
?vmd a sschema:PropertyValue .
?vmd sschema:name ?namedepth .
FILTER (LCASE(?namedepth) IN ( "cmpdep", "package_depth", "collection_depth", "Bottle Depth","sample depth","tow depth") ) .
?vmd sschema:maxValue ?maxDepth_d .
?vmd sschema:minValue ?minDepth_d
bind (COALESCE(?maxDepth_d) As ?maxDepth)
bind (COALESCE(?minDepth_d) As ?minDepth)
}
}
}
GROUP BY ?g ?subj ?name ?description ?type ?pubname ?placename ?datep ?maxDepth ?minDepth ?temporalCoverage ?url ?bbox
LIMIT 100
OFFSET 0
Then filters to be added: