NGSI-LD provides a more complex data model than NGSIv2 by introducing properties, relationships, and additional metadata. It evolves NGSIv2 to support linked data by making payloads valid JSON-LD. This allows for a navigable knowledge graph compared to the simpler NGSIv2 model. The document discusses the differences between the two models and provides examples of creating and reading entity data in each.
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
Â
Data Modeling with NGSI, NGSI-LD
1. Session 11 - Data modeling with NGSI, NGSI-LD
Fernando LĂłpez, Cloud & Platform Senior Expert
fernando.lopez@fiware.org
@flopezaguilar
FIWARE Foundation, e.V.
2. Learning Goals
1
â What is a Information Model?
â Which types of representation of Information Model are used in FIWARE?
â What are the differents between NGSIv2 and NGSI-LD?
â Where can I get details about Data Models in use?
3. Information Model -
2
Attributes
âą Name
âą Type
âą Value
Entity
âą EntityId
âą EntityType
1 n
âhasâ
Metadata
âą Name
âą Type
âą Value1 n
âhasâ
OMA NGSI Information Model
5. Linked Data: JSON to JSON-LD
From: https://json-ld.org/
âȘ JSON-LD is a lightweight Linked Data format. It is easy for humans to read and write. It is
based on the already successful JSON format and provides a way to help JSON data
interoperate at Web-scale.
âȘ 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. It allows an
application to start at one piece of Linked Data and follow embedded links to other pieces of
Linked Data that are hosted on different sites across the Web.
4
{
"@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"
}
6. Linked Data: NGSIv2 to NGSI-LD
From: https://fiware-datamodels.readthedocs.io/en/latest/ngsi-ld_faq/index.html
âȘ NGSI-LD is an evolution of the FIWARE NGSIv2 information model and has been updated/improved to
support linked data (entity relationships), property graphs and semantics (exploiting the capabilities
offered by JSON-LD). This work has been conducted under the ETSI ISG Context Information
Management initiative.
âȘ Creating proper machine-readable Linked Data is fundamental to NGSI-LD.
âȘ NGSI-LD Payloads are valid JSON-LD
5
{
"@context": [
"https://fiware.github.io/data-models/context.jsonld",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
],
"id": "http://dbpedia.org/resource/John_Lennon",
"type": "Person",
"name": {"type": "Property", "value": "John Lennon"},
"born": {"type": "Property", "value": "1940-10-09"},
"spouse": {"type": "Relationship", "object": "http://dbpedia.org/resource/Cynthia_Lennon" }
}
10. NGSI-LD: Evolution not Revolution
NGSI v2
âȘ Well defined REST API for context data
using JSON payloads.
GET, POST and other HTTP verbs do
the things you expect
âȘ CRUD operations -
/v2/entities endpoint
âȘ Augment your context data -
/v2/registrations endpoint
âȘ Push context data to other services -
/v2/subscriptions endpoint
9
NGSI-LD
âȘ Well defined REST API for context data
using JSON and JSON-LD payloads.
GET, POST and other HTTP verbs do the
things you expect
âȘ CRUD operations - /ngsi-
ld/v1/entities endpoint
âȘ Augment your context data - /ngsi-
ld/v1/registrations endpoint
âȘ Push context data to other services - /ngsi-
ld/v1/subscriptions endpoint
13. NGSI-LD Properties: Data Model
NGSI v2
âȘ Entities
âȘ Attributes
âȘ MetaData
12
NGSI-LD
âȘ Entities
âȘ Properties
âȘ Relationships
âȘ Values
plus âŠ
plus âŠ
etc...
The NGSI LD data model is more
complex; the definitions of use are
more rigid which lead to a
navigable knowledge graph.
âȘ Properties of Properties
âȘ Properties of Relationships
âȘ Relationships of Properties
âȘ Relationships of Relationships
âȘ Properties of Properties of Properties
âȘ Relationships of Properties of Properties
âȘ Properties of Properties of Relationships
âȘ Relationships of Properties of Relationships
âȘ Properties of Relationships of Properties
âȘ Relationships of Relationships of Properties
âȘ Properties of Relationships of Relationships
âȘ Relationships of Relationships of Relationships
14. NGSI-LD Properties: Data Model - I
13
The Entity Example Notes
Has an id urn:ngsi-ld:Building:store001 URI/URN. id must be unique.
Has a type. https://uri.fiware.org/ns/
data-models#Building
â Fully qualified URI of a well-defined data model
â Short-hand strings for types, mapped to fully qualified URIs through the JSON-LD
@context.
Has a series of properties name, address, category etc. This can be expanded into http://schema.org/address, which is
known as a fully qualified name (FQN).
Has a series of
properties-of-properties
a verified field for the address This is the equivalent of NGSI v2 metadata
Has a series of relationships managedBy The object corresponds to the URI/URN of another data entity.
Equivalent of NGSI v2 refXXX
Has a series of
properties-of-relationships
managedBy.since Holds additional information about a relationship.
This is the equivalent of metadata about a refXXX property
Has a series of
relationships-of-relationships
managedBy.subordinateTo holds the URI/URN of another relationship.
15. NGSI-LD Properties: Data Model - II
14
The Properties Example Notes
Have a value "BösebrĂŒcke Einkaufâ
[13.3986, 52.5547]
12
"2017-07-29T12:01:32Z"
An NGSI value could be:
â Single value (Number, String, boolean, DateTime).
â Null is not allowed in NGSI-LD and not recommended.
â Complex (Array, Structured Value)
16. NGSI-LD Properties: Data Model â III
15
Cross-domain Example Notes
Might has a location "location": {"type": "geo:json",
"value": {"type": "Point", "coordinates": [13.3986, 52.5547]}
},
Geospatial location, encoded as GeoJSON.
Might has an observedAt "observedAt": "2017-07-29T12:05:02Z" Observation timestamp, encoded as ISO8601,
timestamp in NGSIv2 (Optional).
Might has a createdAt âcreatedAt": "2017-07-29T12:05:02Z", Creation timestamp (of entity, attribute), dateCreated in
NGSIv2 (System generated).
Might has a modifiedAt âmodifiedAt": "2017-07-29T12:05:02Z", Update timestamp (of entity, attribute), dateModified in
NGSIv2 (System generated).
Might has a unitCode A94 (g/mol)
E01 (N/cmÂČ)
MBR (mbar)
Units of measurement, encoded as mandated by
UN/CEFACT.
Note: The UN/CEFACT Common Code C62 stands for
"no unit".
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.
16
18. NGSI-LD Properties: Reading Entity Data
NGSI-LD
âȘ Response is just a JSON payload plus an @context
âȘ @context can be passed either in the Link header
or the payload body:
âȘ Accept: application/ld+json to include
the @context as a JSON attribute
âȘ Accept: application/json returns plain old
JSON objects - @context is passed as a Link header
âȘ Just a minute what has happened to category?
17
curl -G -X GET
'http://localhost:1026/ngsi-ld/v1/entities'
-H 'Link: <https://fiware.github.io/data-models/context.jsonld>;
rel="http://www.w3.org/ns/json-ld#context";
type="application/ld+json"'
-H 'Accept: application/ld+json'
-d 'type=Building'
-d 'options=keyValues'
[
{
"@context": "https://fiware.github.io/data-models/context.jsonld",
"id": "urn:ngsi-ld:Building:store001", "type": "Building",
"address": {
"streetAddress": "Bornholmer StraĂe 65",
"addressRegion": "Berlin",
"addressLocality": "Prenzlauer Berg",
"postalCode": "10439"
},
"name": "BösebrĂŒcke Einkauf",
"category": [
"https://uri.fiware.org/ns/data-models#commercial"
],
"location": {
"type": "Point", "coordinates": [13.3986, 52.5547]
}
}
]
19. NGSI-LD Properties: What to call a location?
âȘ location
âȘ locatedAt
âȘ geocoordinate
âȘ geocoordinates
âȘ place
âȘ ubicaciĂłn
âȘ standort
âȘ çœźăć Žæ
18
With NGSI-LD core @context a location is always
https://uri.etsi.org/ngsi-ld/location
NGSI-LD core @context
"@context": {
"ngsi-ld": "https://uri.etsi.org/ngsi-ld/",
"id": "@id",
"type": "@type",
"value": "https://uri.etsi.org/ngsi-ld/hasValue",
"object": {
"@id": "https://uri.etsi.org/ngsi-ld/hasObject",
"@type": "@id"
},
"Property": "https://uri.etsi.org/ngsi-ld/Property"
"Relationship": "https://uri.etsi.org/ngsi-ld/Relationship",
... etc.
"unitCode": "https://uri.etsi.org/ngsi-ld/unitCode",
"location": "https://uri.etsi.org/ngsi-ld/location",
... etc.
}
20. NGSI-LD Properties: @vocab and Enumerated Values
âȘ An âaddressâ is:
https://schema.org/address
âȘ A âcategoryâ is:
https://uri.fiware.org/ns/data-models#category
âȘ A category is an enum which takes a
set of values such as:
https://uri.fiware.org/ns/data-models#commercial
https://uri.fiware.org/ns/data-models#office
https://uri.fiware.org/ns/data-models#retail
https://uri.fiware.org/ns/data-models#residential
19
FIWARE Data Models @context
"@context": {
"type": "@type",
"id": "@id",
"schema": "https://schema.org/",
"fiware": "https://uri.fiware.org/ns/data-models#",
... etc.
"address": "schema:address",
"category": {
"@id" :"fiware:category",
"@type": "@vocab"
},
"commercial": "fiware:commercial",
"office": "fiware:office",
"retail": "fiware:retail",
"residential": "fiware:residential",
... etc.
}
With NGSI-LD Data Models, attributes and enums are well-defined in a computer-readable fashion
21. NGSI-LD Relationships: Traversing Edge Nodes
From: https://www.w3.org/TR/json-ld/#dfn-graph
A JSON-LD document serializes a dataset which is a collection of graphs
A graph is a labeled directed graph, i.e., a set of nodes connected by edges.
In NGSI-LD:
âȘ Node = NGSI Entity
âȘ Edge = A relationship attribute linking two NGSI Entities
Therefore NGSI Linked Data relies on three separate definitions:
1. A definition that a particular attribute within an NGSI entity really represents a link
2. A machine readable definition of that link in the Data Model (i.e. the @context)
3. A machine readable definition of the set of all types of links available (the @graph)
20
Creating proper machine-readable Linked Data is fundamental to NGSI-LD.
22. NGSI-LD Relationships: 1. Creating Entities
Relationship Links within an NGSI Entity are formally defined using:
"type": "Relationship" OR "@type": "https://uri.etsi.org/ngsi-ld/Relationship"
The attribute of the linked entity is an object rather than a value
21
curl -X POST
http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Shelf:unit001/attrs
-H 'Content-Type: application/ld+json'
-H 'fiware-servicepath: /'
-d '{
"stocks": { "type": "Relationship","object": "urn:ngsi-ld:Product:001"},
"numberOfItems": {"type": "Property","value": 50},
"locatedIn" : {
"type": "Relationship", "object": "urn:ngsi-ld:Building:store001",
"requestedBy": {"type": "Relationship","object": "urn:ngsi-ld:Person:bob-the-manager"},
"installedBy": {"type": "Relationship","object": "urn:ngsi-ld:Person:employee001"},
"statusOfWork": {"type": "Property","value": "completed"}
},
"@context": "https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld"
}'
23. NGSI-LD Relationships: 2. Machine Readable Data Models
Relationship links within the @context are formally defined using: "@type": "@id"
22
FIWARE Data Models @context
"@context": {
"tutorial": "https://fiware.github.io/tutorials.Step-by-Step/schema/",
"Product": "tutorial:Product",
"Shelf": "tutorial:Shelf",
...etc
"installedBy": {
"@id": "tutorial:installedBy",
"@type": "@id"
},
"requestedBy": {
"@id": "tutorial:requestedBy",
"@type": "@id"
},
...etc
25. Context Data as Linked Data - How does it help?
Linking Disparate Data
Sources
âȘ Which crimes in which area are
not related to Jack?
âȘ Does Jack only deal in
Cannabis?
âȘ How is Jack related to
Raymond?
âȘ Which other police officers
should Inspector Devy contact?
24
26. Context Data as Linked Data - How does it help?
25
Rich Text Snippets
Standard schema.org/Product data model
marked up as JSON-LD on the web. Interpreted by
third parties. Search Engine can display product rating
on screen. System âknowsâ if a product is out of stock.
NGSI-LD Supermarket Tutorial
Third party ARV could âknowâ when a shelf needs filling and
retrieve goods from the warehouse.
No need to reprogram for new customers if data follows the
fiware.org/ns/data-models, or the JSON-LD can be
converted to do so.
27. Summary: Terms
26
â JSON, JavaScript Object Notation is an open-standard file format that uses human-readable text to
transmit data objects consisting of attributeâvalue pairs and array data types.
â JSON-LD, JSON-LD, is a method of encoding Linked Data using JSON.
â NGSIv2, version 2 of the Open Mobile Alliance (OMA) Next Generation Service Interfaces (NGSI).
â NGSI-LD, the ETSI definition of a standard API for Context Information Management based in Linked
Data.
â UN/CEFACT is the United Nations Centre for Trade Facilitation and Electronic Business.
28. Summary: Terms
27
â ISO8691, Data elements and interchange formats â Information interchange â Representation of
dates and times is an international standard covering the exchange of date- and time-related data.
â GeoJSON is an open standard format designed for representing simple geographical features, along
with their non-spatial attributes. It is based on the JavaScript Object Notatio
â FQN, a fully qualified name (FQN) is an unambiguous name that specifies which object, function, or
variable a call refers to without regard to the context of the call.
â URI is a string of characters that unambiguously identifies a particular resource.
â URN is a URI that uses the urn scheme.
29. Common UN/CEFACT values
28
UN/CEFACT
Common
Code
Unit of
Measurement
28 kg/mÂČ
2N dB
4H ”m
4K mA
4P N/m
A24 cd/mÂČ
A86 GHz
A94 g/mol
B22 kA
B32 kg âą m2
B43 kJ/(kg.K)
B49 kâŠ
B61 lm/W
BAR bar
C16 mm/s
UN/CEFACT
Common
Code
Unit of
Measurement
C24 mPa.s
C26 ms
C45 nm
C62 1
C65 Pa.s
C91 1/K
C94 min-1
CDL cd
CEL °C
CMQ cmÂł
CMT cm
D33 T
D52 W/K
D74 kg/mol
DAY d
UN/CEFACT
Common
Code
Unit of
Measurement
DD °
E01 N/cmÂČ
E32 l/h
FAR F
GM g/mÂČ
GRM g
HTZ Hz
HUR h
KEL K
KGM kg
KGS kg/s
KHZ kHz
KL kg/m
KMQ kg/mÂł
KVT kV
UN/CEFACT
Common
Code
Unit of
Measurement
KWT kW
L2 l/min
LTR l
LUM lm
LUX lx
MBR mbar
MHZ MHz
MIN min
MMK mmÂČ
MMQ mmÂł
MMT mm
MPA MPa
MQH m3/h
MQS mÂł/s
MTK mÂČ
UN/CEFACT
Common
Code
Unit of
Measurement
MTQ mÂł
MTR m
MTS m/s
NEW N
NU N âą m
NU N.m
OHM âŠ
P1 %
PAL Pa
SEC s
VLT V
WTT W
30. References
29
â FIWARE Catalogue
o https://www.fiware.org/developers/catalogue
â NGSI-LD FAQ
o https://github.com/FIWARE/dataModels/blob/master/specs/ngsi-ld_faq.md
â NGSI-LD HowTo
o https://github.com/FIWARE/dataModels/blob/master/specs/ngsi-ld_howto.md
31. References
30
â ETSI NGSI-LD Specification (October 2019)
o https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.02.01_60/gs_cim009v010201p.pdf
o https://docbox.etsi.org/isg/cim/open/Presentation_for_WoT_Plenary_Meeting_Lyon__TPAC_.pdf
â FIWARE NGSIv2 Specification
o http://fiware.github.io/specifications/ngsiv2/stable/