SlideShare a Scribd company logo
Data Modelling with NGSI
José Manuel Cantera Fonseca – FIWARE Foundation
May 2019 (Aligned with ETSI ISG CIM)
Information Model
1
2
Information Model
Attributes
• Name
• Type
• Value
Entity
• EntityId
• EntityType
1 n
“has”
Metadata
• Name
• Type
• Value1 n
“has”
2
3
Information Model (as UML) – NGSI-LD
4
Information Model - Highlights
 NGSI Entity  Physical or virtual object.
 It has (one) Entity Type.
 Uniquely identified by an Entity Id (URI, mandatory in NGSI-LD)
 Entity has zero or more attributes identified by a name
 Property --> Static or dynamic intrinsic characteristic of an Entity
 GeoProperty (geospatial context)
 Relationship  Association with a Linked entity (unidirectional)
 Properties have a value. An NGSI value can be
 single value (Number, String, boolean, DateTime).
 null is not allowed in NGSI-LD and not recommended.
 complex (Array, Structured Value)
 Relationships have an object
 A URI which points to another entity (target of the relationship). Target can be a collection.
5
Information Model – Highlights (II)
 Cross-Domain, core properties for giving context to your information are
defined in a mandatory way, to be used by API operations (e.g. geo queries)
 location  Geospatial location, encoded as GeoJSON.
 observedAt  Observation timestamp, encoded as ISO8601. (timestamp in NGSIv2)
 createdAt  Creation timestamp (of entity, attribute). dateCreated in NGSIv2
 modifiedAt  Update timestamp (of entity, attribute). dateModified in NGSIv2
 unitCode  Units of measurement, encoded as mandated by UN/CEFACT.
 Recommended practice
 Use URIs to identify your entities. (Mandatory in NGSI-LD).
 A URN schema is provided off-the-shelf. It enables to know in advance what Entity Type
an Entity id refers to
 urn:ngsi-ld:<Entity_Type_Name>:<Entity_Identification_String>
Case of Study 1
Smart City
6
7
Smart City Data Model
Source: ETSI
Specification
8
Classical JSON Representation (a.k.a. NGSIv2)
{
"id": "urn:ngsi-ld:Vehicle:A4567",
"type": "Vehicle",
"brandName": {
"type": "Property",
"value": "Mercedes"
},
"isParked": {
"type": "Relationship",
"value": "urn:ngsi-ld:OffStreetParking:Downtown1",
"metadata": {
”timestamp": {
"value" : "2017-07-29T12:00:04Z",
"type" : "DateTime"
},
"providedBy": {
"type" : "Relationship",
"value" : "urn:ngsi-ld:Person:Bob"
}
}
}
}
{
"id": "urn:ngsi-ld:OffStreetParking:Downtown1",
"type": "OffStreetParking",
"availableSpotNumber": {
"type": "Property",
"value": 121,
"metadata" : {
”timestamp": {
"value" : "2017-07-29T12:00:04Z",
"type" : "DateTime"
},
"reliability": {
"type" : "Property",
"value" : 0.7
},
"providedBy": {
"type" : "Relationship",
"value" : "urn:ngsi-ld:Camera:C1"
}
}
},
"location": {
"type": "geo:json",
"value": {
"type": "Point",
"coordinates": [-8.5, 41.2]
}
}
}
9
JSON-LD (RDF friendly) representation (a.k.a. NGSI-LD)
{
"id": "urn:ngsi-ld:Vehicle:A4567",
"type": "Vehicle",
"brandName": {
"type": "Property",
"value": "Mercedes"
},
"isParked": {
"type": "Relationship",
"object": "urn:ngsi-ld:OffStreetParking:Downtown1",
"observedAt": "2017-07-29T12:00:04Z",
"providedBy": {
"type": "Relationship",
"object": "urn:ngsi-ld:Person:Bob"
}
},
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/",
"https://schema.lab.fiware.org/ld/context/"
]
}
{
"id": "urn:ngsi-ld:OffStreetParking:Downtown1",
"type": "OffStreetParking",
"availableSpotNumber": {
"type": "Property",
"value": 121,
"observedAt": "2017-07-29T12:05:02Z",
"reliability": {
"type": "Property",
"value": 0.7
},
"providedBy": {
"type": "Relationship",
"object": "urn:ngsi-ld:Camera:C1"
}
},
"location": {
"type": "GeoProperty",
"value": {
"type": "Point",
"coordinates": [-8.5, 41.2]
}
},
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/",
"https://schema.lab.fiware.org/ld/context/"
]
}
10
Simplified representation (keyValues)
{
"id": "urn:ngsi-ld:OffStreetParking:Downtown1",
"type": "OffStreetParking",
"name": "Downtown One",
"availableSpotNumber": 121,
"totalSpotNumber": 200,
"location": {
"type": "Point",
"coordinates": [-8.5, 41.2]
},
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/",
"https://schema.lab.fiware.org/ld/context/"
]
}
Equivalent in NGSI-LD and NGSIv2
Case of Study 2
Smart Agrifood
11
1
2
Data Model: Smart Agrifood
13
Classical JSON Representation (a.k.a. NGSIv2)
{
"id": "urn:ngsi-ld:Tractor:A4567",
"type": ”Tractor",
"brandName": {
"type": "Property",
"value": ”John Deere"
},
"speed": {
type": "Property"
"value": 12,
"metadata": {
”timestamp": {
"value" : "2017-07-29T12:00:04Z",
"type" : "DateTime"
}
}
},
"isLabouring": {
"type": "Relationship",
"value": "urn:ngsi-ld:AgriParcel:A456",
"metadata": {
"startedAt": {
"value" : "2017-07-29T12:00:04Z",
"type" : "DateTime"
}
}
}
}
{
"id": "urn:ngsi-ld:AgriParcel:A456",
"type": ”AgriParcel",
"location": {
"type" : "geo:json" {
"value" : {
"type": "Polygon",
"coordinates": [
[
100,
0
],
[
101,
0
],
[
101,
1
],
[
100,
1
],
[
100,
0
]
] }
}
}
14
JSON-LD (RDF friendly) representation (a.k.a. NGSI-LD)
{
"id": "urn:ngsi-ld:Tractor:A4567",
"type": ”Tractor",
"brandName": {
"type": "Property",
"value": "Mercedes"
},
"speed" : {
"type": "Property",
"value": 12,
"observedAt": "2017-07-29T12:01:32Z"
},
"isLabouring": {
"type": "Relationship",
"object": "urn:ngsi-ld:AgriParcel:A456",
”startedAt": {
"type": "Property",
"value": "2017-07-29T12:00:04Z"
}
},
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/",
"https://schema.lab.fiware.org/ld/context/"
]
}
{
"id": "urn:ngsi-ld:AgriParcel:A456",
"type": "AgriParcel",
"location": {
"type" : "GeoProperty" {
"value" : {
"type": "Polygon",
"coordinates": [
[
100,
0
],
[
101,
0
],
[
101,
1
],
[
100,
1
],
[
100,
0
]
] }
},
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/",
"https://schema.lab.fiware.org/ld/context/"
]
}
15
Simplified representation (keyValues)
{
"id": "urn:ngsi-ld:Tractor:A4567",
"type": ”Tractor",
”brandName": ”John Deere",
”speed": 12,
”isLabouring": ”urn:ngsi-ld:AgriParcel:A456",
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/",
"https://schema.lab.fiware.org/ld/context/"
]
}
Equivalent in NGSI-LD and NGSIv2
FIWARE Data Models
1
6
17
FIWARE Data Models
 Landing page: https://schema.fiware.org
 Open source project that has developed multiple data models
 https://github.com/FIWARE/dataModels
 Mainly for the Smart City domain but also some for the Smart Agrifood domain
 Specifications are crafted using markdown + JSON Schema
 Example Weather observed data model
 https://github.com/Fiware/dataModels/blob/master/specs/Weather/WeatherObserved/doc/spec.md
 https://fiware.github.io/dataModels/specs/Weather/WeatherObserved/schema.json
 Data Models Guidelines (how to develop new Data Models)
 https://github.com/Fiware/dataModels/blob/master/specs/guidelines.md
 Pull Request – Review Lifecycle.
See also
1
8
19
References
 NGSI-LD FAQ
 https://github.com/FIWARE/dataModels/blob/master/specs/ngsi-ld_faq.md
 NGSI-LD HowTo
 https://github.com/FIWARE/dataModels/blob/master/specs/ngsi-ld_howto.md
 ETSI NGSI-LD Specification (January 2019)
 https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.01.01_60/gs_CIM009v010101p.pdf
 https://docbox.etsi.org/isg/cim/open/Presentation_for_WoT_Plenary_Meeting_Lyon__TPAC_.pdf
 FIWARE NGSIv2 Specification
 http://fiware.github.io/specifications/ngsiv2/stable/
Thank you!
http://fiware.org
Follow @FIWARE on Twitter
José Manuel Cantera Fonseca
FIWARE Foundation
Josemanuel.cantera@fiware.org

More Related Content

FIWARE Wednesday Webinars - How to Design DataModels

  • 1. Data Modelling with NGSI José Manuel Cantera Fonseca – FIWARE Foundation May 2019 (Aligned with ETSI ISG CIM)
  • 3. 2 Information Model Attributes • Name • Type • Value Entity • EntityId • EntityType 1 n “has” Metadata • Name • Type • Value1 n “has” 2
  • 4. 3 Information Model (as UML) – NGSI-LD
  • 5. 4 Information Model - Highlights  NGSI Entity  Physical or virtual object.  It has (one) Entity Type.  Uniquely identified by an Entity Id (URI, mandatory in NGSI-LD)  Entity has zero or more attributes identified by a name  Property --> Static or dynamic intrinsic characteristic of an Entity  GeoProperty (geospatial context)  Relationship  Association with a Linked entity (unidirectional)  Properties have a value. An NGSI value can be  single value (Number, String, boolean, DateTime).  null is not allowed in NGSI-LD and not recommended.  complex (Array, Structured Value)  Relationships have an object  A URI which points to another entity (target of the relationship). Target can be a collection.
  • 6. 5 Information Model – Highlights (II)  Cross-Domain, core properties for giving context to your information are defined in a mandatory way, to be used by API operations (e.g. geo queries)  location  Geospatial location, encoded as GeoJSON.  observedAt  Observation timestamp, encoded as ISO8601. (timestamp in NGSIv2)  createdAt  Creation timestamp (of entity, attribute). dateCreated in NGSIv2  modifiedAt  Update timestamp (of entity, attribute). dateModified in NGSIv2  unitCode  Units of measurement, encoded as mandated by UN/CEFACT.  Recommended practice  Use URIs to identify your entities. (Mandatory in NGSI-LD).  A URN schema is provided off-the-shelf. It enables to know in advance what Entity Type an Entity id refers to  urn:ngsi-ld:<Entity_Type_Name>:<Entity_Identification_String>
  • 7. Case of Study 1 Smart City 6
  • 8. 7 Smart City Data Model Source: ETSI Specification
  • 9. 8 Classical JSON Representation (a.k.a. NGSIv2) { "id": "urn:ngsi-ld:Vehicle:A4567", "type": "Vehicle", "brandName": { "type": "Property", "value": "Mercedes" }, "isParked": { "type": "Relationship", "value": "urn:ngsi-ld:OffStreetParking:Downtown1", "metadata": { ”timestamp": { "value" : "2017-07-29T12:00:04Z", "type" : "DateTime" }, "providedBy": { "type" : "Relationship", "value" : "urn:ngsi-ld:Person:Bob" } } } } { "id": "urn:ngsi-ld:OffStreetParking:Downtown1", "type": "OffStreetParking", "availableSpotNumber": { "type": "Property", "value": 121, "metadata" : { ”timestamp": { "value" : "2017-07-29T12:00:04Z", "type" : "DateTime" }, "reliability": { "type" : "Property", "value" : 0.7 }, "providedBy": { "type" : "Relationship", "value" : "urn:ngsi-ld:Camera:C1" } } }, "location": { "type": "geo:json", "value": { "type": "Point", "coordinates": [-8.5, 41.2] } } }
  • 10. 9 JSON-LD (RDF friendly) representation (a.k.a. NGSI-LD) { "id": "urn:ngsi-ld:Vehicle:A4567", "type": "Vehicle", "brandName": { "type": "Property", "value": "Mercedes" }, "isParked": { "type": "Relationship", "object": "urn:ngsi-ld:OffStreetParking:Downtown1", "observedAt": "2017-07-29T12:00:04Z", "providedBy": { "type": "Relationship", "object": "urn:ngsi-ld:Person:Bob" } }, "@context": [ "https://uri.etsi.org/ngsi-ld/v1/", "https://schema.lab.fiware.org/ld/context/" ] } { "id": "urn:ngsi-ld:OffStreetParking:Downtown1", "type": "OffStreetParking", "availableSpotNumber": { "type": "Property", "value": 121, "observedAt": "2017-07-29T12:05:02Z", "reliability": { "type": "Property", "value": 0.7 }, "providedBy": { "type": "Relationship", "object": "urn:ngsi-ld:Camera:C1" } }, "location": { "type": "GeoProperty", "value": { "type": "Point", "coordinates": [-8.5, 41.2] } }, "@context": [ "https://uri.etsi.org/ngsi-ld/v1/", "https://schema.lab.fiware.org/ld/context/" ] }
  • 11. 10 Simplified representation (keyValues) { "id": "urn:ngsi-ld:OffStreetParking:Downtown1", "type": "OffStreetParking", "name": "Downtown One", "availableSpotNumber": 121, "totalSpotNumber": 200, "location": { "type": "Point", "coordinates": [-8.5, 41.2] }, "@context": [ "https://uri.etsi.org/ngsi-ld/v1/", "https://schema.lab.fiware.org/ld/context/" ] } Equivalent in NGSI-LD and NGSIv2
  • 12. Case of Study 2 Smart Agrifood 11
  • 14. 13 Classical JSON Representation (a.k.a. NGSIv2) { "id": "urn:ngsi-ld:Tractor:A4567", "type": ”Tractor", "brandName": { "type": "Property", "value": ”John Deere" }, "speed": { type": "Property" "value": 12, "metadata": { ”timestamp": { "value" : "2017-07-29T12:00:04Z", "type" : "DateTime" } } }, "isLabouring": { "type": "Relationship", "value": "urn:ngsi-ld:AgriParcel:A456", "metadata": { "startedAt": { "value" : "2017-07-29T12:00:04Z", "type" : "DateTime" } } } } { "id": "urn:ngsi-ld:AgriParcel:A456", "type": ”AgriParcel", "location": { "type" : "geo:json" { "value" : { "type": "Polygon", "coordinates": [ [ 100, 0 ], [ 101, 0 ], [ 101, 1 ], [ 100, 1 ], [ 100, 0 ] ] } } }
  • 15. 14 JSON-LD (RDF friendly) representation (a.k.a. NGSI-LD) { "id": "urn:ngsi-ld:Tractor:A4567", "type": ”Tractor", "brandName": { "type": "Property", "value": "Mercedes" }, "speed" : { "type": "Property", "value": 12, "observedAt": "2017-07-29T12:01:32Z" }, "isLabouring": { "type": "Relationship", "object": "urn:ngsi-ld:AgriParcel:A456", ”startedAt": { "type": "Property", "value": "2017-07-29T12:00:04Z" } }, "@context": [ "https://uri.etsi.org/ngsi-ld/v1/", "https://schema.lab.fiware.org/ld/context/" ] } { "id": "urn:ngsi-ld:AgriParcel:A456", "type": "AgriParcel", "location": { "type" : "GeoProperty" { "value" : { "type": "Polygon", "coordinates": [ [ 100, 0 ], [ 101, 0 ], [ 101, 1 ], [ 100, 1 ], [ 100, 0 ] ] } }, "@context": [ "https://uri.etsi.org/ngsi-ld/v1/", "https://schema.lab.fiware.org/ld/context/" ] }
  • 16. 15 Simplified representation (keyValues) { "id": "urn:ngsi-ld:Tractor:A4567", "type": ”Tractor", ”brandName": ”John Deere", ”speed": 12, ”isLabouring": ”urn:ngsi-ld:AgriParcel:A456", "@context": [ "https://uri.etsi.org/ngsi-ld/v1/", "https://schema.lab.fiware.org/ld/context/" ] } Equivalent in NGSI-LD and NGSIv2
  • 18. 17 FIWARE Data Models  Landing page: https://schema.fiware.org  Open source project that has developed multiple data models  https://github.com/FIWARE/dataModels  Mainly for the Smart City domain but also some for the Smart Agrifood domain  Specifications are crafted using markdown + JSON Schema  Example Weather observed data model  https://github.com/Fiware/dataModels/blob/master/specs/Weather/WeatherObserved/doc/spec.md  https://fiware.github.io/dataModels/specs/Weather/WeatherObserved/schema.json  Data Models Guidelines (how to develop new Data Models)  https://github.com/Fiware/dataModels/blob/master/specs/guidelines.md  Pull Request – Review Lifecycle.
  • 20. 19 References  NGSI-LD FAQ  https://github.com/FIWARE/dataModels/blob/master/specs/ngsi-ld_faq.md  NGSI-LD HowTo  https://github.com/FIWARE/dataModels/blob/master/specs/ngsi-ld_howto.md  ETSI NGSI-LD Specification (January 2019)  https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.01.01_60/gs_CIM009v010101p.pdf  https://docbox.etsi.org/isg/cim/open/Presentation_for_WoT_Plenary_Meeting_Lyon__TPAC_.pdf  FIWARE NGSIv2 Specification  http://fiware.github.io/specifications/ngsiv2/stable/
  • 21. Thank you! http://fiware.org Follow @FIWARE on Twitter José Manuel Cantera Fonseca FIWARE Foundation Josemanuel.cantera@fiware.org