Package: sdf-wot-converter
SDF-WoT-ConverterThis repository provides a Python-based converter fromSDFtoWoT TDincluding Thing Models.The converter is both usable as a library and a command line tool. It provides
conversion functions between WoT Thing Descriptions, WoT Thing Models and SDF
Models (one for each combination). You can find a number of examples for the
usage of the converter down below as well as overviews for the conversion
between SDF and WoT TMs.The CI pipeline is set up to automatically convert all (valid) models from theoneDM playgroundto WoT Thing Models and upload to the results tothis repository.InstallationYou can install the converter using pip:pipinstallsdf-wot-converterAfterwards, it can be used both as a command line tool and a library.Using the command line toolAfter installing the libary you should be able to call the converter in your terminal usingsdf-wot-converterand one of the six available subcommands:sdf-to-tmsdf-to-tdtd-to-tmtd-to-sdftm-to-tdtm-to-sdfYou can display available parameters by typingsdf-wot-converter --help.
A usage example for each subcommand can be found below.Examples# Convert an SDF model to a WoT Thing Modelsdf-wot-convertersdf-to-tm-iexamples/sdf/example.sdf.json-oconverted-example.tm.jsonld# Convert an SDF model to a WoT Thing Descriptionsdf-wot-convertersdf-to-td-iexamples/sdf/example.sdf.json--mapping-filesexamples/sdf/example.sdf-mapping.json-oconverted-example.td.jsonld# Convert a WoT Thing Model to an SDF modelsdf-wot-convertertm-to-sdf-iexamples/wot/example.tm.jsonld-oconverted-example.sdf.json# Convert a WoT Thing Model to a WoT Thing Descriptionsdf-wot-convertertm-to-td-iexamples/wot/example-with-bindings.tm.jsonld-oconverted-example.td.jsonld# Convert a WoT Thing Description to an SDF model and a mapping filesdf-wot-convertertd-to-sdf-iexamples/wot/example.td.jsonld-oconverted-example.sdf.json--mapping-file-outputconverted-example.sdf-mapping.json# Convert a WoT Thing Description to a WoT Thing Modelsdf-wot-convertertd-to-tm-iexamples/wot/example.td.jsonld-oconverted-example.tm.jsonldUsing the libraryWith the converter installed, you can use also use it as a library in your own projects. Below you can see examples for how to convert an SDF model to a WoT Thing Model and back again. As you can see, nested definitions fromsdfObjects orsdfThings are prefixed with the respective object or thing names.fromsdf_wot_converterimport(convert_sdf_to_wot_tm,convert_wot_tm_to_sdf,)sdf_model={"info":{"title":"Example file for OneDM Semantic Definition Format","version":"2019-04-24","copyright":"Copyright 2019 Example Corp. All rights reserved.","license":"https://example.com/license",},"namespace":{"cap":"https://example.com/capability/cap"},"defaultNamespace":"cap","sdfObject":{"Switch":{"sdfProperty":{"value":{"description":"The state of the switch; false for off and true for on.","type":"boolean","observable":False,}},"sdfAction":{"on":{"description":"Turn the switch on; equivalent to setting value to true."},"off":{"description":"Turn the switch off; equivalent to setting value to false."},"toggle":{"description":"Toggle the switch; equivalent to setting value to its complement."},},}},}thing_model=convert_sdf_to_wot_tm(sdf_model)expected_thing_model={"@context":["https://www.w3.org/2022/wot/td/v1.1",{"cap":"https://example.com/capability/cap","sdf":"https://example.com/sdf",},],"@type":"tm:ThingModel","sdf:title":"Example file for OneDM Semantic Definition Format","sdf:copyright":"Copyright 2019 Example Corp. All rights reserved.","links":[{"href":"https://example.com/license","rel":"license"}],"version":{"model":"2019-04-24"},"sdf:defaultNamespace":"cap","actions":{"on":{"description":"Turn the switch on; equivalent to setting value to true.",},"off":{"description":"Turn the switch off; equivalent to setting value to false.",},"toggle":{"description":"Toggle the switch; equivalent to setting value to its complement.",},},"properties":{"value":{"description":"The state of the switch; false for off and true for on.","type":"boolean","observable":False,}},"sdf:objectKey":"Switch",}assertthing_model==expected_thing_modelsdf_roundtrip_model=convert_wot_tm_to_sdf(thing_model)assertsdf_model==sdf_roundtrip_modelMappings OverviewSDF to WoTBelow you can find a mapping of the most important keywords of SDF to WoT.
We use Thing Models (TMs) as a reference here, as they are most similar to SDF
models.
When converting from SDF to WoT TD, the SDF model (and a mapping file which must
provide the necessary instance-specific information) is first converted to a TM,
which is in turn converted to a TD.SDF KeywordWoT Class/KeywordsdfThingTM withtm:submodellinkssdfObjectTM withouttm:submodellinkssdfPropertyPropertyAffordancewritablereadOnly(negated)readablewriteOnly(negated)sdfActionActionAffordancesdfInputDatainputsdfOutputDataoutputsdfEventEventAffordancesdfOutputDataoutputsdfDataschemaDefinitions (at the Thing level)sdfReftm:refsdfChoiceEnum of JSON objects with an (additional)sdf:choiceNamesdfRequiredtm:requirednamespaces@contextdefaultNamespacesdf:defaultNamespaceInfo BlockMultiple targetsversionmodelfield in theVersionclasstitlesdf:titlecopyrightsdf:copyrightlicenselink with relation-typelicense(if license value is a URL) orsdf:licenseWoT to SDFBelow you can find a mapping of some of the most important classes and keywords from WoT to SDF. Note that there are still
some definitions missing in the table that are already covered by the converter implementation.WoT TD definitions which are not covered by the core SDF vocabulary are mapped to a so-called SDF mapping file
(seedraft-bormann-asdf-sdf-mapping).WoT Class/KeywordSDF KeywordThingsdfThing (if TM hastm:submodellinks), sdfObjecttitlelabeldescriptiondescriptionschemaDefinitionssdfData@contextnamespacesof the SDF model (with exceptions)DataSchemadataqualitiesreadOnlyMapping FilewriteOnlyMapping FileInteractionAffordance(Common Qualities)titlelabeldescriptiondescriptionPropertyAffordancesdfPropertyreadOnlywritable(negated)writeOnlyreadable(negated)observableobservable(negated)ActionAffordancesdfActioninputsdfInputDataoutputsdfOutputDataEventAffordancesdfEventoutputsdfOutputDatasubscriptionMapping FilecancellationMapping FiledataResponseMapping Filetm:refsdfReftm:requiredsdfRequiredLinkMapping File, except for special link types (license,tm:extends,tm:submodel)LicenseThis project is licensed under the MIT license.SPDX-License-Identifier: MIT