oeg-upm / DeltaCimApp

Apache License 2.0
1 stars 0 forks source link

JSON-LD Payload is modified by CIM #20

Closed kostopoulos closed 4 years ago

kostopoulos commented 4 years ago

POSTing a JSON-LD payload via the CIM leads to paylod modification. Such modifications have an impact on our parsers. Please leave the payload as is.

For example our original post is:

{
  "@context": {
    "FEID": {
      "@id": "core:FEID"
    },
    "prefix": "http://delta.iti.gr/",
    "Measurement": {
      "@id": "core:Measurement"
    },
    "PowerConsumption": {
      "@id": "core:PowerConsumption"
    },
    "VirtualNode": {
      "@id": "core:VirtualNode"
    },
    "core": "http://delta.linkeddata.es/def/core#",
    "hasTimeStamp": {
      "@id": "core:hasTimeStamp"
    },
    "hasValue": {
      "@id": "core:hasValue"
    },
    "isRelatedToProperty": {
      "@id": "core:isRelatedToProperty"
    },
    "makesMeasurement": {
      "@id": "core:makesMeasurement"
    },
    "manage": {
      "@id": "core:manage"
    },
    "om": "http://www.foodvoc.org/page/om-1.8/",
    "saref": "https://w3id.org/saref#",
    "xsd": "http://www.w3.org/2001/XMLSchema#"
  },
  "@graph": [
    {
      "@id": "http://delta.iti.gr/dvn4",
      "@type": "VirtualNode",
      "manage": {
        "@id": "prefix:feidID406"
      }
    },
    {
      "@id": "feidID9PowerConsumption0",
      "@type": "Measurement",
      "hasTimeStamp": {
        "@type": "xsd:dateTime",
        "@value": "2020-01-28T18:58:00Z"
      },
      "hasValue": {
        "@type": "xsd:float",
        "@value": "72.54726"
      },
      "isRelatedToProperty": {
        "@id": "PowerConsumption"
      },
      "saref:isMeasuredIn": {
        "@id": "om:watt"
      }
    },
    {
      "@id": "http://delta.iti.gr/feidID406",
      "@type": "FEID",
      "makesMeasurement": [
        {
          "@id": "http://delta.iti.gr/feidID9PowerConsumption0"
        }
      ]
    }
  ]
}

but what is finally received is:

{
    "@graph": [
        {
            "@id": "prefix:dvn4",
            "@type": "core:VirtualNode",
            "manage": "prefix:feidID406"
        },
        {
            "@id": "prefix:feidID406",
            "@type": "core:FEID",
            "makesMeasurement": "prefix:feidID9PowerConsumption0"
        },
        {
            "@id": "prefix:feidID9PowerConsumption0",
            "@type": "core:Measurement",
            "hasTimeStamp": "2020-01-28T18:58:00Z",
            "hasValue": "72.54726",
            "isRelatedToProperty": "prefix:PowerConsumption",
            "isMeasuredIn": "om:watt"
        }
    ],
    "@context": {
        "hasTimeStamp": {
            "@id": "http://delta.linkeddata.es/def/core#hasTimeStamp",
            "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
        },
        "hasValue": {
            "@id": "http://delta.linkeddata.es/def/core#hasValue",
            "@type": "http://www.w3.org/2001/XMLSchema#float"
        },
        "isRelatedToProperty": {
            "@id": "http://delta.linkeddata.es/def/core#isRelatedToProperty",
            "@type": "@id"
        },
        "isMeasuredIn": {
            "@id": "https://w3id.org/saref#isMeasuredIn",
            "@type": "@id"
        },
        "makesMeasurement": {
            "@id": "http://delta.linkeddata.es/def/core#makesMeasurement",
            "@type": "@id"
        },
        "manage": {
            "@id": "http://delta.linkeddata.es/def/core#manage",
            "@type": "@id"
        },
        "core": "http://delta.linkeddata.es/def/core#",
        "prefix": "http://delta.iti.gr/",
        "saref": "https://w3id.org/saref#",
        "xsd": "http://www.w3.org/2001/XMLSchema#",
        "om": "http://www.foodvoc.org/page/om-1.8/"
    }
}
AndreaCimminoArriaga commented 4 years ago

There are several ways to express the same payload in JSON-LD (since data and semantics may be expressed with different serialisations). Adopting a library for handling JSON-LD, like RDFlib, will solve your problem abstracting you from the different forms of representing the same payload and giving you a unified view for the validation and data processing.

The payloads that you provided as example are equivalent, therefore, the problem does not lies at the CIM level. I suggest adopting a JSON-LD library to correctly validate and consume these payloads, instead of forcing the use of a sub-set of JSON-LD, since this will on the one hand go against the semantic interoperability designed for DELTA, and on the other hand, will make your systems not able to interact with external systems which data is been translated by the CIM to JSON-LD.