Skip to content

Commit

Permalink
Merge pull request #1537 from FIWARE/attributes/vocab
Browse files Browse the repository at this point in the history
First draft for VocabProperty
  • Loading branch information
kzangeli authored Jan 18, 2024
2 parents ff465d3 + 0348532 commit 29547ea
Show file tree
Hide file tree
Showing 13 changed files with 555 additions and 60 deletions.
6 changes: 6 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fixed Issue:
* #1535 No matching with 'q' when matching subscriptions for deletion of an entity

New Features:
* Support for VocabularyProperty (highlu untested and 'q' expansions for vocab-properties is not yet implemented)

6 changes: 3 additions & 3 deletions src/lib/orionld/dbModel/dbModelFromApiAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extern "C"
// * First an object "md" is created, and all fields of the attribute, except the special ones are moved inside "md".
// Special fields:
// - type
// - value/object/languageMap (must be renamed to "value" - that's part of the database model)
// - value/object/languageMap/vocab (must be called "value" - that's part of the database model)
// - observedAt
// - datasetId
// - unitCode
Expand Down Expand Up @@ -149,13 +149,13 @@ bool dbModelFromApiAttribute(KjNode* attrP, KjNode* dbAttrsP, KjNode* attrAddedV
//

// Move special fields back to "attrP"
const char* specialV[] = { "type", "value", "object", "languageMap", "datasetId" }; // observedAt+unitCode are mds (db-model)
const char* specialV[] = { "type", "value", "object", "languageMap", "vocab", "datasetId" }; // observedAt+unitCode are mds (db-model)
for (unsigned int ix = 0; ix < K_VEC_SIZE(specialV); ix++)
{
KjNode* nodeP = kjLookup(mdP, specialV[ix]);
if (nodeP != NULL)
{
if ((ix == 2) || (ix == 3)) // "object", "languageMap", change name to "value" (Orion's DB model)
if ((ix == 2) || (ix == 3) || (ix == 4)) // "object", "languageMap", "vocab": change name to "value" (Orion's DB model)
nodeP->name = (char*) "value";

kjChildRemove(mdP, nodeP);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/dbModel/dbModelFromApiEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extern "C"
// * If Array, recursive call for each member (set the name to the sttribute name)
// * "datasetId" present - call orionldDbModelAttributeDatasetId
// * "type" can't be modified
// * "value"/"object"/"languageMap" changes name to "value" and RHS stays as is
// * "value"/"object"/"languageMap"/"vocab" changes name to "value" and RHS stays as is
// * "observedAt" is made an Object with single member "value"
// * "unitCode" is made an Object with single member "value"
// * "md" is created and added
Expand Down
5 changes: 4 additions & 1 deletion src/lib/orionld/dbModel/dbModelFromApiSubAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool dbModelFromApiSubAttribute(KjNode* saP, KjNode* dbMdP, KjNode* mdAddedV, Kj

if (strcmp(saDotName, "value") == 0)
return true;
else if ((strcmp(saDotName, "object") == 0) || (strcmp(saDotName, "languageMap") == 0))
else if ((strcmp(saDotName, "object") == 0) || (strcmp(saDotName, "languageMap") == 0) || (strcmp(saDotName, "vocab") == 0))
saDotName = (char*) "value"; // Orion-LD's database model states that all attributes have a "value"
else if (strcmp(saDotName, "observedAt") == 0)
{
Expand Down Expand Up @@ -155,6 +155,9 @@ bool dbModelFromApiSubAttribute(KjNode* saP, KjNode* dbMdP, KjNode* mdAddedV, Kj
if (valueP == NULL)
valueP = kjLookup(saP, "languageMap");

if (valueP == NULL)
valueP = kjLookup(saP, "vocab");

if (valueP != NULL)
valueP->name = (char*) "value";

Expand Down
36 changes: 33 additions & 3 deletions src/lib/orionld/dbModel/dbModelToApiAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,23 @@ void dbModelToApiAttribute(KjNode* dbAttrP, bool sysAttrs, bool eqsForDots)

if ((typeP != NULL) && (valueP != NULL) && (typeP->type == KjString))
{
if (strcmp(typeP->value.s, "Relationship") == 0) valueP->name = (char*) "object";
else if (strcmp(typeP->value.s, "LanguageProperty") == 0) valueP->name = (char*) "languageMap";
if (strcmp(typeP->value.s, "Relationship") == 0) valueP->name = (char*) "object";
else if (strcmp(typeP->value.s, "LanguageProperty") == 0) valueP->name = (char*) "languageMap";
else if (strcmp(typeP->value.s, "VocabularyProperty") == 0)
{
valueP->name = (char*) "vocab";

if (valueP->type == KjString)
valueP->value.s = orionldContextItemAliasLookup(orionldState.contextP, valueP->value.s, NULL, NULL);
else if (valueP->type == KjArray)
{
for (KjNode* wordP = valueP->value.firstChildP; wordP != NULL; wordP = wordP->next)
{
if (wordP->type == KjString)
wordP->value.s = orionldContextItemAliasLookup(orionldState.contextP, wordP->value.s, NULL, NULL);
}
}
}
}


Expand Down Expand Up @@ -334,7 +349,7 @@ KjNode* dbModelToApiAttribute2(KjNode* dbAttrP, KjNode* datasetP, bool sysAttrs,
// - and No metadata
// => KeyValues
//
// Else, just remove the attribute type, keep value/object/languageMap
// Else, just remove the attribute type, keep value/object/languageMap/vocab
// And call dbModelToApiSubAttribute2 with Concise
//
bool conciseAsKeyValues = false;
Expand Down Expand Up @@ -398,6 +413,21 @@ KjNode* dbModelToApiAttribute2(KjNode* dbAttrP, KjNode* datasetP, bool sysAttrs,
{
if (attrType == Relationship)
nodeP->name = (char*) "object";
else if (attrType == VocabularyProperty)
{
nodeP->name = (char*) "vocab";

if (nodeP->type == KjString)
nodeP->value.s = orionldContextItemAliasLookup(orionldState.contextP, nodeP->value.s, NULL, NULL);
else if (nodeP->type == KjArray)
{
for (KjNode* wordP = nodeP->value.firstChildP; wordP != NULL; wordP = wordP->next)
{
if (wordP->type == KjString)
wordP->value.s = orionldContextItemAliasLookup(orionldState.contextP, wordP->value.s, NULL, NULL);
}
}
}
else if (attrType == LanguageProperty)
{
if (lang != NULL)
Expand Down
10 changes: 6 additions & 4 deletions src/lib/orionld/dbModel/dbModelToApiSubAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ void dbModelToApiSubAttribute(KjNode* dbSubAttrP)

if ((typeP != NULL) && (valueP != NULL) && (typeP->type == KjString))
{
if (strcmp(typeP->value.s, "Relationship") == 0) valueP->name = (char*) "object";
else if (strcmp(typeP->value.s, "LanguageProperty") == 0) valueP->name = (char*) "languageMap";
if (strcmp(typeP->value.s, "Relationship") == 0) valueP->name = (char*) "object";
else if (strcmp(typeP->value.s, "LanguageProperty") == 0) valueP->name = (char*) "languageMap";
else if (strcmp(typeP->value.s, "VocabularyProperty") == 0) valueP->name = (char*) "vocab";
}
}

Expand Down Expand Up @@ -140,8 +141,9 @@ KjNode* dbModelToApiSubAttribute2(KjNode* dbSubAttributeP, bool sysAttrs, Orionl

if (strcmp(nodeP->name, "value") == 0)
{
if (subAttrType == Relationship) nodeP->name = (char*) "object";
else if (subAttrType == LanguageProperty) nodeP->name = (char*) "languageMap";
if (subAttrType == Relationship) nodeP->name = (char*) "object";
else if (subAttrType == LanguageProperty) nodeP->name = (char*) "languageMap";
else if (subAttrType == VocabularyProperty) nodeP->name = (char*) "vocab";

kjChildAdd(subAttrP, nodeP);
}
Expand Down
21 changes: 20 additions & 1 deletion src/lib/orionld/notifications/notificationSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,26 @@ static void attributeFix(KjNode* attrP, CachedSubscription* subP)
if (addedP != NULL) kjChildRemove(attrP, addedP);
if (removedP != NULL) kjChildRemove(attrP, removedP);

bool asSimplified = false;

//
// If vocab-property, its value needs to be compacted
//
KjNode* vocabP = kjLookup(attrP, "vocab");
if (vocabP != NULL)
{
if (vocabP->type == KjString)
vocabP->value.s = orionldContextItemAliasLookup(subP->contextP, vocabP->value.s, NULL, NULL);
else if (vocabP->type == KjArray)
{
for (KjNode* wordP = vocabP->value.firstChildP; wordP != NULL; wordP = wordP->next)
{
if (wordP->type == KjString)
wordP->value.s = orionldContextItemAliasLookup(subP->contextP, wordP->value.s, NULL, NULL);
}
}
}

bool asSimplified = false;
if (attrP->type == KjObject)
{
if (simplified) attributeToSimplified(attrP, subP->lang.c_str());
Expand All @@ -284,6 +302,7 @@ static void attributeFix(KjNode* attrP, CachedSubscription* subP)
if (strcmp(saP->name, "value") == 0) continue;
if (strcmp(saP->name, "object") == 0) continue;
if (strcmp(saP->name, "languageMap") == 0) continue;
if (strcmp(saP->name, "vocab") == 0) continue;
if (strcmp(saP->name, "unitCode") == 0) continue;

eqForDot(saP->name);
Expand Down
Loading

0 comments on commit 29547ea

Please sign in to comment.