generated from opengeospatial/bblock-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extended examples and stardog load/query tests
- Loading branch information
1 parent
44806c7
commit 564766c
Showing
23 changed files
with
552 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "Aggregation Activity", | ||
"abstract": "An aggregation activity integrates a stream of observations into a persistent archive.", | ||
"status": "under-development", | ||
"dateTimeAddition": "2023-05-19T00:00:00Z", | ||
"itemClass": "schema", | ||
"register": "ccm", | ||
"version": "1.0", | ||
"dateOfLastChange": "2023-05-19", | ||
"sources": [ | ||
], | ||
"maturity": "development", | ||
"scope": "unstable", | ||
"dependsOn": [ | ||
], | ||
"tags": [ | ||
"prov"], | ||
"group": "Activities", | ||
"highlighted": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Aggregation Activity | ||
|
||
This building block provides a JSON schema based on the PROV model for an activity that performs an aggregation over dimensions of a set of data observations. | ||
|
||
The aggregation function must be described using an appropriate AggregationFunction entity. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Prefixes will be used for all RDF Turtle resources so that they can be omitted from the actual snippets | ||
# prefixes: | ||
# dct: http://purl.org/dc/terms/ | ||
|
||
## List of examples | ||
examples: | ||
- title: Aggregation | ||
|
||
## Markdown content that will be shown for the example. | ||
content: | ||
Shows a aggregation activity with a positive result. | ||
|
||
## Base URI for semantic uplift | ||
base-uri: http://example.com/activities/ | ||
|
||
## The example can define its own prefixes, that will be merged with the global ones | ||
prefixes: | ||
myData: http://example.com/datasets/ | ||
|
||
## List of code snippets for this example | ||
snippets: | ||
- language: json | ||
# Reference to file | ||
ref: examples/aggregation.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"provType": [ "Activity", "Aggregation" ], | ||
"id": "aggregation_example", | ||
"endedAtTime": "2029-01-01T22:05:19+02:00", | ||
"wasAssociatedWith": "eg_agents:bc-3", | ||
"generated": { "id": "myData:YearlySummary", | ||
"wasDerivedFrom" : "myData:WeeklyRecords", | ||
"wasGeneratedBy" : "aggregation_example" | ||
}, | ||
"used": "myData:WeeklyRecords" | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
description: Aggregation activity | ||
$defs: | ||
Aggregation: | ||
allOf: | ||
- $ref: bblocks://ogc.ogc-utils.prov#/$defs/Activity | ||
- properties: | ||
provType: | ||
type: array | ||
contains: | ||
type: string | ||
const: Aggregation | ||
required: | ||
- provType | ||
- generated | ||
- used | ||
|
||
anyOf: | ||
- $ref: "#/$defs/Aggregation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "Derivation Activity", | ||
"abstract": "A derivation activity takes a data set and derives a new data set from it. It must reference an Entity which defines the derivation function, allowing identification of the derivation process.", | ||
"status": "under-development", | ||
"dateTimeAddition": "2023-05-19T00:00:00Z", | ||
"itemClass": "schema", | ||
"register": "ccm", | ||
"version": "1.0", | ||
"dateOfLastChange": "2023-05-19", | ||
"sources": [ | ||
], | ||
"maturity": "development", | ||
"scope": "unstable", | ||
"dependsOn": [ | ||
], | ||
"tags": [ | ||
"prov"], | ||
"group": "Activities", | ||
"highlighted": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Derivation Activity | ||
|
||
This building block provides a JSON schema based on the PROV model for an activity derives new data using a function based on properties of that data. | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Prefixes will be used for all RDF Turtle resources so that they can be omitted from the actual snippets | ||
# prefixes: | ||
# dct: http://purl.org/dc/terms/ | ||
|
||
## List of examples | ||
examples: | ||
- title: Derivation | ||
|
||
## Markdown content that will be shown for the example. | ||
content: | ||
Shows a derivation activity with a positive result. | ||
|
||
## Base URI for semantic uplift | ||
base-uri: http://example.com/activities/ | ||
|
||
## The example can define its own prefixes, that will be merged with the global ones | ||
prefixes: | ||
mydata: http://example.com/datasets/ | ||
|
||
## List of code snippets for this example | ||
snippets: | ||
- language: json | ||
# Reference to file | ||
ref: examples/derivation.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
@prefix mydata: <http://example.com/data/> . | ||
@prefix prov: <http://www.w3.org/ns/prov#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
@prefix sdo: <https://schema.org/> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
@prefix ex: <http://example.org/> . | ||
@prefix geo: <http://www.opengis.net/ont/geosparql#> . | ||
@prefix sf: <http://www.opengis.net/ont/sf#> . | ||
|
||
|
||
<http://example.com/activities/add1> | ||
a prov:Activity ; | ||
rdfs:label "Adder-run1" ; | ||
prov:endedAtTime "2029-01-01T22:05:19+02:00"^^xsd:dateTime ; | ||
prov:generated mydata:c ; | ||
prov:used mydata:a, mydata:b ; | ||
prov:wasAssociatedWith <http://example.com/agents/adder> . | ||
|
||
mydata:a | ||
a prov:Entity ; | ||
rdfs:label "A" ; | ||
sdo:value 1 | ||
. | ||
|
||
mydata:b | ||
a prov:Entity ; | ||
rdfs:label "B" ; | ||
sdo:value 2 | ||
. | ||
|
||
mydata:c | ||
a <http://example.com/data/results/c> ; | ||
geo:hasGeometry [ geo:asWKT """POLYGON((150.5000 -34.0000, 150.5020 -34.0005, 150.5040 -34.0010, 150.5060 -34.0015, | ||
150.5080 -34.0020, 150.5100 -34.0025, 150.5120 -34.0030, 150.5140 -34.0035, | ||
150.5160 -34.0040, 150.5180 -34.0045, 150.5200 -34.0050, 150.5220 -34.0045, | ||
150.5240 -34.0040, 150.5260 -34.0035, 150.5280 -34.0030, 150.5300 -34.0025, | ||
150.5280 -34.0020, 150.5260 -34.0015, 150.5240 -34.0010, 150.5220 -34.0005, | ||
150.5200 -34.0000, 150.5180 -34.0005, 150.5160 -34.0010, 150.5140 -34.0015, | ||
150.5120 -34.0020, 150.5100 -34.0025, 150.5080 -34.0030, 150.5060 -34.0025, | ||
150.5040 -34.0020, 150.5020 -34.0015, 150.5000 -34.0010, 150.5000 -34.0000))"""^^geo:wktLiteral ; | ||
geo:asGeoJSON """{ | ||
"type": "Polygon", | ||
"coordinates": [[ | ||
[150.5000, -34.0000], [150.5020, -34.0005], [150.5040, -34.0010], [150.5060, -34.0015], | ||
[150.5080, -34.0020], [150.5100, -34.0025], [150.5120, -34.0030], [150.5140, -34.0035], | ||
[150.5160, -34.0040], [150.5180, -34.0045], [150.5200, -34.0050], [150.5220, -34.0045], | ||
[150.5240, -34.0040], [150.5260, -34.0035], [150.5280, -34.0030], [150.5300, -34.0025], | ||
[150.5280, -34.0020], [150.5260, -34.0015], [150.5240, -34.0010], [150.5220, -34.0005], | ||
[150.5200, -34.0000], [150.5180, -34.0005], [150.5160, -34.0010], [150.5140, -34.0015], | ||
[150.5120, -34.0020], [150.5100, -34.0025], [150.5080, -34.0030], [150.5060, -34.0025], | ||
[150.5040, -34.0020], [150.5020, -34.0015], [150.5000, -34.0010], [150.5000, -34.0000] | ||
]] | ||
}"""^^geo:geoJSONLiteral | ||
]; | ||
|
||
rdfs:label "C" ; | ||
sdo:value 3 ; | ||
prov:wasDerivedFrom mydata:a, mydata:b ; | ||
prov:wasGeneratedBy <http://example.com/activities/add1> . | ||
|
||
<http://example.com/agents/adder> | ||
a prov:Agent ; | ||
rdfs:label "Add" ; | ||
sdo:description "Adds all input values" | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"provType": [ "Activity", "Derivation" ], | ||
"id": "derivation_example", | ||
"endedAtTime": "2029-01-01T22:05:19+02:00", | ||
"wasAssociatedWith": "eg_agents:bc-3", | ||
"generated": { "id": "mydata:YearlySummary", | ||
"wasDerivedFrom" : "mydata:WeeklyRecords", | ||
"wasGeneratedBy" : "derivation_example" | ||
}, | ||
"used": "mydata:WeeklyRecords" | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
description: Derivation activity | ||
$defs: | ||
Derivation: | ||
allOf: | ||
- $ref: bblocks://ogc.ogc-utils.prov#/$defs/Activity | ||
- properties: | ||
provType: | ||
type: array | ||
contains: | ||
type: string | ||
const: Derivation | ||
required: | ||
- provType | ||
- generated | ||
- used | ||
|
||
anyOf: | ||
- $ref: "#/$defs/Derivation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CLEAR GRAPH $graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<tag:stardog:api:graph:aliases> { | ||
<tag:cross-domain-model> <tag:stardog:api:graph:alias> <https://www.w3.org/ns/prov> . | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
prefix prov: <http://www.w3.org/ns/prov#> | ||
SELECT ?A ?p ?plabel ?o ?olabel | ||
WHERE { | ||
$entity prov:wasGeneratedBy ?A . | ||
?A ?p ?o . | ||
OPTIONAL { ?p rdfs:label ?plabel } | ||
OPTIONAL { ?o rdfs:label ?olabel } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
prefix prov: <http://www.w3.org/ns/prov#> | ||
SELECT $entity ?p ?plabel ?o ?olabel | ||
WHERE { | ||
$entity ?p ?o . | ||
OPTIONAL { ?p rdfs:label ?plabel } | ||
OPTIONAL { ?o rdfs:label ?olabel } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
prefix prov: <http://www.w3.org/ns/prov#> | ||
prefix geo: <http://www.opengis.net/ont/geosparql#> | ||
SELECT $entity ?label ?geojson ?wkt | ||
WHERE { | ||
$entity geo:hasGeometry ?g . | ||
OPTIONAL { ?g geo:asGeoJSON ?geojson } | ||
OPTIONAL { ?g geo:asWKT ?wkt } | ||
OPTIONAL { $entity rdfs:label ?label } | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import csv | ||
import os | ||
import requests | ||
from requests.auth import HTTPBasicAuth | ||
|
||
# Retrieve the server, database, username, and password from environment variables | ||
stardog_server = os.getenv('STARDOG_SERVER') | ||
stardog_database = os.getenv('STARDOG_DATABASE') | ||
username = os.getenv('STARDOG_USERNAME') | ||
password = os.getenv('STARDOG_PASSWORD') | ||
|
||
# Check if all required environment variables are set | ||
if not all([stardog_server, stardog_database, username, password]): | ||
raise ValueError("One or more required environment variables are not set") | ||
|
||
|
||
# Define the default value for the "model" column | ||
DEFAULT_MODEL = None | ||
|
||
|
||
def load(filename, uri, context, model): | ||
""" | ||
Load a data file into stardog, so that it appears as a named graph. | ||
The named graph is included in an "alias" - allowing multiple queryable data collections to co-exist. | ||
Todo: force entailment using the named "model" as a reasoning graph | ||
Parameters: | ||
- name: The filename of the graph. | ||
- uri: The URI for the named graph. | ||
- context: The alias (collection) graph to include the new data in. | ||
- [ model: The reasoning model (T-box) . ] | ||
""" | ||
# Set up the headers | ||
with open(filename, 'r') as file: | ||
data = file.read() | ||
|
||
headers = { | ||
'Content-Type': 'text/turtle', | ||
'Accept': 'application/sparql-results+json' | ||
} | ||
# Construct the Stardog URL | ||
stardog_url = f"{stardog_server}/{stardog_database}?graph={uri}" | ||
|
||
# Send the POST request with Basic Authentication | ||
response = requests.put( | ||
stardog_url, | ||
headers=headers, | ||
data=data, | ||
auth=HTTPBasicAuth(username, password) | ||
) | ||
|
||
# Check if the request was successful | ||
if response.status_code in [200,201]: | ||
# Print the response JSON (assuming it's in JSON format) | ||
print(f"{filename} - > {uri} : {response.status_code}") | ||
else: | ||
print(f"Error: {filename} - > {uri} : {response.status_code}") | ||
print(response.text) | ||
|
||
|
||
def process_csv(file_path): | ||
with open(file_path, newline='') as csvfile: | ||
reader = csv.DictReader(csvfile) | ||
for row in reader: | ||
name = row.get('filename') | ||
uri = row.get('uri') | ||
context = row.get('context') | ||
model = row.get('model', DEFAULT_MODEL) # Use default model if not present | ||
|
||
# Call the load function with the values from the CSV row | ||
load(name, uri, context, model) | ||
|
||
|
||
# Specify the path to your CSV file | ||
csv_file_path = 'manifest.csv' | ||
|
||
# Process the CSV file | ||
process_csv(csv_file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
filename,uri,context,model | ||
../_sources/activities/derivation/examples/a-plus-b.ttl,tag:prov:a-plus-b,tag:prov-demo,tag:prov-demo-model |
Oops, something went wrong.