9.2.5 Semantic Query
When a SPARQL query is created, it can be passed in the "semanticFilter" request parameter, shown below with the shortname form of the request parameter of "smf". The query must first be ascii encoded. Using python, the following code will execute query 4 from above to dynamically determine all four primitives needed to use the SDT model of the washing machine. Additionally, the "Semantic Query Indicator", "sqi", is set to "1" to distinguish this query request from a semantic discovery request. A semantic discovery request will return a list of URIs that match the query rather than a query response.
query = '''PREFIX sn:<http://www.XYZ.com/WashingMachines#>
PREFIX m2m: <https://git.onem2m.org/MAS/BaseOntology/raw/master/base_ontology.owl#>
PREFIX saref: <https://saref.etsi.org/core/>
SELECT ?sarefCommand ?method ?targetURI ?attr ?res
WHERE {
?wm m2m:hasOperation ?operation .
?operation a m2m:Operation .
?operation m2m:oneM2MMethod ?method .
optional {?operation m2m:hasDataRestriction ?res} .
optional {?operation m2m:oneM2Mattribute ?attr} .
?operation a ?sarefCommand .
?operation m2m:oneM2MTargetURI ?targetURI .
VALUES ?wm {<http://www.XYZ.com/WashingMachines#XYZ_CoolWASH_XYZ_deviceClothesWasher>} .
VALUES ?sarefCommand {saref:GetCommand saref:OnCommand saref:OffCommand saref:ToggleCommand}
}
ORDER BY ?sarefCommand
'''
encSMQ = encodedSparqlQuery(query)
RETRIEVE (
'http://localhost:50000/oneM2M-semantics?fu=1&sqi=1&smf='+ encSMQ,
# Request Headers
{
'X-M2M-Origin' : originator2, # Set the originator
'X-M2M-RI' : 'semQ1', # Unique request identifier
'X-M2M-RVI' : '3', # Release verson indicator
'Accept' : 'application/json' # Response shall be JSON
}
)
The resulting oneM2M primitive request and response using the HTTP protocol binding and JSON payload binding is shown below. It is important to note the JSON response to the query. An application will have to parse the response from the query to get the desired information.
Sending request to
http://localhost:50000/oneM2M-semantics?fu=1&sqi=1&smf=PREFIX sn%3A<http%3A%2F%2Fwww.XYZ.com%2FWashingMachines%23> PREFIX m2m%3A <https%3A%2F%2Fgit.onem2m.org%2FMAS%2FBaseOntology%2Fraw%2Fmaster%2Fbase_ontology.owl%23> PREFIX saref%3A <https%3A%2F%2Fsaref.etsi.org%2Fcore%2F> SELECT %3FsarefCommand %3Fmethod %3FtargetURI %3Fattr %3Fres WHERE { %3Fwm m2m%3AhasOperation %3Foperation . %3Foperation a m2m%3AOperation . %3Foperation m2m%3AoneM2MMethod %3Fmethod . optional {%3Foperation m2m%3AhasDataRestriction %3Fres} . optional {%3Foperation m2m%3AoneM2Mattribute %3Fattr} . %3Foperation a %3FsarefCommand . %3Foperation m2m%3AoneM2MTargetURI %3FtargetURI . VALUES %3Fwm {<http%3A%2F%2Fwww.XYZ.com%2FWashingMachines%23XYZ_CoolWASH_XYZ_deviceClothesWasher>} . VALUES %3FsarefCommand {saref%3AGetCommand saref%3AOnCommand saref%3AOffCommand saref%3AToggleCommand} } ORDER BY %3FsarefCommand
CHECK WHITESPACE
Headers missing text
Response missing text
Body
[
{
"attr": {
"type": "literal",
"value": "currentMachineState"
},
"method": {
"type": "literal",
"value": "RETRIEVE"
},
"sarefCommand": {
"type": "uri",
"value": "https://saref.etsi.org/core/GetCommand"
},
"targetURI": {
"type": "literal",
"value": "/deviceClothesWasher/runState"
}
},
{
"attr": {
"type": "literal",
"value": "powerState"
},
"method": {
"type": "literal",
"value": "UPDATE"
},
"res": {
"type": "literal",
"value": "False"
},
"sarefCommand": {
"type": "uri",
"value": ""
},
"targetURI": {
"type": "literal",
"value": "/deviceClothesWasher/binarySwitch"
}
},
{
"attr": {
"type": "literal",
"value": "powerState"
},
"method": {
"type": "literal",
"value": "UPDATE"
},
"res": {
"type": "literal",
"value": "True"
},
"sarefCommand": {
"type": "uri",
"value": ""
},
"targetURI": {
"type": "literal",
"value": "/deviceClothesWasher/binarySwitch"
}
},
{
"method": {
"type": "literal",
"value": "UPDATE"
},
"sarefCommand": {
"type": "uri",
"value": ""
},
"targetURI": {
"type": "literal",
"value": "/deviceClothesWasher/binarySwitch/toggle"
}
}
]