Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EliottPaillard opened this issue Jun 4, 2024 · 5 comments
Open

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

EliottPaillard opened this issue Jun 4, 2024 · 5 comments

Comments

@EliottPaillard
Copy link

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
Copy link
Member

bobeal commented Jun 4, 2024

Hi @EliottPaillard,

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

  • from https://smartdatamodels.org/context.jsonld, name is expanded to https://uri.etsi.org/ngsi-ld/name at entity creation time
  • when you get the entity without specifying any context, only the default core context is taken into account (https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld for Stellio)
  • in the core context, there is a "ngsi-ld": "https://uri.etsi.org/ngsi-ld/" clause, so https://uri.etsi.org/ngsi-ld/name is compacted to ngsi-ld:name
  • please note that this is JSON-LD expansion / compaction behavior, so not something specific to NGSI-LD specification

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

  • as described in 5.5.7: "For the avoidance of doubt, the @context used to perform compaction or expansion of terms shall be the one provided by each API call (or the default @context in its absence), and not any other @context which might have been supplied previously. For instance, when performing "Query Entity" operations (clause 5.7.2), the @context used to perform URI expansion and compaction shall be the one provided by the request.".
  • so if you do a GET operation without specifying any specific JSON-LD context, the context broker will use its default core context (https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld for Stellio)
  • and the context used at entity creation time is always discarded after expansion has been done

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

  • can you give me the request you are doing (with the request headers)?
  • are you doing it on the same entity provided in the issue?

@EliottPaillard
Copy link
Author

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
Copy link
Member

bobeal commented Jun 8, 2024

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
Copy link
Author

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
Copy link
Member

bobeal commented Jun 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants