D.1 Introduction
These algorithms are informative but NGSI-LD implementations should
aim at either implementing them as they are described here or devising
similar algorithms which take exactly the same input and provides
exactly the same output (or an equivalent one as per the JSON-LD
specification [2]).
This algorithm takes as input an NGSI-LD graph which top level node
is a particular Entity and returns as output a JSON-LD document which
represents all the data associated to the entity. The JSON-LD document
(and its associated @context) corresponds to a representation of
the Entity in JSON-LD as per the NGSI-LD Information Model.
NOTE:
An
early
implementation
of
this
algorithm
can
be
found
at
[i.5].
Let:
Let N be G's top level node.
N is an Entity instance of type T or types
Ts. Type name is "AliasT" or there is an Array of Type
names ["AliasT1", …,"AliasTn"], N's identifier is I.
N has 0 or more associated Property. Each Property
(Psi) is defined as follows:
Property type identifier is Pi.
Property name is "AliasPi".
Property Value is Vi.
Property Value's associated data type is Di.
Relationship type identifier is Ri.
Relationship name is "AliasRi".
Relationship target object identifier is Robji.
The algorithm should run as follows, provided all the preconditions
defined above are satisfied:
Add to C a new member <"AliasT", T> or new members <"AliasT1",
T1> … <"AliasTn", Tn>.
Add to O two new members:
a) <"id", I>.
b) <"type", "AliasT"> or <"type", ["AliasT1", …,"AliasTn"]>
.">.
For each Property Psi (Pi, "AliasP", Vi, Di) associated to N:
a) Run Algorithm ALG1.1 taking the following inputs:
For each Relationship Rs (Ri, AliasRi, Robji) associated to N:
a) Run Algorithm ALG1.2 taking the following inputs:
Return (O, C) and end of the algorithm.
Let Ps be the Property that has to be transformed.
It is defined by (P, "AliasP", V, D), where P denotes a
Property Type Id, "AliasP" is the Property name,
V is the Property Value and D is the
Property Value's data type.
Ps might be associated to extra Properties or Relationships.
Let O be the output JSON-LD object and C the associated JSON-LD
context:
Execute the following steps:
a) If no member with "AliasP" is present in O, add a new member to O with
key "AliasP" and value an object structure, let it be named
Op as defined in the following. Otherwise, add all
existing members with "AliasP" to a JSON-LD array and in addition put
the object structure Op as defined in the following:
1) <"@type", D>.
2) <"@value", V>.
1) <"value", V>.
b) Add a new member to C as follows:
c) For each Property associated to Ps (Pss) recursively run the present
algorithm (ALG1.1) taking the following inputs:
d) For each Relationship associated to Ps (Rss) run algorithm
ALG1.2 taking the following inputs:
Return (O,C) and end of the algorithm.
Let Rs be the Relationship that has to be
transformed. It is defined by (R, "AliasR", Robj), where
R denotes a Relationship Type Id,
"AliasR" is the Relationship's name and
Robj is the identifier of the target object of the
Relationship.
Rs might be associated to extra Properties or Relationships.
Let O be the output JSON-LD object and C the current JSON-LD
context:
Execute the following statements:
a) If no member with "AliasR" is present in O, add a new member to O with
key "AliasR" and value an object structure, let it be named
Or, and defined as in the following. Otherwise, add all
existing members with "AliasR" to a JSON-LD array and in addition put
the object structure Or as defined in the following:
b) For each Property associated to Rs (Pss) run the algorithm
ALG1.1 taking the following inputs:
c) For each Relationship associated to Rs (Rss) recursively run the
present algorithm ALG1.2 taking the following inputs:
Return (O,C) and end of the algorithm.