This section aims to provide few simple guidelines for the adoption of Smart Data Models. Readers interested into modifying or creating new data models should refer to Data models guidelines. This guide is not exhaustive and does not aim to cover the specifics of each model, rather it provides general usage tips valid for most of the existing models and for expected models in the future.
Data Models have been defined in relation to the FIWARE reference data context model (NGSI v2). While this does not imply that they cannot be used outside of the NGSI context model, it does however indicate that some of design principles have been driven by that. This also implicitly means that Data Models will follow the evolution of FIWARE platform, NGSI-LD mappings are being added to all existing Data Models.
The general principle guiding your adoption should be: keep it simple.
Each Data Model is programmatically defined using a JSON Schema, as previously mentioned, the JSON schema covers only the so called key-value representation of NGSI v2 context data. Thus the JSON Schema does not cover the normalised representation of context data.
In the NGSI v2
normalised format each attribute (key
) of the Data Model is represented by a
JSON object with the following syntax:
value
property, whose value may be
any JSON datatype.type
property, whose value is
a string containing the NGSI type.metadata
property. Its value is
another JSON object which contains a property per metadata element defined
(the name of the property is the name
of the metadata element). Each
metadata element, in turn, is represented by a JSON object containing the
following properties:
value
: Its value contains the metadata value, which may correspond to
any JSON datatype.type
: Its value contains a string representation of the metadata NGSI
type.{
"id": "entityId",
"type": "entityType",
"att1": {
"value": "value1",
"type": "Text",
"metadata": {
"metada1": {
"value": "metavalue1"
}
}
}
}
In the case of the key-value format (also known as Simplified Entity Representation in the NGSI v2 specification), values are directly mapped to the keys, and metadata are not covered:
{
"id": "entityId",
"type": "entityType",
"att1": "value1"
}
Of course the normalised format contains richer information, but on the other side it is redundant and less efficient in term of transport.
To clarify the difference among the two representation here is a complete
example from the AirQualityObserved
Data Model:
{
"id": "Madrid-AmbientObserved-28079004-2016-03-15T11:00:00",
"type": "AirQualityObserved",
"dateObserved": {
"value": "2016-03-15T11:00:00/2016-03-15T12:00:00"
},
"airQualityLevel": {
"value": "moderate"
},
"CO": {
"value": 500,
"metadata": {
"unitCode": {
"value": "GP"
}
}
},
"temperature": {
"value": 12.2
},
"NO": {
"value": 45,
"metadata": {
"unitCode": {
"value": "GQ"
}
}
},
"refPointOfInterest": {
"type": "Relationship",
"value": "28079004-Pza.deEspanya"
},
"windDirection": {
"value": 186
},
"source": {
"value": "http://datos.madrid.es"
},
"windSpeed": {
"value": 0.64
},
"SO2": {
"value": 11,
"metadata": {
"unitCode": {
"value": "GQ"
}
}
},
"NOx": {
"value": 139,
"metadata": {
"unitCode": {
"value": "GQ"
}
}
},
"location": {
"type": "geo:json",
"value": {
"type": "Point",
"coordinates": [-3.712247222222222, 40.423852777777775]
}
},
"airQualityIndex": {
"value": 65
},
"address": {
"type": "PostalAddress",
"value": {
"addressCountry": "ES",
"addressLocality": "Madrid",
"streetAddress": "Plaza de Espa\u00f1a"
}
},
"reliability": {
"value": 0.7
},
"relativeHumidity": {
"value": 0.54
},
"precipitation": {
"value": 0
},
"NO2": {
"value": 69,
"metadata": {
"unitCode": {
"value": "GQ"
}
}
},
"CO_Level": {
"value": "moderate"
}
}
{
"id": "Madrid-AmbientObserved-28079004-2016-03-15T11:00:00",
"type": "AirQualityObserved",
"address": {
"addressCountry": "ES",
"addressLocality": "Madrid",
"streetAddress": "Plaza de España"
},
"dateObserved": "2016-03-15T11:00:00/2016-03-15T12:00:00",
"location": {
"type": "Point",
"coordinates": [-3.712247222222222, 40.423852777777775]
},
"source": "http://datos.madrid.es",
"precipitation": 0,
"relativeHumidity": 0.54,
"temperature": 12.2,
"windDirection": 186,
"windSpeed": 0.64,
"airQualityLevel": "moderate",
"reliability": 0.9,
"CO": 500,
"NO": 45,
"NO2": 69,
"NOx": 139,
"SO2": 11,
"CO_Level": "good",
"NO_Level": "moderate",
"refPointOfInterest": "28079004-Pza. de España"
}
For each Data Model we provide a set of examples (in some cases also using the Normalised representation of NGSI v2), such examples have been validated against the respective JSON Schema and against a Orion Context Broker instance (to ensure that also the content encoding is compliant with the reference implementation).
As a consequence of the NGSI v2 specifications, all Data Models must include the following attributes:
id
: a unique identified of the entity modelled.type
: The entity type, i.e. the type of Data Model, e.g. Alert
.dateModified
: Last update timestamp of the entity.dateCreated
: The entity’s creation timestamp.dateCreated
and dateModified
are special entity attributes provided
off-the-shelf by NGSI v2 implementations.
Most of the Smart Data Models adopt the GSMA common definitions, and so also include standard GSMA terminology such as:
owner
: An array of URIs or pointers to NGSI entities representing the
owner(s) of the entity.source
: A pointer (eventually an URI) to the service providing the data.name
: A mnemonic name given to the entity as per
schema.org defined within the core context as
https://uri.etsi.org/ngsi-ld/name
alternateName
: An alternative mnemonic name given to the entity as per
schema.orgdescription
: A textual description of the entity as per
schema.org defined within the core context
as https://uri.etsi.org/ngsi-ld/description
dataProvider
: A name identifying the entity providing the data.See for example the
Building
Data Model.
Similarly most of the Smart Data Models adopt the Location common definitions, and thus include the following attributes:
address
: the civic address of the entity as per
schema.org.location
: the GeoJSON
representation of the entity location.See for example the Building
Data Model.
GeoJSON supports the definition of quite complex geometries (Point
,
LineString
, Polygon
, MultiPoint
, MultiLineString
, and MultiPolygon
)
representing the localisation of entities. Examples of GeoJSON geometries are
available here.
unitCode
metadata annotation in your data (and you will need to adopt the normalised
representation). Code used should be the ones defined by
UN/CEFACT.
E.g.:"length": {
"value": 11,
"metadata": {
"unitCode": {
"value": "FOT"
}
}
}
Often, different attributes of the same entity are updated at different points
in time as the result of data aggregation across measurements from different
sensors. Note that the dateModified
value only reflects only the point in time
the NGSI v2 implementation received an entity update, it does not correspond to
the moment in time at which an attribute changed. In order to be able to define
when a specific attribute changed you should you should use the timestamp
metadata annotation. E.g.:
"speed": {
"value": 11,
"metadata": {
"timestamp": {
"value": "2016-03-15T11:00:00.000"
}
}
}
With the introduction of NGSI-LD, a growing number attributes are being defined which represent relationships between entities.
Previously the Smart data model defined the name of such attributes was normed
to be ref
followed by the name of the Entity Type referenced by the attribute,
for example in the case of Entity Type Device
, the full attribute would be
refDevice
.
With the introduction of NGSI-LD, following the link with practises in the
ontologies, such attributes are defined with the usage of a verb (plus
optionally an object) such as hasStop
, operatedBy
, hasTrip
, etc.
While in the first case, the entity type to be looked for is implicitly defined
by the attribute name, this is no longer the case with NGSI-LD, that’s why it is
important to use NGSI-LD URNs that convey
the type of the target entity, for instance urn:ngsi-ld:gtfs:Stop:S123
.
Currently it is up to the logic of your application to include the logic to navigate entity relationships, as it is not yet defined within implementations of the NGSI v2 or NGSI-LD specification.