M3 API and user interface documentation

M3 API and user interface documentation
Designing Semantic Web of Things Applications with M3
M3 API Documentation and user interface for developers
Creator
Send
Feedback
Goal
Requirement
Created
Last updated
Status
URL
Amelie Gyrard (Eurecom)
Do not hesitate to ask for help or give us feedback, advices to improve our
tools or documentations, fix bugs and make them more user-friendly and
convenient:
•
This documentation guides developers to design Semantic Web of
Things applications thanks to the Machine-to-Machine Measurement
(M3) framework through APIs that we develop or user interfaces.
• Get Semantic Web of Things templates with web services or the user
interface
• Use the M3 converter to semantically annotate IoT data
• Interpret IoT data and get suggestions or high level abstractions
• A tutorial is also included to design the application with the M3 and
Jena framework.
• Use LOV4IoT web services
• Use M3 nomenclature and M3 ontology web services
Use the Jena Framework.
April 22, 2015
February 25, 2016
Work in progress
http://www.sensormeasurement.appspot.com/documentation/M3APIDocum
entation.pdf
This documentation guides developers to design Semantic Web of Things applications thanks to
the Machine-to-Machine Measurement (M3) framework.
It will assist them in:
• Generating IoT templates. The developers do not need to design any ontologies,
datasets and rules, they are provided in the M3 templates.
• Semantically annotating IoT data. The developers not need to semantically annotate
his IoT data. It will be automatically done by the M3 converter.
• Interpreting IoT data. The developers are assisted by the M3 framework to interpret
IoT data. They will get high-level abstractions or even M3 suggestions according to the
M3 template chosen.
In this documentation, the developers can either use web service or user interface.
Table of Contents
I. Tutorial: Building the naturopathy application with the user interface SWoT generator
and the Jena framework ............................................................................................................. 3
1.
Generating the naturopathy template with the SWoT generator................................... 3
2.
Explore the naturopathy template .................................................................................. 4
3.
Get the sensor dataset already converted with M3 ........................................................ 5
4.
Be familiar with the Jena framework ............................................................................... 6
5.
Load the sensor dataset in your Java application with the Jena framework................... 6
6.
Load the ontologies and datasets in your Java application with the Jena framework.... 6
1.
Load the rules and execute the Jena reasoner ................................................................ 7
2.
Modify the SPARQL query ................................................................................................ 7
3.
Execute the SPARQL query with Jena .............................................................................. 8
4.
Check that the naturopathy application works ............................................................... 9
II.
Generating IoT templates with M3 user interface or web services .................................. 10
1.
M3 User interface........................................................................................................... 10
2.
M3 Web Service: looking for IoT application template ................................................. 11
3.
M3 Web Service: generating IoT application template ................................................. 12
4.
M3 Web Service: generating the SPARQL query with variables replaced ..................... 13
5.
Code example ................................................................................................................. 15
III.
Semantically annotating IoT data with the M3 converter ............................................. 16
1.
M3 converter user interface .......................................................................................... 16
2.
Code example to semantically annotate IoT data with M3 ........................................... 17
3.
Enrich the M3 converter and adapt it to your data ....................................................... 17
IV.
Interpreting IoT data and getting M3 suggestions ........................................................ 19
1.
Loading M3 domain knowledge ..................................................................................... 19
2.
Executing rules ............................................................................................................... 20
3.
Executing SPARQL query ................................................................................................ 20
4.
Finishing the application ................................................................................................ 20
5.
Code summary ............................................................................................................... 21
V.
Summary: Developing Semantic Web of Things applications ........................................... 21
VI.
Query the M3 nomenlature/ontology ........................................................................... 22
1.
Web service: querying sensors ...................................................................................... 22
2.
Web service: querying actuators ................................................................................... 23
3.
Web service: querying domains ..................................................................................... 23
4.
Web service: querying health devices ........................................................................... 23
5.
Web service: querying transport devices....................................................................... 24
6.
Web service: querying home devices ............................................................................ 24
VII.
LOV4IoT web services .................................................................................................... 24
1.
Web service: Get the total number of ontologies ......................................................... 24
2.
Web service: Get the number od ontologies by domains ............................................. 25
3.
Web service: Get the number of ontology by ontology status...................................... 26
4.
Use case .......................................................................................................................... 27
VIII.
Citations ......................................................................................................................... 28
I.
Tutorial: Building the naturopathy
application with the user interface
SWoT generator and the Jena
framework
1. Generating the naturopathy template with the
SWoT generator
• Go on this web page:
http://www.sensormeasurement.appspot.com/?p=m3api
• Choose the sensor ‘Thermometer’ in the drop-down list.
• Choose the domain ‘Healthcare’ in the drop-down list.
•
•
Choose the template ‘Body Temperature, Symptoms and Home Remedies’ in the dropdown list. In this case, we suggest only one template.
Click on the button ‘Generate ZIP file.’
Figure 1. Download the naturopathy template using the SWoT generator
2. Explore the naturopathy template
Open the naturopathy template that you just downloaded. This template is composed of the
following files:
• ruleM3Converter.txt: a set of rules used to convert sensor data according to our M3
language implemented in the M3 ontology. For instance, we use the term temperature
and not term. An essential basis for the reasoning.
• naturopathy.owl: the naturopathy ontology
• naturopathy-dataset.rdf: the naturopathy dataset
• m3SparqlGeneric.sparql: the SPARQL query to get smarter data or even suggestions.
For instance, get home remedies when you have the fever.
• m3.owl: the M3 ontology essential to describe sensor data in an interoperable manner
to ease the reasoning and the interlinking of domains.
• LinkedOpenRulesHealth.txt: This file is a dataset of interoperable rules to interpret
health measurements. For instance: IF BodyTemperature > 38°C THEN HighFever.
• health.owl: the health ontology. For instance, Symptom is a concept defined in this
ontology.
• health-dataset.rdf: the health dataset. For instance, HighFever is an instance of the
Symptom concept in this dataset.
Figure 2. The naturopathy template
3. Get the sensor dataset already converted with M3
•
Download the sensor dataset:
http://www.sensormeasurement.appspot.com/dataset/sensor_data/senml_m3_health
_data.rdf
To begin with, try with the sensor dataset that we have already converted according to the M3
ontology. In the extract below, you have the measurement ‘temperature 38°C’, a new type has
been added ‘BodyTemperature’ which will be used in the reasoning process to infer high-level
abstractions.
Figure 3. Extract of the sensor dataset
4. Be familiar with the Jena framework
Jena tutorial if you are not familiar with this framework: https://jena.apache.org/
5. Load the sensor dataset in your Java application
with the Jena framework
Java code example:
Figure 4.Load the Sensor dataset with Jena
ReadFile Java Class:
Java code example:
Figure 5.Load a file (ontology or RDF dataset) in the Jena model
6. Load the ontologies and datasets in your Java
application with the Jena framework
// load m3.owl
ReadFile.enrichJenaModelOntologyDataset(model, ROOT_OWL_WAR + "m3");
// load naturopathy.owl
ReadFile.enrichJenaModelOntologyDataset(model, NATUROPATHY_ONTOLOGY_PATH);
// load naturopathy-dataset.rdf
ReadFile.enrichJenaModelOntologyDataset(model, NATUROPATHY_DATASET_PATH);
// load health.owl
ReadFile.enrichJenaModelOntologyDataset(model, HEALTH_ONTOLOGY_PATH);
// load health-dataset.rdf
ReadFile.enrichJenaModelOntologyDataset(model, HEALTH_DATASET_PATH);
1. Load the rules and execute the Jena reasoner
// load LinkedOpenRulesHealth.txt
Figure 6.Load rules and execute the Jena reasoner
2. Modify the SPARQL query
Java code example to modify the SPARQL query with variables:
Figure 7.Modify variables in the SPARQL query
In this example, we are looking for BodyTemperature measurements in the dataset.
VariableSparql Java Class:
Figure 8. The VariableSparql Java Class example
3. Execute the SPARQL query with Jena
// load m3SparqlGeneric.sparql
Figure 9. Execute the SPARQL query example
ExecuteSparqlGeneric Java class
Figure 10. Get the result of the SPARQL query, more precisely the high level abstractions
ExecuteSparqlGeneric Java class
Figure 11. ExecuteSparqlGeneric Java class example
4. Check that the naturopathy application works
You should have the results in xml, if it not empty it works!
Congratulations!
You can then design your own applications, and display the result in a user interface.
Figure 12. Suggestions provided by the SPARQL query from the template
II.
Generating IoT templates with M3
user interface or web services
1. M3 User interface
You can use the user interface: http://www.sensormeasurement.appspot.com/?p=m3api
See user guide: www.sensormeasurement.appspot.com/documentation/UserGuide.pdf
Figure 13. Generating M3 templates using M3 user interface
Be careful, the SPARQL query generated does not have SPARQL variables
replaced.
Due to technical issues with Google Web Toolkit (cannot write in a file),
please use the M3 web service to generate the SPARQL query with variables
replaced.
If you are familiar with SPARQL, you can replace variables yourself.
2. M3 Web Service: looking for IoT application
template
Web service URL:
http://www.sensormeasurement.appspot.com/m3/searchTemplate/?sensorName=LightSensor
&domain=Weather&format=json
Description: You are looking for IoT application templates with the following parameters:
• sensorName=LightSensor
The parameter sensorName is the name of the sensor.
If you want to indicate another sensorName , see:
http://www.sensormeasurement.appspot.com/documentation/NomenclatureSensorData.pdf
domain=Weather
The parameter domain is where is deployed your sensor.
If you want to indicate another domain, see:
http://www.sensormeasurement.appspot.com/documentation/NomenclatureSensorData.pdf
format= json
The parameter format can be json or xml
Results:
Figure 14. Looking for the M3 templates
3. M3 Web Service: generating IoT application
template
Web service URL:
http://sensormeasurement.appspot.com/m3/generateTemplate/?iotAppli=WeatherTransporta
tionSafetyDeviceLight
Description: To generate the domain knowledge needed to build the IoT application template:
• ioTappli=WeatherTransportationSafetyDeviceLight
The parameter ioTappli is the end of the m2mappli URI that you can find in the result provided
by the previous web service
(http://www.sensormeasurement.appspot.com/m3/searchTemplate/?sensorName=LightSenso
r&domain=Weather&format=json)
Results:
http://sensormeasurement.appspot.com/ont/m3/transport#@http://sensormeasureme
nt.appspot.com/RULES/LinkedOpenRulesWeather.txt@http://sensormeasurement.apps
pot.com/SPARQL/m3SparqlGeneric.sparql@http://sensormeasurement.appspot.com/da
taset/transportdataset/@http://sensormeasurement.appspot.com/dataset/weatherdataset/@http://sensormeasurement.appspot.com/ont/m3/weather#@http://sensorme
asurement.appspot.com/m3#@
All URI files generated as separated by @.
URI finishing with # are ontologies
URI finishing with / are datasets
URI finishing with .txt are rules
URI finishing with .sparql are SPARQL queries to query data (to ignore because of google app
engine wa cannot automatically generate/write a new file)
To get the SPARQL query ask the web service:
http://sensormeasurement.appspot.com/m3/getSparqlQuery/?iotAppli=WeatherTransportatio
nSafetyDeviceLight (see next section)
4. M3 Web Service: generating the SPARQL query
with variables replaced
http://sensormeasurement.appspot.com/m3/getSparqlQuery/?iotAppli=WeatherTransportatio
nSafetyDeviceLight
Generate the generic sparql query with variables replaced
Results:
Figure 15. Generating the M3 SPARQL query
5. Code example
Figure 16. Generating M3 templates using M3 web services
III.
Semantically annotating IoT data
with the M3 converter
1. M3 converter user interface
The developer can use the M3 converter user interface:
http://www.sensormeasurement.appspot.com/?p=senml_converter
See user guide: www.sensormeasurement.appspot.com/documentation/UserGuide.pdf
Use Chrome to get the data in a text format, with Firefox you only have the
JavaScript alert popup.
Figure 17. Semantically annotating IoT data with the M3 converter user interface
2. Code example to semantically annotate IoT data
with M3
Figure 18. Semantically annotating IoT data with the M3 converter web service
3. Enrich the M3 converter and adapt it to your data
When you download a template with the SWoT generator 1 you also get the rules to
semantically annotate data, the file is called ’ruleM3Converter.txt’.
We did not have time to implement all the M3 nomenclature. Further, we
frequently update the M3 nomenclature 2.
But you can still improve and add more rules to semantically annotate your sensor
data.
1
2
http://www.sensormeasurement.appspot.com/?p=m3api
http://www.sensormeasurement.appspot.com/documentation/NomenclatureSensorData.pdf
Figure 19. Rules provided in the template to semantically annotate sensor data
The following rule means that we explicitly add the context:
If you get a temperature from health domain (subclassOf m3:FeatureOfInterest), we will
explicitly add that it corresponds to a body temperature.
Figure 20. Add new rules to semantically annotate sensor data according to the M3 ontology.
This is important because after, you have the rules adapted to this kind of measurement.
Figure 21. Explicit M3 measurement type is reused in the reasoning process
IV.
Interpreting IoT data and getting
M3 suggestions
Several steps need to be achieved to interpret IoT data (see Figure 22):
• Loading M3 ontologies, datasets which have been generated in the M3 template.
• Loading M3 data.= which has been generated by the M3 converter.
• Interpreting IoT data using the Jena reasoned
• Executing the M3 SPARQL query which has been generated in the M3 template
• Parse the result and build the user interface , control actuators or send notification, etc.
1. Loading M3 domain knowledge
Jena tutorial:
http://jena.apache.org/tutorials/rdf_api.html
Code example:
// STEP 1: Loading M3 domain knowledge and m3_data
Model model = ModelFactory.createDefaultModel();
InputStream in = new FileInputStream(PATH_FILE + m3_data);
// m3_data has been generated with the M3 converter
model.read( in, fileURL );//read all ontologies generated in the M3 template (.owl)
model.read( in, fileURL );//read all datasets generated in the M3 template (.rdf)
in.close();
2. Executing rules
Jena tutorial:
http://jena.apache.org/documentation/inference/
Code example:
// STEP 2: Interpreting M3 data
Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(PATH_FILE +
LinkedOpenRules*.txt));
// LinkedOpenRules*.txt: rules generated in the M3 template
reasoner.setDerivationLogging(true);
InfModel infModel = ModelFactory.createInfModel(reasoner, model); //apply the reasoner
// infModel has been updated with high-level abstraction
3. Executing SPARQL query
Jena tutorial:
http://jena.apache.org/tutorials/rdf_api.html
Code example:
// STEP 3: Getting M3 suggestions
//
Executing the SPARQL query:
Query query = QueryFactory(m3_sparql); // m3_sparql has been generated in the M3 template
ResultSet results = QueryExecutionFactory.create(m3_sparql, model)
String m3_suggestions = ResultSetFormatter.asXMLString(results)
4. Finishing the application
The main task of the develop is to design a user-friendly interface or control actuators, etc.
according to the high-level abstractions deduce by M3 or the M3 suggestions provided by M3.
Code example:
// STEP 4: Parsing and displaying m3_suggestions to build the IoT application
// or control actuators, alerting, etc.
5. Code summary
Figure 22. Code example to interpret IoT data and get M3 suggestions
V.
Summary: Developing Semantic
Web of Things applications
 STEP 1: Getting the domain knowledge to interpret sensor data
o Use the web service (see M3 Web Service: generating IoT application template)
o Generating ontologies (.owl)
o Generating datasets (.rdf)
o Generating rules (LinkedOpenRules*.txt)
 STEP 2: Getting the SPARQL query
o Use the web service (see M3 Web Service: generating the SPARQL query with
variables replaced)
o Generating the SPARQL query: m3_sparql (.sparql)
 STEP 3: Converting your data using SenML to RDF converter
o http://www.sensormeasurement.appspot.com/?p=senml_converter
o See documentation:
www.sensormeasurement.appspot.com/documentation/UserGuide.pdf
o Storing the RDF M3 sensor data in a file "m3_data.rdf"
 STEP 4: Building the cross-domain IoT application:
o Tutorial: An Introduction to RDF and the Jena RDF API
o Storing RDF sensor data "m3_data.rdf" file in a Jena Model:
Model model = ModelFactory.createDefaultModel();
InputStream in = new FileInputStream(PATH_FILE + "m3_data.rdf");
model.read( in, fileURL );//read all ontologies generated in STEP 1 (.owl)
model.read( in, fileURL );//read all datasets generated in STEP 1 (.rdf)
in.close();
o Tutorial: Reasoners and rule engines: Jena inference support
o Download the files with rules:
Sensor-based Linked Open Rules (S-LOR) or generated in see M3 Web Service: generating IoT
application template
Syntax: Jena rules, fileName = "LinkedOpenRules*.txt"
o Reasoning on sensor data:
Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(PATH_FILE +
LinkedOpenRules*.txt));// read rules
reasoner.setDerivationLogging(true);
InfModel infModel = ModelFactory.createInfModel(reasoner, model); //apply the
reasoner
// infModel model updated with sensor data inferred
o Executing the SPARQL query:
Query query = QueryFactory(m3_sparql)
ResultSet results = QueryExecutionFactory.create(m3_sparql, model)
Return ResultSetFormatter.asXMLString(results)
o Parse and display the results to build the IoT application
VI.
Query the M3
nomenlature/ontology
1. Web service: querying sensors
Search for all M3 sensors:
http://www.sensormeasurement.appspot.com/m3/subclassOf/?nameClass=Sensor&format=js
on
Results:
2. Web service: querying actuators
Search for all M3 actuators:
http://www.sensormeasurement.appspot.com/m3/subclassOf/?nameClass=Actuator&format=j
son
3. Web service: querying domains
Search for all M3 domains (=FeatureOfInterest):
http://www.sensormeasurement.appspot.com/m3/subclassOf/?nameClass=FeatureOfInterest
&format=json
4. Web service: querying health devices
Search for all M3 health devices:
http://www.sensormeasurement.appspot.com/m3/subclassOf/?nameClass=HealthM2MDevice
&format=json
5. Web service: querying transport devices
Search for all M3 transport devices:
http://www.sensormeasurement.appspot.com/m3/subclassOf/?nameClass=TransportM2MDev
ice&format=json
6. Web service: querying home devices
Search for all M3 home devices:
http://www.sensormeasurement.appspot.com/m3/subclassOf/?nameClass=HomeM2MDevice
&format=json
VII.
LOV4IoT web services
Yan can download the LOV4IoT RDF dataset 3.
Otherwise, we design some web services:
1. Web service: Get the total number of ontologies
Query:
http://www.sensormeasurement.appspot.com/lov4iot/totalOnto/
3
http://www.sensormeasurement.appspot.com/dataset/lov4iot-dataset
Figure 23. LOV4IoT Web service to count the total number of ontologies
In the picture, 270 is the total number of ontologies referenced in the LOV4IoT RDF dataset.
2. Web service: Get the number of ontologies by
domains
Query:
http://www.sensormeasurement.appspot.com/lov4iot/nbOntoDomain/?domain=BuildingAuto
mation
For instance domain is: BuildingAutomation, Weather, Emotion, Agriculture, Health, Tourism,
Transportation, City, Energy, Environment, TrackingFood, Activity, Fire, TrackingCD,
TrackingDVD, SensorNetworks, Security.
The domain is referenced in the M3 nomenclature which is implemented in the M3 ontology
(subclassOf FeatureOfInterest).
Figure 24. LOV4IoT Web service to count the number of ontologies by domain
3. Web service: Get the number of ontology by
ontology status
Query:
http://www.sensormeasurement.appspot.com/lov4iot/ontoStatus/?status=Online
For instance, status is: Confidential, OngoingProcessOnline, WaitForAnswer, Online, OnelinLOV,
AlreadyLOV.
Figure 25. LOV4IoT Web service to count the number of ontologies by ontology status
The web service returns that 87 ontologies referenced in the LOV4IoT RDF dataset are online.
4. Use case
All of these web services have been used in the HTML LOV4IoT web page 4 to automatically
count the number of ontologies in the dataset (e.g., by domains, by ontology status, etc.)
4
http://www.sensormeasurement.appspot.com/?p=ontologies
LO4IoT web service:
/lov4iot/totalOnto/
LO4IoT web service:
/lov4iot/nbOntoDomain/
LO4IoT web service:
/lov4iot/ontoStatus/
Figure 26. LOV4IoT web services
VIII.
Citations
If you use our work, please do not forget to cite us:
o Standardizing generic cross-domain applications in Internet of Things [Gyrard et al.
2014]
o Helping IoT application developers with sensor-based linked open rules [Gyrard et
al., ISWC SSN 2014]
o Enrich machine-to-machine data with semantic web technologies for cross-domain
applications [Gyrard et al., WF-IOT 2014]
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising