Update queryExample authored by Adam Kučera's avatar Adam Kučera
...@@ -5,7 +5,7 @@ The RDF definitions of the ontology reside here: http://is.muni.cz/www/255658/sb ...@@ -5,7 +5,7 @@ The RDF definitions of the ontology reside here: http://is.muni.cz/www/255658/sb
## SPARQL query example ## SPARQL query example
When populated by proper individuals, ontology can be used as data source for SPARQL queries. When populated by proper individuals, the ontology can be used as a data source for SPARQL queries.
SPARQL Query that collects all the available data about a data point has following structure (in this particular case, the data point has BMS ID ``11304.AI3'': SPARQL Query that collects all the available data about a data point has following structure (in this particular case, the data point has BMS ID ``11304.AI3'':
...@@ -74,4 +74,97 @@ WHERE ...@@ -74,4 +74,97 @@ WHERE
?datapoint sbms:publishedByDevice ?publisher. ?datapoint sbms:publishedByDevice ?publisher.
?publisher sbim:hasBIMId ?publisherbimId ?publisher sbim:hasBIMId ?publisherbimId
} }
```
## Translation of a RESTful Semantic API call to the SPARQL
The example below illustrates translation of the RESTful query to the SPARQL query and shows the JSON response.
### RESTful request
```
http://.../sbms/semantics/datapoints/
?fields=bmsId,type,source.bimId,source.type,scope.bimId,
scope.type,sensing.type,sensing.window,publisher.bimId
&grouping=noGrouping
&source.type=TemperatureSensor
&property.domain=Air
&property.quality=temperature
```
### SPARQL query
```
SELECT ?bmsId ?type ?sourcebimId ?sourcetype ?scopebimId ?scopetype ?sensingtype ?sensingwindow ?publisherbimId
WHERE
{ ?datapoint <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#hasBMSId> ?bmsId ;
<http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#expressesObservation> ?obs .
?obs <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#observedBy> ?source .
?source <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBIM#hasBIMId> ?sourcebimId .
?obs <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#featureOfInterest> ?scope .
?scope <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBIM#hasBIMId> ?scopebimId .
?obs <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#sensingMethodUsed> ?sensing
OPTIONAL
{ ?sensing <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#hasAggregationTimeWindow> ?sensingwindow}
?obs <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#observedProperty> ?property .
?property <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#hasPhysicalQuality> <http://purl.oclc.org/NET/muo/ucum/physical-quality/temperature> ;
<http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#hasPropertyDomain> <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#Air> .
?datapoint <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#publishedByDevice> ?publisher .
?publisher <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBIM#hasBIMId> ?publisherbimId .
?sensing a ?sensingtype .
?sensingtype <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#Sensing>
FILTER NOT EXISTS { ?subtype <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?sensingtype
FILTER ( ( ?subtype != ?sensingtype ) && ( ?subtype != <http://www.w3.org/2002/07/owl#Nothing> ) )
}
?scope a ?scopetype .
?scopetype <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBIM#Facility>
FILTER NOT EXISTS { ?subtype <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?scopetype
FILTER ( ( ?subtype != ?scopetype ) && ( ?subtype != <http://www.w3.org/2002/07/owl#Nothing> ) )
}
?source a ?sourcetype .
?sourcetype <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBIM#Device>
FILTER NOT EXISTS { ?subtype <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?sourcetype
FILTER ( ( ?subtype != ?sourcetype ) && ( ?subtype != <http://www.w3.org/2002/07/owl#Nothing> ) )
}
?source a <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBIM#TemperatureSensor> .
?datapoint a ?type .
?type <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://is.muni.cz/www/255658/sbms/v2_0/SemanticBMS#DataPoint>
FILTER NOT EXISTS { ?subtype <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?type
FILTER ( ( ?subtype != ?type ) && ( ?subtype != <http://www.w3.org/2002/07/owl#Nothing> ) )
}
}
```
### JSON response
(simplified due to the space considerations -- the query on the sample dataset return 750 items)
```
{
"results": {
"noGrouping": [
{
"bmsId": "11304.AI3",
"type": "Input",
"publisher": {
"bimId": "BHA14N01013MAKB001"
},
"source": {
"bimId": "BHA14N01012MABT001",
"type": "TemperatureSensor"
},
"scope": {
"bimId": "BHA14N01012",
"type": "Room"
},
"sensing": {
"type": "StatelessDirectSensing"
}
}
]
},
"groups": [
"noGrouping"
]
}
``` ```
\ No newline at end of file