Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

Is there a standardized way to migrate FIWARE NGSI-LD entity representations to NGSI-v2?

I already found this script by the FIWARE-Community, which converts an NGSI-v2 normalized representation into an NGSI-LD representation.

Is there something similar for the opposite direction? I am aware that most of the steps can be done backwards. However, I am not sure about the usual procedure for converting back the "type": "Property" nodes.

E.g given an NGSI-v2 entity representation:

{
    "id": "Store:001",
    "type": "Store",
    "name": {
        "type": "Text",
        "value": "Checkpoint Markt"
    }
}

Running the script on this will lead to:

{
    "@context": [
        https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
    ],
    "id": "urn:ngsi-ld:Store:Store:001",
    "type": "Store",
    "name": {
        "type": "Property,
        "value": "Checkpoint Markt"
    }
}

So in this case it is quite difficult to convert the "type": "Property" node back to "type": "Text".

But given the following NGSI-v2 entity representation:

{
    "type": "Store",
    "id": "Store:002",
    "address": {
        "type": "PostalAddress",
        "value": {
            "streetAddress": "Friedrichstra?e 44",
            "addressRegion": "Berlin",
            "addressLocality": "Kreuzberg",
            "postalCode": "10969"
        }
    }
}

will be converted to:

{
    "@context": [
        https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
    ],
    "id": "urn:ngsi-ld:Store:Store:002",
    "type": "Store",
    "address": {
        "type": "Property",
        "value": {
            "streetAddress": "Friedrichstrau00dfe 44",
            "addressRegion": "Berlin",
            "addressLocality": "Kreuzberg",
            "postalCode": "10969",
            "type": "PostalAddress"
        }
    }
}

This is caused by a special case in the script:

if attr['type'] == 'PostalAddress':
    ld_attr['value']['type'] = 'PostalAddress'

Wouldn't it be possible to extend all converted attributes with such a "type": _-pair in their value? Or is there a reason that this is restricted in the code to the type "PostalAddress" only? Otherwise, is there any norm for converting back these "type": "Property" nodes?

question from:https://stackoverflow.com/questions/65831813/is-there-a-standardized-way-to-migrate-fiware-ngsi-ld-entity-representations-to

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not an expert in NGSI-LD but the conversion for this particular case could be solved this way:

  • If the Property has a type within its value then use it for the attribute type in NGSIv2 (as in the "PostalAddress" case you show)
  • If the Property hasn't any type within its value then use as attribute type the default type specified in NGSIv2 specification "Partial Representations" section. For instance, if value is "Checkpoint Markt" (which is a string) then attribute type in NGSIv2 will correspond to "Text".

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...