stellio-hub / stellio-context-broker

Stellio is an NGSI-LD compatible context broker
https://stellio.readthedocs.io
Apache License 2.0
25 stars 11 forks source link

[Question] @context and "name" attribute #1176

Open EliottPaillard opened 1 month ago

EliottPaillard commented 1 month ago

Hello. I'm using Stellio 2.13.0

I POST this entity : { "id": "urn:ngsi-ld:Building:001", "type": "Building", "name": { "type": "Property", "value": "Eiffel Tower" }, "subCategory": { "type": "Property", "value": "tourism" }, "airQualityLevel": { "type": "Property", "value": 4, "unitCode": "C62", "observedAt": "2020-09-09T16:40:00.000Z" }, "almostFull": { "type": "Property", "value": false }, "@context": [ "https://smartdatamodels.org/context.jsonld", "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.7.jsonld" ] } Then when I want to retrieve it using: GET -H "Accept: application/ld+json"

The "name" element become "ngsi-ld:name". However none of user or core context have such an extended syntax. I thought it would be instead "https://uri.etsi.org/ngsi-ld/name" as it is in the provided user context. Why is this not the case? I did not find why in the API Specifications.

Also I expected the "@context" element to be like the provided one. Instead I have "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld". I believe this is related to Stellio and its version and not related to the context provided when the entity was created but I found it kinda curious actually. Again I did not find anything relevant about this behaviour in the specs but the provided examples with the same Accept header show the "@context" element as an array with an user and a core context.

At the same time, speaking about the "ngsi-ld:name" appearance, I experimented the aggregated methods for the temporal evolutions of entities. And the responses display them as "ngsi-ld:avg" or "ngsi-ld:max". I found it curious as well, and again I did not find in the specs apart one example showing "max" and "avg" in the response. Is this a normal behaviour though?

I hope I am understandable so you can enlighten me. Thanks in advance

bobeal commented 1 month ago

Hi @EliottPaillard,

For the 1st point (name becoming ngsi-ld:name):

For the 2nd point (provided "@context" point):

For the 3rd point (ngsi-ld:avg):

EliottPaillard commented 4 weeks ago

Hello @bobeal,

About point 1 and 2 I understand well now, thank you for this!

Regarding point 3 : I create this entity : { "id": "urn:ngsi-ld:Vehicle:temporalEvolution", "type": "Vehicle", "speed": [ { "type": "Property", "value": 120, "observedAt": "2020-08-01T12:03:00Z" }, { "type": "Property", "value": 80, "observedAt": "2020-08-01T12:05:00Z" }, { "type": "Property", "value": 100, "observedAt": "2020-08-01T12:07:00Z" } ], "batteryLevel": [ { "type": "Property", "value": 67, "observedAt": "2020-08-01T12:03:00Z" }, { "type": "Property", "value": 53, "observedAt": "2020-08-01T13:05:00Z" }, { "type": "Property", "value": 40, "observedAt": "2020-08-01T14:07:00Z" } ], "@context": [ "https://smartdatamodels.org/context.jsonld", "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld" ] }

And I do this request : curl -iX GET 'http://localhost:1080/ngsi-ld/v1/temporal/entities/urn:ngsi-ld:Vehicle:temporalEvolution/?aggrMethods=avg,max&aggrPeriodDuration=PT1H&options=aggregatedValues' -H 'Accept: application/json' -H 'Link: https://smartdatamodels.org/context.jsonld; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"'

And the response is: { "id": "urn:ngsi-ld:Vehicle:temporalEvolution", "type": "Vehicle", "batteryLevel": { "type": "Property", "ngsi-ld:avg": { "@list": [ { "@list": [ 67.0, "2020-08-01T12:03:00Z", "2020-08-01T13:03:00Z" ] }, { "@list": [ 53.0, "2020-08-01T13:03:00Z", "2020-08-01T14:03:00Z" ] }, { "@list": [ 40.0, "2020-08-01T14:03:00Z", "2020-08-01T15:03:00Z" ] } ] }, "ngsi-ld:max": { "@list": [ { "@list": [ 67.0, "2020-08-01T12:03:00Z", "2020-08-01T13:03:00Z" ] }, { "@list": [ 53.0, "2020-08-01T13:03:00Z", "2020-08-01T14:03:00Z" ] }, { "@list": [ 40.0, "2020-08-01T14:03:00Z", "2020-08-01T15:03:00Z" ] } ] } }, "speed": { "type": "Property", "ngsi-ld:avg": { "@list": [ { "@list": [ 100.0, "2020-08-01T12:03:00Z", "2020-08-01T13:03:00Z" ] } ] }, "ngsi-ld:max": { "@list": [ { "@list": [ 120.0, "2020-08-01T12:03:00Z", "2020-08-01T13:03:00Z" ] } ] } } }

bobeal commented 3 weeks ago

Hi @EliottPaillard,

The provided context (https://smartdatamodels.org/context.jsonld) contains pieces of the NGSI-LD core context (look for all the terms starting with http://uri.etsi.org/ngsi-ld/).

When Stellio receives the query, it looks at the provided context and thinks the NGSI-LD core context is already included in it since it finds many terms from the NGSI-LD core context. So it does not add it at the end as it should do when the core context is not provided and the JSON-LD compaction is not what you are expecting since some important definitions are missing. For instance, this one:

  "avg": {
      "@id": "ngsi-ld:avg",
      "@container": "@list"
  }

These contexts including (often outdated) pieces from the core context are really dangerous :(

I'll think of a way we can better handle this in Stellio...

EliottPaillard commented 3 weeks ago

Hey,

I tried to manage this context problem by removing the incriminated elements. However, I met again the 503 code error I was already talking about in #1162 But this time I made the context available through a github page as you recommended. I don't understand why the 503 appears again.

For example while trying to create this entity: { "id": "urn:ngsi-ld:Building:002", "type": "Building", "name": { "type": "Property", "value": "Eiffel Tower" }, "subCategory": { "type": "Property", "value": "tourism" }, "location": { "type": "GeoProperty", "value": { "type": "Point", "coordinates": [ 13.3986, 52.5547 ] } }, "@context": "https://raw.githubusercontent.com/EliottPaillard/context/main/test.jsonld" }

bobeal commented 3 weeks ago

Hi,

The link you are using is not pointing to a GitHub page.

For instance, for this raw context file that we have in one of our repository: https://raw.githubusercontent.com/easy-global-market/ngsild-api-data-models/master/authorization/jsonld-contexts/authorization-compound.jsonld, the GitHub page version is: https://easy-global-market.github.io/ngsild-api-data-models/authorization/jsonld-contexts/authorization-compound.jsonld

Tried to find it for your context but https://eliottpaillard.github.io/context/test.jsonld is giving me a 404.