Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-17188

[Fiware-tech-help] Data Modeling with NGSI-LD: Relationship re-utilization

    Details

    • Type: extRequest
    • Status: Closed
    • Priority: Major
    • Resolution: Done
    • Fix Version/s: 2021
    • Component/s: FIWARE-TECH-HELP
    • Labels:
      None

      Description

      Good morning,

      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.io/en/latest/datamodels.html

      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

      __________________________________________________________________________________________

      You can get more information about our cookies and privacy policies on the following links:

      fiware-tech-help mailing list
      fiware-tech-help@lists.fiware.org

      To unsubscribe from fiware-tech-help mailing list, go to the information page of the list at:
      https://lists.fiware.org/listinfo/fiware-tech-help

      [Created via e-mail received from: "daniel.gonzalez.sanchez" <daniel.gonzalez.sanchez@alumnos.upm.es>]

        Activity

        Hide
        jason.fox Jason Fox added a comment -

        eMail Sent:

        Good morning Daniel,

        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/etsi_gs/CIM/001_099/009/01.03.01_60/gs_cim009v010301p.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.Relationships-Linked-Data#nine-request
        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/entities/urn:ngsi-ld:Shelf:unit001/attrs \
        -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.

        Show
        jason.fox Jason Fox added a comment - eMail Sent: Good morning Daniel, 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/etsi_gs/CIM/001_099/009/01.03.01_60/gs_cim009v010301p.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.Relationships-Linked-Data#nine-request 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/entities/urn:ngsi-ld:Shelf:unit001/attrs \ -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.

          People

          • Assignee:
            jason.fox Jason Fox
            Reporter:
            fw.ext.user FW External User
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: