Skip to content

Commit 8412400

Browse files
make linktemplate rules assume blank nodes
1 parent c6d4e79 commit 8412400

7 files changed

Lines changed: 61 additions & 99 deletions

File tree

_sources/v1/schemas/linkTemplate/bblock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"ogcapi-records",
1717
"records"
1818
],
19-
"abstract": "This building block corresponds to the schema for an OGC API Records linkTemplate"
19+
"abstract": "This building block corresponds to the schema for an OGC API Records linkTemplate."
2020
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Link Template
2+
3+
### JSON-LD mapping
4+
5+
This Building block maps variables to **blank nodes** - this means that multiple mappings can co-exist in a system without clashing, even if the same variable name is re-used.
6+
7+
(if identification of variables is required at a global level @id can be used in variable names)
8+
9+
### Tests:
10+
11+
tests if variables present in uriTemplates exist in variable declarations using SHACL

_sources/v1/schemas/linkTemplate/example.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"maxItems": 4
1515
},
1616
"crs": {
17+
"@id": "https://org.org/some-standard-param-set/crs",
1718
"description": "...",
1819
"type": "string",
1920
"enum": [

_sources/v1/schemas/linkTemplate/rules.shacl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ rec:testVarExists
1717
SELECT $this ?path ?value ?template
1818
WHERE {
1919
BIND (rec:hasVariable as ?path)
20-
$this rec:hasVariable ?var .
20+
$this rec:hasVariable/dct:identifier ?var .
2121
$this rec:uriTemplate ?template .
22-
BIND ( STRAFTER ( STR(?var),STR( rec: ) ) AS ?value )
2322
}
2423
GROUP BY $this ?path ?value ?template
25-
HAVING ( COUNT(?var) = SUM(
24+
HAVING ( COUNT(?var) != SUM(
2625
IF(
27-
CONTAINS(?template, CONCAT("{",?value,"}" )),1,0 )
26+
CONTAINS(?template, CONCAT("{",?var,"}" )),1,0 )
2827
) )
2928

3029
""" ; ]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"rel": "describes",
3+
"title": "World Ozone and Ultraviolet Radiation Data Centre (WOUDC) stations",
4+
"uriTemplate": "https://geo.woudc.org/ows?crs={crs}&bbox={bbox}",
5+
"variables": {
6+
"bbox": {
7+
"description": "...",
8+
"type": "array",
9+
"items": {
10+
"type": "number",
11+
"format": "double"
12+
},
13+
"minItems": 4,
14+
"maxItems": 4
15+
}
16+
}
17+
}

_sources/v1/schemas/linkTemplate/tests/var-exists-fail.ttl

Lines changed: 0 additions & 94 deletions
This file was deleted.

test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import rdflib
2+
3+
4+
g = rdflib.Graph()
5+
g.parse('build-local/tests/api/records/v1/schemas/linkTemplate/var-exists-fail.ttl', format='turtle')
6+
7+
# Define the SPARQL query
8+
query = """
9+
PREFIX rec: <https://www.opengis.net/def/ogc-api/records/>
10+
prefix oa: <http://www.w3.org/ns/oa#>
11+
SELECT COUNT(?var)
12+
WHERE {
13+
BIND (rec:hasVariable as ?path)
14+
$this rec:hasVariable/dct:identifier ?var .
15+
$this rec:uriTemplate ?template .
16+
17+
}
18+
GROUP BY $this ?path ?value ?template
19+
20+
"""
21+
22+
# Run the query against the local graph
23+
qres = g.query(query)
24+
25+
for row in qres:
26+
print(f"Subject: {row.s}, Predicate: {row.p}, Object: {row.o}")
27+
# Or by index:
28+
# print(f"Subject: {row[0]}, Predicate: {row[1]}, Object: {row[2]}")

0 commit comments

Comments
 (0)