This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Informatievlaanderen/feat/crowdscan
Feat/crowdscan
- Loading branch information
Showing
19 changed files
with
416 additions
and
5 deletions.
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
12 changes: 12 additions & 0 deletions
12
...informatievlaanderen/vsds/demonstrator/member/application/services/PropertyExtractor.java
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,12 @@ | ||
package be.informatievlaanderen.vsds.demonstrator.member.application.services; | ||
|
||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.RDFNode; | ||
|
||
import java.util.List; | ||
|
||
public interface PropertyExtractor { | ||
|
||
List<RDFNode> getProperties(Model model); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...rmatievlaanderen/vsds/demonstrator/member/application/services/PropertyPathExtractor.java
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,48 @@ | ||
package be.informatievlaanderen.vsds.demonstrator.member.application.services; | ||
|
||
import org.apache.jena.query.*; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.RDFNode; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PropertyPathExtractor implements PropertyExtractor { | ||
|
||
private static final String OBJECT_VAR_NAME = "object"; | ||
private static final String IRI_OPENING_SYMBOL = "<"; | ||
private final String queryString; | ||
|
||
private PropertyPathExtractor(String propertyPath) { | ||
queryString = "SELECT * where { ?subject %s ?object }".formatted(propertyPath); | ||
} | ||
|
||
/** | ||
* This factory method was provided for backwards compatibility. | ||
* In the past we supported properties to be provided as strings in a non IRI | ||
* format. | ||
* When a property is provided as a plain string, we wrap it to an IRI. | ||
* NOTE: Does not work with property paths -> ex:foo/ex:bar will not get auto | ||
* wrapping. | ||
*/ | ||
public static PropertyPathExtractor from(String propertyPath) { | ||
return propertyPath.startsWith(IRI_OPENING_SYMBOL) | ||
? new PropertyPathExtractor(propertyPath) | ||
: new PropertyPathExtractor("<%s>".formatted(propertyPath)); | ||
} | ||
|
||
@Override | ||
public List<RDFNode> getProperties(Model model) { | ||
final Query query = QueryFactory.create(queryString); | ||
try (QueryExecution queryExecution = QueryExecutionFactory.create(query, model)) { | ||
ResultSet resultSet = queryExecution.execSelect(); | ||
|
||
List<RDFNode> results = new ArrayList<>(); | ||
while (resultSet.hasNext()) { | ||
results.add(resultSet.next().get(OBJECT_VAR_NAME)); | ||
} | ||
return results; | ||
} | ||
} | ||
|
||
} |
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
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 @@ | ||
<https://crowdscan.be/id/zone/${environment}/${zone}> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://crowdscan.be/ns/Zone> . | ||
<https://crowdscan.be/id/zone/${environment}/${zone}> <http://www.opengis.net/ont/geosparql#asWKT> "${geometry}"^^<http://www.opengis.net/ont/geosparql#wktLiteral> . |
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
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
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,14 @@ | ||
{ | ||
"@context": { | ||
"@vocab": "https://www.crowdscan.be/ns/count#", | ||
"time": { | ||
"@type": "http://www.w3.org/2001/XMLSchema#DateTime" | ||
}, | ||
"timedelta": { | ||
"@type": "http://www.w3.org/2001/XMLSchema#int" | ||
}, | ||
"regions": { | ||
"@container": "@list" | ||
} | ||
} | ||
} |
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 @@ | ||
{ | ||
"@context": [ | ||
{ | ||
"@vocab": "https://www.crowdscan.be/ns/map#", | ||
"last_updated": { | ||
"@type": "http://www.w3.org/2001/XMLSchema#DateTime" | ||
} | ||
}, | ||
"http://geojson.org/geojson-ld/geojson-context.jsonld" | ||
] | ||
} |
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,50 @@ | ||
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 time: <http://www.w3.org/2006/time#> | ||
PREFIX : <https://www.crowdscan.be/ns/count#> | ||
|
||
CONSTRUCT { | ||
|
||
GRAPH ?observation { | ||
?observation a :Observation ; | ||
:time ?time ; | ||
:value ?value ; | ||
:environment ?environment ; | ||
:timedelta ?delta ; | ||
:region ?zone . | ||
} | ||
|
||
} WHERE { | ||
|
||
?header :environment ?environment . | ||
?header :time ?time . | ||
?header :timedelta ?timedelta . | ||
bind(strdt(concat("-PT", str(?timedelta), "M"), xsd:duration) as ?delta) . | ||
|
||
?payload :payload ?regions . | ||
{ | ||
SELECT (count(?first) as ?zoneCount) WHERE { ?list rdf:first ?first . } | ||
} | ||
|
||
OPTIONAL { filter(?zoneCount = 1) | ||
?list rdf:first ?value . | ||
bind(0 as ?zone) . | ||
} | ||
|
||
OPTIONAL { filter(?zoneCount > 1) | ||
{ | ||
SELECT ?value (count(?mid) as ?zone) | ||
WHERE | ||
{ | ||
?regions rdf:rest* ?mid . | ||
?mid rdf:rest ?node . | ||
?node rdf:first ?value . | ||
} | ||
GROUP BY ?node ?value | ||
} | ||
} | ||
|
||
bind(uri(concat("https://crowdscan.be/id/observation/", ?environment, "/", str(?zone))) as ?observation) . | ||
|
||
} |
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,30 @@ | ||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | ||
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> | ||
|
||
PREFIX : <https://crowdscan.be/ns/> | ||
PREFIX http: <https://crowdscan.be/ns/HttpRequest.> | ||
PREFIX obs: <http://def.isotc211.org/iso19156/2011/Observation#> | ||
PREFIX prov: <http://www.w3.org/ns/prov#> | ||
|
||
CONSTRUCT { | ||
?request a :HttpRequest . | ||
?request http:url ?url . | ||
?request http:body ?body . | ||
?request http:method "POST" . | ||
?request http:header ?type . | ||
?request http:header ?accept . | ||
} WHERE { | ||
?obs rdf:type obs:OM_Observation . | ||
?obs obs:OM_Observation.featureOfInterest ?loc . | ||
?obs prov:generatedAtTime ?obstime . | ||
|
||
|
||
bind(concat(replace(replace(str(?loc), "www.crowdscan.be", "crowdscan.be"),"box4","beacon"), "/") as ?locpart) . | ||
|
||
# set HTTP request parameters | ||
bind(bnode() as ?request) . | ||
bind("http://rdf4j-server:8080/rdf4j-server/repositories/locations" as ?url) . | ||
bind(concat("describe ?zone From <http://crowdscan-locations> Where { { select (max(?t) as ?max) Where { ?z <http://www.w3.org/ns/prov#generatedAtTime> ?time . Filter(?t < \"", str(?obstime), "\") . bind(str(?time) as ?t) . } } bind(IRI(concat(\"", ?locpart, "\", ?max)) as ?zone) . }") as ?body) . | ||
bind("Content-Type: application/sparql-query" as ?type) . | ||
bind("Accept: application/n-quads" as ?accept) . | ||
} |
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 @@ | ||
PREFIX : <https://crowdscan.be/ns/> | ||
|
||
|
||
CONSTRUCT { | ||
?s ?p ?o . | ||
} | ||
WHERE { | ||
?s ?p ?o . | ||
|
||
{SELECT ?request | ||
WHERE { | ||
?request a :HttpRequest . | ||
}} | ||
FILTER(?s != ?request) | ||
} |
Oops, something went wrong.