简体   繁体   中英

FIWARE, NGSI-LD - Understand the @context

I am creating a data model for a particular application and I did not start from any base model; since I did not start from any base model, the context below is sufficient, correct?

"@context": [
            "https://schema.lab.fiware.org/ld/context",
            "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld"
]

My data model is not complicated, with just these properties and entity being more "complex":

"address": {
            "type": "Property",
            "value": {
                "streetAddress": "",
                "postalCode": "",
                "addressLocality": "",
                "addressCountry": ""
            }
},
"location": {
            "type": "Point",
            "coordinates": [
                ,
            ]
},
{
        "id": "urn:ngsi-ld:MeasurementSensor:",
        "type": "MeasurementSensor",
        "measurementVariable": {
            "type": "Property",
            "value": "Temperature"
        },
        "measurementValue": {
            "type": "Property",
            "value": 32.0,
            "unitCode": "ºC",
            "observedAt": "2022-05-10T11:09:00.000Z"
        },
        "refX": {
            "type": "Relationship",
            "object": "urn:ngsi-ld:"
        },
        "@context": [
            "https://schema.lab.fiware.org/ld/context",
            "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld"
        ]
}

If you are using your own custom vocabulary you should declare your types and properties in your own LD @context. For instance,

{
   "@context": [
    {
     "MeasurementSensor": "https://example.org/my-types/MesaurementSensor"
    },
    "https://schema.lab.fiware.org/ld/context",
    "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld"
   ]
}

it also seems you are not using URNs properly, you should check. unitCode seems to be broken as well, as it must follow the UN/CEFACT unit codes.

Nonetheless, I would not recommend to define your own vocabulary for sensors, given there are existing Vocabularies such as SAREF or W3C SOSA that can and should be reused.

I'm not a data model expert but I do know a thing or two about NGSI-LD and NGSI-LD brokers. The @context you use is an array of "https://schema.lab.fiware.org/ld/context" and v1.3 of the core context.

"https://schema.lab.fiware.org/ld/context" in its turn is an array of "https://fiware.github.io/data-models/context.jsonld" and v1.1 of the core context ...

And, ""https://fiware.github.io/data-models/context.jsonld" doesn't define any of the three terms you are using, so, no need to give any context for that. The terms will be expanded using the default URL of the core context (the value of the @vocab member of the core context defines the default URL).

An NGSI-LD broker has the core context built-in, you don't need to pass it, so do yourself a favor, and get faster responses by not passing the core context to the broker. No need. And, if you need a user context, pass it in the HTTP Header "Link" instead. Host it somewhere (an NGSi-LD broker offers that service), so you don't force the poor broker to parse the @conterxt in each and every request.

Lastly, do follow Jose Manuels recommendations and use standard names for your attributes (and value for unitCode).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM