From fa202221ecb06ae5f5ee3fda8eb1e8f7935c762e Mon Sep 17 00:00:00 2001 From: dvince Date: Wed, 5 Feb 2025 13:37:54 -0500 Subject: [PATCH 1/5] [TASK]: Grounding extra concept to be updated #6436 Using the `modifiers` instead of `context` --- .../src/components/widgets/tera-concept.vue | 14 ++++++------- .../client/hmi-client/src/services/concept.ts | 20 +++++++++---------- packages/client/hmi-client/src/types/Types.ts | 1 - .../models/dataservice/Grounding.java | 14 +------------ .../service/tasks/TaskUtilities.java | 2 +- .../service/data/DatasetServiceTests.java | 20 +++++++++---------- .../service/data/DocumentServiceTests.java | 14 ++++++------- .../data/TerariumAssetCloneServiceTests.java | 8 ++++---- 8 files changed, 40 insertions(+), 53 deletions(-) diff --git a/packages/client/hmi-client/src/components/widgets/tera-concept.vue b/packages/client/hmi-client/src/components/widgets/tera-concept.vue index d8018e81d4..4708f330c1 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-concept.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-concept.vue @@ -23,11 +23,11 @@ import { computed, ref, watch } from 'vue'; import AutoComplete, { AutoCompleteCompleteEvent } from 'primevue/autocomplete'; import type { DKG, Grounding } from '@/types/Types'; import { - getDKGFromGroundingContext, + getDKGFromGroundingModifier, getDKGFromGroundingIdentifier, parseCurieToIdentifier, - parseListDKGToGroundingContext, - searchCuriesEntities + searchCuriesEntities, + parseListDKGToGroundingModifiers } from '@/services/concept'; defineProps<{ @@ -44,7 +44,7 @@ async function searchDKG(event: AutoCompleteCompleteEvent) { const concepts = ref([]); function saveConcepts() { - const newGrounding = { ...(grounding.value as Grounding), identifiers: {}, context: {} }; + const newGrounding = { ...(grounding.value as Grounding), identifiers: {}, modifiers: {} }; if (!isEmpty(concepts.value)) { // Split the list of concepts into identifier (first item) and context (rest of the items) @@ -55,7 +55,7 @@ function saveConcepts() { } if (!isEmpty(contextConcepts)) { - newGrounding.context = parseListDKGToGroundingContext(contextConcepts); + newGrounding.modifiers = parseListDKGToGroundingModifiers(contextConcepts); } } @@ -86,8 +86,8 @@ watch( } // Then add the context concepts - if (!isEmpty(newGrounding.context)) { - getDKGFromGroundingContext(newGrounding.context).then((dkgList) => { + if (!isEmpty(newGrounding.modifiers)) { + getDKGFromGroundingModifier(newGrounding.modifiers).then((dkgList) => { concepts.value.push(...dkgList); }); } diff --git a/packages/client/hmi-client/src/services/concept.ts b/packages/client/hmi-client/src/services/concept.ts index 527f7739be..8cabf21aba 100644 --- a/packages/client/hmi-client/src/services/concept.ts +++ b/packages/client/hmi-client/src/services/concept.ts @@ -123,10 +123,10 @@ async function getDKGFromGroundingIdentifier(identifier: Object): Promise { return dkg; } -async function getDKGFromGroundingContext(context: Grounding['context']): Promise { +async function getDKGFromGroundingModifier(modifiers: Grounding['modifiers']): Promise { let dkgList: DKG[] = []; - if (!isEmpty(context)) { - Object.entries(context).forEach(([key, value]) => { + if (!isEmpty(modifiers)) { + Object.entries(modifiers).forEach(([key, value]) => { const dkg: DKG = { name: '', curie: '', description: '' }; // Test if the value is a curie or a string @@ -158,17 +158,17 @@ function parseCurieToIdentifier(curie: string | undefined): { [key: string]: str return { [key]: value }; } -function parseListDKGToGroundingContext(dkgList: DKG[]): { [index: string]: string } { - const context: Grounding['context'] = {}; +function parseListDKGToGroundingModifiers(dkgList: DKG[]): { [index: string]: string } { + const modifiers: Grounding['modifiers'] = {}; dkgList.forEach((dkg) => { if (dkg.name.includes(':')) { const [key, value] = dkg.name.split(':'); - context[key] = value; + modifiers[key] = value; } else { - context[dkg.name] = dkg.curie; + modifiers[dkg.name] = dkg.curie; } }); - return context; + return modifiers; } // Takes in 2 lists of generic {id, groundings} and returns the singular @@ -371,9 +371,9 @@ export { getNameOfCurieCached, getCurieFromGroundingIdentifier, getDKGFromGroundingIdentifier, - getDKGFromGroundingContext, + getDKGFromGroundingModifier, parseCurieToIdentifier, - parseListDKGToGroundingContext, + parseListDKGToGroundingModifiers, autoModelMapping, autoCalibrationMapping, autoEntityMapping, diff --git a/packages/client/hmi-client/src/types/Types.ts b/packages/client/hmi-client/src/types/Types.ts index 3b2b12ca6f..a8a0f9fbaf 100644 --- a/packages/client/hmi-client/src/types/Types.ts +++ b/packages/client/hmi-client/src/types/Types.ts @@ -124,7 +124,6 @@ export interface CsvAsset { export interface Grounding extends TerariumEntity { identifiers: { [index: string]: string }; - context?: { [index: string]: string }; modifiers?: { [index: string]: string }; } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/Grounding.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/Grounding.java index 161c4085f4..8597b41759 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/Grounding.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/Grounding.java @@ -33,12 +33,6 @@ public class Grounding extends TerariumEntity { @Column(columnDefinition = "json") private Map identifiers; - /** (Optional) Additional context that informs the grounding */ - @TSOptional - @Type(JsonType.class) - @Column(columnDefinition = "json") - private Map context; - /** (Optional) Additional stratification modifiers */ @TSOptional @Type(JsonType.class) @@ -48,7 +42,6 @@ public class Grounding extends TerariumEntity { /** Default constructor */ public Grounding() { this.identifiers = new HashMap<>(); - this.context = new HashMap<>(); this.modifiers = new HashMap<>(); } @@ -57,7 +50,6 @@ public Grounding(DKG dkg) { this.identifiers = new HashMap<>(); final String[] curie = dkg.getCurie().split(":"); this.identifiers.put(curie[0], curie[1]); - this.context = new HashMap<>(); this.modifiers = new HashMap<>(); } @@ -69,10 +61,6 @@ public Grounding clone() { clone.identifiers = new HashMap<>(); clone.identifiers.putAll(this.identifiers); } - if (this.context != null && !this.context.isEmpty()) { - clone.context = new HashMap<>(); - clone.context.putAll(this.context); - } if (this.modifiers != null && !this.modifiers.isEmpty()) { clone.modifiers = new HashMap<>(); clone.modifiers.putAll(this.modifiers); @@ -83,6 +71,6 @@ public Grounding clone() { @TSIgnore public Boolean isEmpty() { - return this.identifiers.isEmpty() && this.context.isEmpty() && this.modifiers.isEmpty(); + return this.identifiers.isEmpty() && this.modifiers.isEmpty(); } } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java index 049d0deb9a..c697a63cdb 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java @@ -213,7 +213,7 @@ public static void getCuratedGrounding(List parts) { part.setGrounding(curatedGrounding); } else { newGrounding.setIdentifiers(curatedGrounding.getIdentifiers()); - newGrounding.setContext(curatedGrounding.getContext()); + newGrounding.setModifiers(curatedGrounding.getModifiers()); part.setGrounding(newGrounding); } } diff --git a/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/DatasetServiceTests.java b/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/DatasetServiceTests.java index d785b1fabc..9fb272f11c 100644 --- a/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/DatasetServiceTests.java +++ b/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/DatasetServiceTests.java @@ -60,7 +60,7 @@ static Grounding createGrounding(final String key) { final Map context = new HashMap<>(); context.put("hello", "world-" + key); context.put("foo", "bar-" + key); - grounding.setContext(context); + grounding.setModifiers(context); return grounding; } @@ -116,16 +116,16 @@ public void testItCanCreateDataset() throws Exception { Assertions.assertNotNull(col.getGrounding().getCreatedOn()); Assertions.assertNotNull(col.getGrounding().getIdentifiers()); Assertions.assertEquals(col.getGrounding().getIdentifiers().size(), 1); - Assertions.assertNotNull(col.getGrounding().getContext()); - Assertions.assertEquals(col.getGrounding().getContext().size(), 2); + Assertions.assertNotNull(col.getGrounding().getModifiers()); + Assertions.assertEquals(col.getGrounding().getModifiers().size(), 2); } Assertions.assertNotNull(after.getGrounding()); Assertions.assertNotNull(after.getGrounding().getId()); Assertions.assertNotNull(after.getGrounding().getCreatedOn()); Assertions.assertNotNull(after.getGrounding().getIdentifiers()); - Assertions.assertNotNull(after.getGrounding().getContext()); - Assertions.assertEquals(after.getGrounding().getContext().size(), 2); + Assertions.assertNotNull(after.getGrounding().getModifiers()); + Assertions.assertEquals(after.getGrounding().getModifiers().size(), 2); } @Test @@ -165,8 +165,8 @@ public void testItCanCreateDatasetAndAddColumnsLater() throws Exception { Assertions.assertNotNull(col.getGrounding().getCreatedOn()); Assertions.assertNotNull(col.getGrounding().getIdentifiers()); Assertions.assertEquals(col.getGrounding().getIdentifiers().size(), 1); - Assertions.assertNotNull(col.getGrounding().getContext()); - Assertions.assertEquals(col.getGrounding().getContext().size(), 2); + Assertions.assertNotNull(col.getGrounding().getModifiers()); + Assertions.assertEquals(col.getGrounding().getModifiers().size(), 2); } } @@ -248,7 +248,7 @@ public void testItCanCloneDataset() throws Exception { Assertions.assertNotEquals(dataset.getId(), cloned.getId()); Assertions.assertEquals(dataset.getGrounding().getIdentifiers(), cloned.getGrounding().getIdentifiers()); - Assertions.assertEquals(dataset.getGrounding().getContext(), cloned.getGrounding().getContext()); + Assertions.assertEquals(dataset.getGrounding().getModifiers(), cloned.getGrounding().getModifiers()); Assertions.assertEquals(dataset.getColumns().size(), cloned.getColumns().size()); for (int i = 0; i < dataset.getColumns().size(); i++) { Assertions.assertEquals(dataset.getColumns().get(i).getName(), cloned.getColumns().get(i).getName()); @@ -267,8 +267,8 @@ public void testItCanCloneDataset() throws Exception { cloned.getColumns().get(i).getGrounding().getIdentifiers() ); Assertions.assertEquals( - dataset.getColumns().get(i).getGrounding().getContext(), - cloned.getColumns().get(i).getGrounding().getContext() + dataset.getColumns().get(i).getGrounding().getModifiers(), + cloned.getColumns().get(i).getGrounding().getModifiers() ); } } diff --git a/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/DocumentServiceTests.java b/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/DocumentServiceTests.java index 9a058e8d28..ee1717a264 100644 --- a/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/DocumentServiceTests.java +++ b/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/DocumentServiceTests.java @@ -55,10 +55,10 @@ public void teardown() throws IOException { static Grounding createGrounding(final String key) { final DKG dkg = new DKG("curie:test", "maria", "", null, null); final Grounding grounding = new Grounding(dkg); - final Map context = new HashMap<>(); - context.put("hello", "world-" + key); - context.put("foo", "bar-" + key); - grounding.setContext(context); + final Map modifiers = new HashMap<>(); + modifiers.put("hello", "world-" + key); + modifiers.put("foo", "bar-" + key); + grounding.setModifiers(modifiers); return grounding; } @@ -101,8 +101,8 @@ public void testItCanCreateDocument() throws Exception { Assertions.assertNotNull(after.getGrounding().getId()); Assertions.assertNotNull(after.getGrounding().getCreatedOn()); Assertions.assertNotNull(after.getGrounding().getIdentifiers()); - Assertions.assertNotNull(after.getGrounding().getContext()); - Assertions.assertEquals(after.getGrounding().getContext().size(), 2); + Assertions.assertNotNull(after.getGrounding().getModifiers()); + Assertions.assertEquals(after.getGrounding().getModifiers().size(), 2); } @Test @@ -200,6 +200,6 @@ public void testItCanCloneDocumentAsset() throws Exception { Assertions.assertNotEquals(documentAsset.getId(), cloned.getId()); Assertions.assertEquals(documentAsset.getGrounding().getIdentifiers(), cloned.getGrounding().getIdentifiers()); - Assertions.assertEquals(documentAsset.getGrounding().getContext(), cloned.getGrounding().getContext()); + Assertions.assertEquals(documentAsset.getGrounding().getModifiers(), cloned.getGrounding().getModifiers()); } } diff --git a/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/TerariumAssetCloneServiceTests.java b/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/TerariumAssetCloneServiceTests.java index a05187a231..a7bf08f189 100644 --- a/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/TerariumAssetCloneServiceTests.java +++ b/packages/server/src/test/java/software/uncharted/terarium/hmiserver/service/data/TerariumAssetCloneServiceTests.java @@ -72,10 +72,10 @@ public void teardown() throws IOException { static Grounding createGrounding(final String key) { final DKG dkg = new DKG("curie:test", "maria", "", null, null); final Grounding grounding = new Grounding(dkg); - final Map context = new HashMap<>(); - context.put("hello", "world-" + key); - context.put("foo", "bar-" + key); - grounding.setContext(context); + final Map modifiers = new HashMap<>(); + modifiers.put("hello", "world-" + key); + modifiers.put("foo", "bar-" + key); + grounding.setModifiers(modifiers); return grounding; } From 6a5d7c37ba2916108bce5eb15613efd472400af0 Mon Sep 17 00:00:00 2001 From: dvince Date: Wed, 5 Feb 2025 14:46:30 -0500 Subject: [PATCH 2/5] [TASK]: Grounding extra concept to be updated #6436 Using the `modifiers` instead of `context` --- .../hmi-client/src/components/widgets/tera-concept.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/client/hmi-client/src/components/widgets/tera-concept.vue b/packages/client/hmi-client/src/components/widgets/tera-concept.vue index 4708f330c1..bc6aa55be2 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-concept.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-concept.vue @@ -48,14 +48,14 @@ function saveConcepts() { if (!isEmpty(concepts.value)) { // Split the list of concepts into identifier (first item) and context (rest of the items) - const [identifierConcept, ...contextConcepts] = concepts.value; + const [identifierConcept, ...modifiersConcepts] = concepts.value; if (identifierConcept) { newGrounding.identifiers = parseCurieToIdentifier(identifierConcept.curie); } - if (!isEmpty(contextConcepts)) { - newGrounding.modifiers = parseListDKGToGroundingModifiers(contextConcepts); + if (!isEmpty(modifiersConcepts)) { + newGrounding.modifiers = parseListDKGToGroundingModifiers(modifiersConcepts); } } From 67a8ba780bb91655a13e9308714bad1a5ffa49fc Mon Sep 17 00:00:00 2001 From: Yohann Paris Date: Thu, 6 Feb 2025 15:26:54 -0500 Subject: [PATCH 3/5] Update tera-concept.vue --- .../client/hmi-client/src/components/widgets/tera-concept.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/hmi-client/src/components/widgets/tera-concept.vue b/packages/client/hmi-client/src/components/widgets/tera-concept.vue index bc6aa55be2..4f87c02422 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-concept.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-concept.vue @@ -85,7 +85,7 @@ watch( }); } - // Then add the context concepts + // Then add the modifiers concepts if (!isEmpty(newGrounding.modifiers)) { getDKGFromGroundingModifier(newGrounding.modifiers).then((dkgList) => { concepts.value.push(...dkgList); From a42db05580e3c8161d46f62561de14a090add0e6 Mon Sep 17 00:00:00 2001 From: Yohann Paris Date: Thu, 6 Feb 2025 16:21:57 -0500 Subject: [PATCH 4/5] stop displaying strata --- .../client/hmi-client/src/services/concept.ts | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/packages/client/hmi-client/src/services/concept.ts b/packages/client/hmi-client/src/services/concept.ts index 624c593c91..3074fd1d08 100644 --- a/packages/client/hmi-client/src/services/concept.ts +++ b/packages/client/hmi-client/src/services/concept.ts @@ -83,32 +83,18 @@ async function getDKGFromGroundingIdentifier(identifier: Object): Promise { } async function getDKGFromGroundingModifier(modifiers: Grounding['modifiers']): Promise { - let dkgList: DKG[] = []; - if (!isEmpty(modifiers)) { - Object.entries(modifiers).forEach(([key, value]) => { - const dkg: DKG = { name: '', curie: '', description: '' }; + if (isEmpty(modifiers)) return [] as DKG[]; - // Test if the value is a curie or a string - if (value.includes(':')) { - dkg.curie = value; - dkg.name = key; - } else { - dkg.name = `${key}: ${value}`; - } - dkgList.push(dkg); - }); - - // Resolve the name of curies properly - dkgList = await Promise.all( - dkgList.map(async (dkg) => { - if (isEmpty(dkg.curie)) return dkg; - const newName = await getNameOfCurieCached(dkg.curie); + return Promise.all( + Object.entries(modifiers) + .filter(([_key, value]) => value.includes(':')) // Test if the value is a curie or a string + .map(async ([key, value]) => { + const dkg: DKG = { name: key, curie: value, description: '' }; + const newName = await getNameOfCurieCached(dkg.curie); // Resolve the name of curies properly if (!isEmpty(newName)) dkg.name = newName; return dkg; }) - ); - } - return dkgList; + ); } function parseCurieToIdentifier(curie: string | undefined): { [key: string]: string } { From aea20c73a4b9282d8480a3fddef960efecb7a3a4 Mon Sep 17 00:00:00 2001 From: Yohann Paris Date: Tue, 11 Feb 2025 14:01:28 -0500 Subject: [PATCH 5/5] Update tera-concept.vue --- .../hmi-client/src/components/widgets/tera-concept.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/client/hmi-client/src/components/widgets/tera-concept.vue b/packages/client/hmi-client/src/components/widgets/tera-concept.vue index 4f87c02422..edf1402927 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-concept.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-concept.vue @@ -56,6 +56,16 @@ function saveConcepts() { if (!isEmpty(modifiersConcepts)) { newGrounding.modifiers = parseListDKGToGroundingModifiers(modifiersConcepts); + + if (grounding.value?.modifiers) { + // Remove the curie modifiers from the original list of modifiers + const nonCurieModifiers = Object.fromEntries( + Object.entries(grounding.value.modifiers).filter(([_key, value]) => !value.includes(':')) + ); + + // Add the original list of non-curie modifiers to the new modifiers + Object.assign(newGrounding.modifiers, nonCurieModifiers); + } } }