Context Modeling using JSON-LD

The PIR motion sensor plugged to a Raspberry Pi, may provide only a value related to the detection of motion or not. While such information is necessary to implement the Smart Mailbox IoT project, additional context-related information is required. For example: What is the IP address of the sensor? Who is the owner? Where is the sensor located? Etc.

During this lab you will use Linked-data modeling techniques to add context information for the Smart Mailbox IoT project.

Linked Data

Linked Data empowers people that publish and use information on the Web. It is a way to create a network of standards-based, machine-readable data across Web sites. All users of the Internet will be familiar with the concept of hypertext links, the way that a link on one web page is able to guide the browser to loading another page from a known location.

Whilst humans are able to understand relationship discoverability and how links work, computers find this much more difficult, and require a well-defined protocol to be able to traverse from one data element to another held in a separate location.

Creating a system of readable links for computers requires the use of a well defined data format (JSON-LD) and assignation of unique IDs (URLs or URNs) for both data entities and the relationships between entities so that semantic meaning can be programmatically retrieved from the data itself.

Properly defined linked data can be used to help answer big data questions, and the data relationships can be traversed to answer questions like  “Which products are currently available on the shelves of Store X and what prices are they sold at?”

Useful Video

JSON-LD

JSON-LD is an extension of JSON , it is a standard way of avoiding ambiguity when expressing linked data in JSON so that the data is structured in a format which is parsable by machines. It is a method of ensuring that all data attributes can be easily compared when coming from a multitude of separate data sources, which could have a different idea as to what each attribute means. For example, when two data entities have a name attribute, how can the computer be certain that this refers to a “Name of a thing” in the same sense (rather than a Username or a Surname or something)? URLs and data models are used to remove ambiguity by allowing attributes to have a both short form (such as name) and a fully specified long form (such http://schema.org/name) which means it is easy to discover which attribute have a common meaning within a data structure.

JSON-LD introduces the concept of the @context element which provides additional information allowing the computer to interpret the rest of the data with more clarity and depth.

Furthermore, the JSON-LD specification enables you to define a unique @type associating a well-defined data model to the data itself.

Design

JSON-LD is designed around the concept of a “context” to provide additional mappings from JSON. The context links object properties in a JSON document to concepts in an ontology. In order to create the JSON-LD syntax, JSON-LD allows values to be coerced to a specified type or to be tagged with a language. A context can be embedded directly in a JSON-LD document or put into a separate file and referenced from different documents (from traditional JSON documents via an HTTP Link header).

Example

{
  "@context": "https://json-ld.org/contexts/person.jsonld",
  "@id": "http://dbpedia.org/resource/John_Lennon",
  "name": "John Lennon",
  "born": "1940-10-09",
  "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}

Useful Video

Context Modeling using JSON-LD

In today’s interconnected world wide web, there are tons of different ways to represent data and a lot of different data models. Data models in general define the standardized representation formats and semantics that applications will use to consume and publish data. One could “reinvent” the wheel and create their own data models, but ontological types are meant to be shared, and defining customized or ad hoc types to be used in one single environment or application normally defeats their purpose.

Smart Data Models is a data model collection available to be used by the FIWARE Foundation. These data models are open-source, allowing for free use, modification, and sharing of modifications, and have been harmonized to enable data portability for a variety of applications, including Smart Cities, Smart Agrifood, Smart Environment,Smart Energy, Smart Water, Smart Destination, Smart Robotics and Smart Manufacturing.

Where can we find them and what examples of their usage are there?

There are 2 different important links for the smart data models project:

We propose using the github repository. Then, to model a sensor, you have to find the data model “Device” in Smart Sensoring.

Motion Sensor modeling

Using the “Device” data model, inlude information for:

  • Device ID
  • Type
  • MAC address of the device (Raspberry Pi)
  • IP address of the device (Raspberry Pi)
  • Category of the sensor
  • Device state
  • Motion detection value
  • Descrpiption of the sensor
  • Owner (groups number)

Smart Mailbox modeling

Smart data models by FIWARE do not provide data models for a mailbox and in general for smart objects. Therefore, you will have to create a data model for our “Smart Mailbox” project.

For this laboratory, you don’t have to create the data model itself, but a JSON-LD object of how the smart mailbox would look.

Please inlude the following information:

  • Device using the JSON-LD reference ID
  • Type
  • Location (building, room) where the mailbox is located
  • ID of the mailbox
  • Smart mailbox status (e.g., new letter)
  • Letter count
  • Add other attributes you find useful

Smart Mailbox testing

Use the smart mailbox JSON objects and the motion sensor to print the mailbox status and motion sensor details. Make sure that values of dynamic attributes are updated (Smart mailbox status, Motion detection).

Previous
Next