We use proprietary and third party´s cookies to improve your experience and our services, identifying your Internet Browsing preferences on our website; develop analytic activities and display advertising based on your preferences. If you keep browsing, you accept its use. You can get more information on our Cookie Policy
Cookies Policy
Ask Your Question
0

Data Modeling with NGSI-LD: Relationship re-utilization

asked 2020-12-10 13:47:47 +0200

Daniel gravatar image

Hi everyone,

I have a doubt relative to Relationship attribute definition in a NGSI-LD data models. I was wondering if is posible to re-use the same relationship (with the same relationship name) to point to different Entity types encoded as the objects of the relationship itself.

For example, if we have the use case of a Store that sells different type of electronics Items (e.g. computers, smartphones or printers), can we establish the relationship between a Store entity and these types of Item entities (Computer, Smartphone and Printer) with the same "hasItem" Relationship? In this use case, would the data model lose semantics?

NGSI-LD simplified representation for Store entity pointing to Computer and Printer entity objects:

{ "id": "urn:ngsi-ld:Store:store-1", "type": "Store", "hasItem": [{ "type": "Relationship", "object": "urn:ngsi-ld:Computer:computer-HP-0001" },{ "type": "Relationship", "object": "urn:ngsi-ld:Printer:printer-HP-0001" }] ... }

I've seen in different tutorials of FIWARE about data models in NGSI-LD that one NGSI-LD entity with different relationships of properties (relationship like a metadata of property) can re-use the same type of relationship. There is an example of this with a "providedBy" relationship between Building properties and Temperature and FillingLevel Sensors entities in Step-by-Step for NGSI-LD Tutorial of FIWARE: https://ngsi-ld-tutorials.readthedocs...

My doubt is about if is posible to re-use the same type of relationship between different entities if we use normal relationship like "hasItem" in the explained use case (no metadata Relationship of Property like "providedBy").

If this were posible, like "hasItem" is a multi-relationship entry with different entity objects, it would be necessary to introduce a "datasetId" parameter in each relationship instance in "hasItem" to uniquely identify these relationship instances (i.e. one datasetId por Computer instance object and another one for Printer instance object in the hasItem multi-relationship)? I think not because this multi-relationship entry points to different types of entities and it would not be necessary to uniquely identify them.

Finally, also I was wondering if is posible to re-use the same relationship (with the same relationship name) in different types of Entities. For example, if we have the use case of two different stores: Electronic Store and Garden Store that sells different types of Items, can we re-use the same "hasItem" Relationship for both ElectronicStore and GardenStore entities?

NGSI-LD simplified representations for ElectronicStore and GardenStore entities using the "hasItem" Relationship:

{ "id": "urn:ngsi-ld:ElectronicStore:electronic-store-1", "type": "ElectronicStore", "hasItem": { "type": "Relationship", "object": "urn:ngsi-ld:Computer:computer-HP-0001" } ... }

{ "id": "urn:ngsi-ld:GardenStore:garden-store-1", "type": "GardenStore", "hasItem": { "type": "Relationship", "object": "urn:ngsi-ld:Mower:mower-model-AX23" } ... }

Thank you very much in advance. Sincerely,

Daniel González Sánchez

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2020-12-14 09:24:16 +0200

admin gravatar image

Your eMail poses some interesting questions which I will attempt to answer. Properties and Relationships are defined within the ETSI specification:

https://www.etsi.org/deliver/etsigs/CIM/001099/009/01.03.0160/gscim009v010301p.pdf

and trying to reduce this 200 page document to a series of bite size tutorials is quite a task. The short answer is yes, one-to-many relationships are fully supported by NGSI-LD, although the official syntax is more verbose than I personally would like.

The 1.3.1 spec supports arrays of relationships as shown:

curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Building:store001/attrs' \ -H 'Content-Type: application/ld+json' \ --data-raw '{ "furniture": [ { "type": "Relationship", "datasetId": "urn:ngsi-ld:Relationship:1", "object": "urn:ngsi-ld:Shelf:001" } ,

{ "type": "Relationship", "datasetId": "urn:ngsi-ld:Relationship:2", "object": "urn:ngsi-ld:Shelf:002" } ], "@context": "https://fiware.github.io/tutorials.Step-by-Step/data-models-context.jsonld" }'

Each element beyond the first must have a unique datasetId. This syntax is also used for Multi valued Properties or GeoProperties (For example where location is being provided by two different sensors e.g. GPS urn:ngsi-ld:GPS or Wifi triangulation. urn:ngsi-ld:WiFi)

The example above comes from the older NGSI-LD for NGSI-v2 Supermarket tutorial https://github.com/FIWARE/tutorials.R... I haven't added an equivalent in the newer Smart Farm NGSI-LD first Smart Farm system yet.

The Orion-LD context broker still supports an unofficial simplified syntax:

curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Building:store001/attrs' \ -H 'Content-Type: application/ld+json' \ --data-raw '{ "furniture":

{ "type": "Relationship", "object": [ "urn:ngsi-ld:Shelf:001", "urn:ngsi-ld:Shelf:002"] } , "@context": "https://fiware.github.io/tutorials.Step-by-Step/data-models-context.jsonld" }'

This mimics the key-values format and also allows one-to-many relationships, but does not allow for meta-data on each element.

As you correctly stated, relationships are directional, and this furniture one-to-many is the direct opposite of reusing something like locatedIn which would appear on multiple entities

curl -X POST \ http://localhost:1026/ngsi-ld/v1/enti... \ -H 'Content-Type: application/ld+json' \ -H 'fiware-servicepath: /' \ -d '{ "locatedIn" :

{ "type": "Relationship", "object": "urn:ngsi-ld:Building:store001", } , "@context": "https://fiware.github.io/tutorials.Step-by-Step/data-models-context.jsonld" }'

Within NGSI-LD the object attribute of a Relationship is specified to be a URN - it can point to any other object, so there is no problem with your Combined urn-ngsi-ld:Computer:001 and urn-ngsi-ld:Mower:002 example.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-12-10 13:42:38 +0200

Seen: 444 times

Last updated: Dec 14 '20