Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SPARQL in functions.py #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 47 additions & 35 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,18 @@ async def get_datasets(count=1000, offset=0):
"""
sparql = """\
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX loci: <http://linked.data.gov.au/def/loci#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?d
WHERE {
{
?d a dcat:Dataset .
}
UNION
{
?d a loci:Dataset .
}
UNION
{
?c rdfs:subClassOf+ dcat:Dataset .
?d a ?c .
Expand Down Expand Up @@ -314,7 +319,7 @@ async def get_locations(count=1000, offset=0):
"""
sparql = """\
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX prov: <http://www.w3.org/ns/prov#>
# PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?l
Expand All @@ -331,19 +336,20 @@ async def get_locations(count=1000, offset=0):
rdf:predicate rdf:type ;
rdf:object geo:Feature .
}
UNION
{ ?l a prov:Location }
UNION
{
?c2 rdfs:subClassOf+ prov:Location .
?l a ?c2 .
}
UNION
{
?s2 rdf:subject ?l ;
rdf:predicate rdf:type ;
rdf:object prov:Location .
} .
# UNION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My best guess as to why this was here in the first place is because "overlaps" objects are treated as geo:Features but we want to exclude them from being returned as locations. I'm not sure though, @ashleysommer ?

Copy link
Author

@dr-shorthair dr-shorthair Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these computed ahead and cached? If so, I would prefer to see an explicit feature-type for overlaps. Maybe loci:Overlap ? Then these can be explicitly excluded, rather than borrowing an unrelated feature-type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree it shouldn't be a feature but I can't remember all the reasoning around it from our older discussions. I believe we can actually get rid of overlaps objects altogether because all that information should be elsewhere but @ashleysommer has more history and probably more insight on this. We need to break up scope here as well. It would be good to merge whatever is the minimum set of changes to support the new LDAPIs and deal with larger refactors, like overlaps, later.

# { ?l a prov:Location }
# UNION
# {
# ?c2 rdfs:subClassOf+ prov:Location .
# ?l a ?c2 .
# }
# UNION
# {
# ?s2 rdf:subject ?l ;
# rdf:predicate rdf:type ;
# rdf:object prov:Location .
# }
.
}
"""
resp = await query_graphdb_endpoint(sparql, limit=count, offset=offset)
Expand Down Expand Up @@ -628,28 +634,29 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
overlaps_sparql = """\
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ipo: <http://purl.org/dc/terms/isPartOf>
PREFIX dcterms: <http://purl.org/dc/terms/>
# PREFIX ipo: <http://purl.org/dc/terms/isPartOf>
PREFIX geox: <http://linked.data.gov.au/def/geox#>
PREFIX qb4st: <http://www.w3.org/ns/qb4st/>
# PREFIX qb4st: <http://www.w3.org/ns/qb4st/>
PREFIX epsg: <http://www.opengis.net/def/crs/EPSG/0/>
PREFIX dt: <http://linked.data.gov.au/def/datatype/>
SELECT <SELECTS>
WHERE {
{
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this bracket might not be closed and might need commenting

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which bracket? there is nothing in the change.

?s1 rdf:subject <URI> ;
<LINKSET_FILTER>
rdf:predicate geox:transitiveSfOverlap;
rdf:object ?o .
} UNION {
# ?s1 rdf:subject <URI> ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can take this out until we've rebuilt the linksets and that is beyond the scope of the LDAPI refactors currently underway. AFAIK we use geox:transitiveSfOverlap still and can't depend on geo:sfOverlaps yet

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets verify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so in tests with excelerator use cases, we either have to:
a) change the linksets and/or triples in the cache so that this API endpoint works with your proposed query @dr-shorthair
or
b) defer removing the union statement (i.e. keep it) so it works with the current linkset triples

b) is more expedient; but a) is probably what we should do in the longer term

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it is the bracket above this comment I think it also needs commenting. Not sure though it just looks like an extra line needs commenting.

# <LINKSET_FILTER>
# rdf:predicate geox:transitiveSfOverlap;
# rdf:object ?o .
# } UNION {
?s2 rdf:subject <URI> ;
<LINKSET_FILTER>
rdf:predicate geo:sfOverlaps;
rdf:object ?o .
}
}
UNION
{ <URI> geox:transitiveSfOverlap ?o }
# UNION
# { <URI> geox:transitiveSfOverlap ?o }
UNION
{ <URI> geo:sfOverlaps ?o }
<EXTRAS>
Expand All @@ -659,9 +666,10 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
contains_sparql = """\
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ipo: <http://purl.org/dc/terms/isPartOf>
PREFIX dcterms: <http://purl.org/dc/terms/>
# PREFIX ipo: <http://purl.org/dc/terms/isPartOf>
PREFIX geox: <http://linked.data.gov.au/def/geox#>
PREFIX qb4st: <http://www.w3.org/ns/qb4st/>
# PREFIX qb4st: <http://www.w3.org/ns/qb4st/>
PREFIX epsg: <http://www.opengis.net/def/crs/EPSG/0/>
PREFIX dt: <http://linked.data.gov.au/def/datatype/>
SELECT ?c <SELECTS>
Expand All @@ -685,8 +693,9 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX geox: <http://linked.data.gov.au/def/geox#>
PREFIX ipo: <http://purl.org/dc/terms/isPartOf>
PREFIX qb4st: <http://www.w3.org/ns/qb4st/>
PREFIX dcterms: <http://purl.org/dc/terms/>
# PREFIX ipo: <http://purl.org/dc/terms/isPartOf>
# PREFIX qb4st: <http://www.w3.org/ns/qb4st/>
PREFIX epsg: <http://www.opengis.net/def/crs/EPSG/0/>
PREFIX dt: <http://linked.data.gov.au/def/datatype/>
SELECT ?w <SELECTS>
Expand Down Expand Up @@ -716,12 +725,14 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
areas_sparql = """\
OPTIONAL {
<URI> geox:hasAreaM2 ?ha1 .
?ha1 qb4st:crs epsg:3577 .
# ?ha1 qb4st:crs epsg:3577 .
?ha1 geox:inCRS epsg:3577 .
?ha1 dt:value ?a1 .
}
OPTIONAL {
?o geox:hasAreaM2 ?ha2 .
?ha2 qb4st:crs epsg:3577 .
# ?ha2 qb4st:crs epsg:3577 .
?ha2 geox:inCRS epsg:3577 .
?ha2 dt:value ?a2 .
}
"""
Expand All @@ -746,8 +757,9 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
} .
OPTIONAL {
?i geox:hasAreaM2 ?ha3 .
?ha3 qb4st:crs epsg:3577 .
?ha3 dt:value ?a3 .
# ?ha3 qb4st:crs epsg:3577 .
?ha3 geox:inCRS epsg:3577 .
?ha3 dt:value ?a3 .
}
}
"""
Expand All @@ -763,13 +775,13 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
sparql = sparql.replace("<EXTRAS>", extras)
sparql = sparql.replace("<URI>", "<{}>".format(str(target_uri)))
if not linksets_filter is None:
sparql = sparql.replace("<LINKSET_FILTER>", "ipo: <{}> ;".format(str(linksets_filter)))
sparql = sparql.replace("<LINKSET_FILTER>", "dcterms:isPartOf <{}> ;".format(str(linksets_filter)))
else:
sparql = sparql.replace("<LINKSET_FILTER>", "")
overlaps = []
bindings = []
if not linksets_filter is None:
sparql = sparql.replace("<LINKSET_FILTER>", "ipo: <{}> ;".format(str(linksets_filter)))
sparql = sparql.replace("<LINKSET_FILTER>", "dcterms:isPartOf <{}> ;".format(str(linksets_filter)))
else:
sparql = sparql.replace("<LINKSET_FILTER>", "")
await query_build_response_bindings(sparql, count, offset, bindings)
Expand All @@ -783,7 +795,7 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
sparql = sparql.replace("<EXTRAS>", extras)
sparql = sparql.replace("<URI>", "<{}>".format(str(target_uri)))
if not linksets_filter is None:
sparql = sparql.replace("<LINKSET_FILTER>", "ipo: <{}> ;".format(str(linksets_filter)))
sparql = sparql.replace("<LINKSET_FILTER>", "dcterms:isPartOf <{}> ;".format(str(linksets_filter)))
else:
sparql = sparql.replace("<LINKSET_FILTER>", "")
await query_build_response_bindings(sparql, count, offset, bindings)
Expand All @@ -797,7 +809,7 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
sparql = sparql.replace("<EXTRAS>", extras)
sparql = sparql.replace("<URI>", "<{}>".format(str(target_uri)))
if not linksets_filter is None:
sparql = sparql.replace("<LINKSET_FILTER>", "ipo: <{}> ;".format(str(linksets_filter)))
sparql = sparql.replace("<LINKSET_FILTER>", "dcterms:isPartOf <{}> ;".format(str(linksets_filter)))
else:
sparql = sparql.replace("<LINKSET_FILTER>", "")
await query_build_response_bindings(sparql, count, offset, bindings)
Expand Down