INTER-LAYER – Data and Semantics to Data and Semantics (DS2DS): Expressing data model in RDF

(Getting Ready) Scenario description

Lets consider a scenario in which we want to acheive interoperability on data and semantics layer between IoT artifacts witn INTER-IoT. One of the artifacts can be a platform that should publish data about devices controlled by it. Lets assume that the platform uses internally JSON and device description following FIWARE Device Model. Note that INTER-IoT internally uses RDF in JSON-LD syntax. To be able to publish messages to INTER-IoT each interconnected platform data format needs to be converted to RDF. Specifically, platform data model should be represented in RDF. If platform does not support semantics natively, such RDF should be designed during the integration process. This recipe presents how JSON data can be translated to RDF data preserving the same information content. Note that RDF structure can be designed from scratch, or any existing representation can be used. You can also reference existing ontologies e.g. SAREF, SSN/SOSA, Time Ontology.

Recipe ingredients

Prerequisites

(How to Do it)

Different approaches can be used here, one of the simpliest is to identify entities and relations between them, as well as their properties and values they can take. If we have the following structure in JSON:

{
    "id": "myDevice-wastecontainer-sensor-345",
    "type": "DeviceModel",
    "category": {
        "value": ["sensor"]
    },
    "function": {
        "value": ["sensing"]
    },
    "modelName": {
        "value": "S4Container 345"
    },
    "name": {
        "value": "myDevice Sensor for Containers 345"
    },
    "brandName": {
        "value": "myDevice"
    },
    "manufacturerName": {
        "value": "myDevice Inc."
    },
    "controlledProperty": {
        "value": ["fillingLevel", "temperature"]
    }
}

It can be represented on the graph structure as follows:

Device description

RDF triples are represented with node pair and adjacent edge e.g. myDevice-wastecontainer-sensor-345 (subject) function (predicate) is sensing (object).

Now, simple RDF to represent this data can be designed (example is in N3 notation):

[ a <http://inter-iot.eu/syntax/FIWAREv2#Entity> ;
<http://inter-iot.eu/syntax/FIWAREv2#hasAttribute>
    [ a     <http://inter-iot.eu/syntax/FIWAREv2#Attribute> ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasName> "name" ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasValue>
        [    <http://inter-iot.eu/syntax/FIWAREv2#hasAttrValue>"myDevice Sensor for Containers 345"^^<http://www.w3.org/2001/XMLSchema#string>
        ]
    ],
    [ a     <http://inter-iot.eu/syntax/FIWAREv2#Attribute> ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasName> "modelName" ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasValue>
        [    <http://inter-iot.eu/syntax/FIWAREv2#hasAttrValue>"S4Container 345"^^<http://www.w3.org/2001/XMLSchema#string>
        ]
    ],
    [ a     <http://inter-iot.eu/syntax/FIWAREv2#Attribute> ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasName> "brandName" ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasValue>
        [    <http://inter-iot.eu/syntax/FIWAREv2#hasAttrValue>"myDevice"^^<http://www.w3.org/2001/XMLSchema#string>
        ]
    ],
    [ a     <http://inter-iot.eu/syntax/FIWAREv2#Attribute> ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasName> "manufacturerName" ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasValue>
        [    <http://inter-iot.eu/syntax/FIWAREv2#hasAttrValue>"myDevice Inc."^^<http://www.w3.org/2001/XMLSchema#string>
        ]
    ],
    [ a     <http://inter-iot.eu/syntax/FIWAREv2#Attribute> ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasName> "category" ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasValue>
        [ a <http://inter-iot.eu/syntax/FIWAREv2#Array> ;
            <http://inter-iot.eu/syntax/FIWAREv2#hasElement>
            [ a <http://inter-iot.eu/syntax/FIWAREv2#ArrayElement> ;
                <http://inter-iot.eu/syntax/FIWAREv2#hasNumber> "1"^^
                <http://www.w3.org/2001/XMLSchema#int> ;
                <http://inter-iot.eu/syntax/FIWAREv2#hasValue> "sensor"^^
                <http://www.w3.org/2001/XMLSchema#string>
            ]
        ]
    ],
    [ a     <http://inter-iot.eu/syntax/FIWAREv2#Attribute> ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasName> "function" ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasValue>
        [ a <http://inter-iot.eu/syntax/FIWAREv2#Array> ;
            <http://inter-iot.eu/syntax/FIWAREv2#hasElement>
            [ a <http://inter-iot.eu/syntax/FIWAREv2#ArrayElement> ;
                <http://inter-iot.eu/syntax/FIWAREv2#hasNumber> "1"^^
                <http://www.w3.org/2001/XMLSchema#int> ;
                <http://inter-iot.eu/syntax/FIWAREv2#hasValue> "sensing"^^
                <http://www.w3.org/2001/XMLSchema#string>
            ]
        ]
    ],
    [ a     <http://inter-iot.eu/syntax/FIWAREv2#Attribute> ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasName> "controlledProperty" ;
        <http://inter-iot.eu/syntax/FIWAREv2#hasValue>
        [ a <http://inter-iot.eu/syntax/FIWAREv2#Array> ;
            <http://inter-iot.eu/syntax/FIWAREv2#hasElement>
            [ a <http://inter-iot.eu/syntax/FIWAREv2#ArrayElement> ;
                <http://inter-iot.eu/syntax/FIWAREv2#hasNumber> "1"^^
                <http://www.w3.org/2001/XMLSchema#int> ;
                <http://inter-iot.eu/syntax/FIWAREv2#hasValue> "fillingLevel"^^
                <http://www.w3.org/2001/XMLSchema#string>
            ],
            [ a <http://inter-iot.eu/syntax/FIWAREv2#ArrayElement> ;
                <http://inter-iot.eu/syntax/FIWAREv2#hasNumber> "2"^^
                <http://www.w3.org/2001/XMLSchema#int> ;
                <http://inter-iot.eu/syntax/FIWAREv2#hasValue> "temperature"^^
                <http://www.w3.org/2001/XMLSchema#string>
            ]
        ]
    ]
] ;
<http://inter-iot.eu/syntax/FIWAREv2#hasId> "myDevice-wastecontainer-sensor-345" ;
<http://inter-iot.eu/syntax/FIWAREv2#hasName> "myDevice Sensor for Containers 345" ;
<http://inter-iot.eu/syntax/FIWAREv2#hasType> "DeviceModel"
]

Proposed RDF uses namespace http://inter-iot.eu/syntax/FIWAREv2 that is discussed in Recipe 8 - Syntactic translation. It provides a common scheme to transform JSON data into RDF. Note, that RDF can be of your arbitrary choice. The crucial point is to have a mechanism for internal IoT artifacts' data models conversion into RDF.

Presented RDF snipped is quite long but the structure is schematic. It can be converted to other RDF syntaxes using RDF Converter and visualized with JSON-LD Playground.

Note that when we have JSON schema or XSD available, we may use conceptual terms to prepare data model in a graph form. Otherwise, we should extract the model from available instances.

Wrapping things up

After IoT artifact data is translated to RDF it can be persisted as JSON-LD (following INTER-IoT message format).