Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK]: Grounding extra concept to be updated #6436 #6443

Merged
merged 17 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand All @@ -44,18 +44,28 @@ async function searchDKG(event: AutoCompleteCompleteEvent) {

const concepts = ref<DKG[]>([]);
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)
const [identifierConcept, ...contextConcepts] = concepts.value;
const [identifierConcept, ...modifiersConcepts] = concepts.value;

if (identifierConcept) {
newGrounding.identifiers = parseCurieToIdentifier(identifierConcept.curie);
}

if (!isEmpty(contextConcepts)) {
newGrounding.context = parseListDKGToGroundingContext(contextConcepts);
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);
}
}
}

Expand Down Expand Up @@ -85,9 +95,9 @@ watch(
});
}

// Then add the context concepts
if (!isEmpty(newGrounding.context)) {
getDKGFromGroundingContext(newGrounding.context).then((dkgList) => {
// Then add the modifiers concepts
if (!isEmpty(newGrounding.modifiers)) {
getDKGFromGroundingModifier(newGrounding.modifiers).then((dkgList) => {
concepts.value.push(...dkgList);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:chart-settings="[...selectedInterventionSettings, ...selectedVariableSettings]"
:are-embed-actions-visible="true"
:placeholder="placeholderText"
:progress="processingMessage"
:processing="processingMessage"
/>
<vega-chart v-if="lossChartSpec" :are-embed-actions-visible="false" :visualization-spec="lossChartSpec" />
</section>
Expand Down
46 changes: 16 additions & 30 deletions packages/client/hmi-client/src/services/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,19 @@ async function getDKGFromGroundingIdentifier(identifier: Object): Promise<DKG> {
return dkg;
}

async function getDKGFromGroundingContext(context: Grounding['context']): Promise<DKG[]> {
let dkgList: DKG[] = [];
if (!isEmpty(context)) {
Object.entries(context).forEach(([key, value]) => {
const dkg: DKG = { name: '', curie: '', description: '' };
async function getDKGFromGroundingModifier(modifiers: Grounding['modifiers']): Promise<DKG[]> {
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 } {
Expand All @@ -126,17 +112,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;
}

/**
Expand Down Expand Up @@ -285,9 +271,9 @@ export {
getNameOfCurieCached,
getCurieFromGroundingIdentifier,
getDKGFromGroundingIdentifier,
getDKGFromGroundingContext,
getDKGFromGroundingModifier,
parseCurieToIdentifier,
parseListDKGToGroundingContext,
parseListDKGToGroundingModifiers,
autoCalibrationMapping,
autoMappingGrounding,
getCompareModelConcepts,
Expand Down
1 change: 0 additions & 1 deletion packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export interface CsvAsset {

export interface Grounding extends TerariumEntity {
identifiers: { [index: string]: string };
context?: { [index: string]: string };
modifiers?: { [index: string]: string };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public class Grounding extends TerariumEntity {
@Column(columnDefinition = "json")
private Map<String, String> identifiers;

/** (Optional) Additional context that informs the grounding */
@TSOptional
@Type(JsonType.class)
@Column(columnDefinition = "json")
private Map<String, String> context;

/** (Optional) Additional stratification modifiers */
@TSOptional
@Type(JsonType.class)
Expand All @@ -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<>();
}

Expand All @@ -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<>();
}

Expand All @@ -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);
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static void getCuratedGrounding(List<? extends GroundedSemantic> parts) {
part.setGrounding(curatedGrounding);
} else {
newGrounding.setIdentifiers(curatedGrounding.getIdentifiers());
newGrounding.setContext(curatedGrounding.getContext());
newGrounding.setModifiers(curatedGrounding.getModifiers());
part.setGrounding(newGrounding);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static Grounding createGrounding(final String key) {
final Map<String, String> context = new HashMap<>();
context.put("hello", "world-" + key);
context.put("foo", "bar-" + key);
grounding.setContext(context);
grounding.setModifiers(context);
return grounding;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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());
Expand All @@ -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()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> context = new HashMap<>();
context.put("hello", "world-" + key);
context.put("foo", "bar-" + key);
grounding.setContext(context);
final Map<String, String> modifiers = new HashMap<>();
modifiers.put("hello", "world-" + key);
modifiers.put("foo", "bar-" + key);
grounding.setModifiers(modifiers);
return grounding;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> context = new HashMap<>();
context.put("hello", "world-" + key);
context.put("foo", "bar-" + key);
grounding.setContext(context);
final Map<String, String> modifiers = new HashMap<>();
modifiers.put("hello", "world-" + key);
modifiers.put("foo", "bar-" + key);
grounding.setModifiers(modifiers);
return grounding;
}

Expand Down
Loading