Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Data Modeling with NGSI, NGSI-LD

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Cargando en…3
×

Eche un vistazo a continuación

1 de 34 Anuncio
Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

Similares a Data Modeling with NGSI, NGSI-LD (20)

Anuncio

Más de Fernando Lopez Aguilar (20)

Más reciente (20)

Anuncio

Data Modeling with NGSI, NGSI-LD

  1. 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. 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. 3. Information Model - 2 Attributes • Name • Type • Value Entity • EntityId • EntityType 1 n “has” Metadata • Name • Type • Value1 n “has” OMA NGSI Information Model
  4. 4. Information Model (as UML) - 3 Property Graph Information Model
  5. 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. 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" } }
  7. 7. Classical JSON Representation (a.k.a. NGSIv2). ) 6 { "id": "urn:ngsi-ld:OffStreetParking:Downtown1", "type": "OffStreetParking", "availableSpotNumber": { "type": "Property", "value": 121, "metadata" : { "timestamp": { "type" : "DateTime”, "value" : "2017-07-29T12:00:04Z" }, "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] } } }
  8. 8. JSON-LD (RDF friendly) representation (a.k.a. NGSI-LD ) 7 { "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/" ] }
  9. 9. Simplified representation (Key:Value) 8 { "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
  10. 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
  11. 11. NGSI-LD Properties: Creating an Entity NGSI v2 10 NGSI-LD curl -iX POST 'http://localhost:1026/v2/entities' -H 'Content-Type: application/json' -d '{ "type": "Store", "id": "store001", "category": { "type": "Array", "value": ["commercial"]}, "address": { "type": "PostalAddress", "value": { "streetAddress": "Bornholmer Straße 65", "addressRegion": "Berlin", "addressLocality": "Prenzlauer Berg", "postalCode": "10439" }, "metadata": { "verified": { "type": "Boolean","value": true} } }, "location": {"type": "geo:json", "value": {"type": "Point", "coordinates": [13.3986, 52.5547]} }, "name": {"type": "Text", "value": "Bösebrücke Einkauf"} }' curl -iX POST http://localhost:1026/ngsi-ld/v1/entities -H 'Content-Type: application/ld+json' -d '{ "type": "Building", "id": "urn:ngsi-ld:Building:store001", "category": { "type": "Property", "value": ["commercial"]}, "address": { "type": "Property"," value": { "streetAddress": "Bornholmer Straße 65", "addressRegion": "Berlin", "addressLocality": "Prenzlauer Berg", "postalCode": "10439" }, "verified": { "type": "Property", "value": true } }, "location": { "type": "GeoProperty", "value": { "type": "Point", "coordinates": [13.3986, 52.5547]} }, "name": { "type": "Property", "value": "Bösebrücke Einkauf" }, "@context": [ "https://fiware.github.io/data-models/context.jsonld", "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld" ] }'
  12. 12. NGSI-LD Properties: Creating an Entity NGSI v2 11 NGSI-LD curl -iX POST 'http://localhost:1026/v2/entities' -H 'Content-Type: application/json' -d '{ "type": "Store", "id": "store001", "category": { "type": "Array", "value": ["commercial"]}, "address": { "type": "PostalAddress", "value": { "streetAddress": "Bornholmer Straße 65", "addressRegion": "Berlin", "addressLocality": "Prenzlauer Berg", "postalCode": "10439" }, "metadata": { "verified": { "type": "Boolean", "value": true} } }, "location": { "type": "geo:json", "value": {"type": "Point", "coordinates": [13.3986, 52.5547]} }, "name": {"type": "Text", "value": "Bösebrücke Einkauf"} }' curl -iX POST http://localhost:1026/ngsi-ld/v1/entities -H 'Content-Type: application/ld+json' -d '{ "type": "Building", "id": "urn:ngsi-ld:Building:store001", "category": { "type": "Property", "value": ["commercial"]}, "address": { "type": "Property"," value": { "streetAddress": "Bornholmer Straße 65", "addressRegion": "Berlin", "addressLocality": "Prenzlauer Berg", "postalCode": "10439" }, "verified": { "type": "Property", "value": true } }, "location": { "type": "GeoProperty", "value": { "type": "Point", "coordinates": [13.3986, 52.5547]} }, "name": { "type": "Property", "value": "Bösebrücke Einkauf" }, "@context": [ "https://fiware.github.io/data-models/context.jsonld", "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld" ] }'
  13. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
  24. 24. NGSI-LD Relationships: 3. Machine Readable Links 23 FIWARE Data Models @graph "@graph": [ { "@id": "tutorial:Product", "@type": "rdfs:Class", "rdfs:comment": [ {"@language": "en", "@value": "Product is sold in a Store."}, {"@language": "ja", "@value": "製品はストアで販売されている物"}], "rdfs:label": [{"@language": "en", "@value": "Product"}, {"@language": "ja", "@value": "製品"}], "rdfs:subClassOf": {"@id": "http://schema.org/Thing"} }, … etc { "@id": "tutorial:requestedBy", "@type": "https://uri.etsi.org/ngsi-ld/Relationship", "schema:domainIncludes": [{"@id": "tutorial:Shelf"}, {"@id": "tutorial:StockOrder"}], "schema:rangeIncludes": [{"@id": "schema:Person"}], "rdfs:comment": [ {"@language": "en","@value": "Object requested by person."}, {"@language": "ja","@value": "人が要求したオブジェクト"}], "rdfs:label": [{"@language": "en", "@value": "requested by"},{"@language": "ja", "@value": "要求者"}] }, ]
  25. 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. 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. 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. 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. 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. 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. 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/
  32. 32. Question & Answer 31 fiware-tech-help@lists.fiware.org
  33. 33. 3 2 http://fiware.org Follow @FIWARE on Twitter
  34. 34. 3 3

×