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 all commits
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
83 changes: 42 additions & 41 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ async def get_datasets(count=1000, offset=0):
}
UNION
{
?d a loci:Dataset .
?d a loci:Dataset .
}
UNION
{
Expand Down Expand Up @@ -319,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 @@ -336,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 @@ -635,40 +636,36 @@ 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 {
?p rdfs:subPropertyOf* geo:sfOverlaps .
Copy link
Contributor

@jyucsiro jyucsiro Apr 23, 2020

Choose a reason for hiding this comment

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

{
{
?s1 rdf:subject <URI> ;
<LINKSET_FILTER>
rdf:predicate geox:transitiveSfOverlap;
rdf:object ?o .
} UNION {
?s2 rdf:subject <URI> ;
<LINKSET_FILTER>
rdf:predicate geo:sfOverlaps;
rdf:object ?o .
}
?s2 rdf:subject <URI> ;
<LINKSET_FILTER>
rdf:predicate ?p ;
rdf:object ?o .
}
UNION
{ <URI> geox:transitiveSfOverlap ?o }
UNION
{ <URI> geo:sfOverlaps ?o }
{
<URI> ?p ?o
}
<EXTRAS>
}
GROUP BY ?o
"""
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 @@ -692,8 +689,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 @@ -723,11 +721,13 @@ 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 geox:inCRS epsg:3577 .
?ha1 dt:value ?a1 .
}
OPTIONAL {
?o geox:hasAreaM2 ?ha2 .
# ?ha2 qb4st:crs epsg:3577 .
?ha2 geox:inCRS epsg:3577 .
?ha2 dt:value ?a2 .
}
Expand All @@ -753,8 +753,9 @@ async def get_location_overlaps(target_uri, output_featuretype_uri, include_area
} .
OPTIONAL {
?i geox:hasAreaM2 ?ha3 .
?ha3 geox:inCRS epsg:3577 .
?ha3 dt:value ?a3 .
# ?ha3 qb4st:crs epsg:3577 .
?ha3 geox:inCRS epsg:3577 .
?ha3 dt:value ?a3 .
}
}
"""
Expand All @@ -770,13 +771,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 @@ -791,7 +792,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 @@ -805,7 +806,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