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

Ts/2509 task update entity similarity api #2791

Merged
merged 8 commits into from
Feb 22, 2024
27 changes: 18 additions & 9 deletions packages/client/hmi-client/src/services/calibrate-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const autoCalibrationMapping = async (
const result = [] as CalibrateMap[];
const allModelGroundings: string[] = [];
const allDataGroundings: string[] = [];
const acceptableDistance = 0.7;
const acceptableDistance = 0.5;
// Get all model groundings
modelOptions.forEach((state) => {
if (state.grounding?.identifiers) {
Expand All @@ -135,31 +135,40 @@ export const autoCalibrationMapping = async (
});
// Get all data column groundings
datasetOptions.forEach((col) => {
const dataGroundingList = Object.keys(col.metadata?.groundings?.identifiers);
dataGroundingList.forEach((ele) => allDataGroundings.push(ele));
if (col.metadata?.groundings?.identifiers) {
Object.entries(col.metadata?.groundings?.identifiers)
.map((ele) => ele.join(':'))
.forEach((ele) => allDataGroundings.push(ele));
}
});

// take out duplicates:
const distinctModelGroundings = [...new Set(allModelGroundings)];
const distinctDataGroundings = [...new Set(allDataGroundings)];
const allSimilarity = await getEntitySimilarity(distinctModelGroundings, distinctDataGroundings);
if (!allSimilarity) return result;

const filteredSim = allSimilarity.filter((ele) => ele.distance < acceptableDistance);
// normalized cosine similarities
Tom-Szendrey marked this conversation as resolved.
Show resolved Hide resolved
const filteredSim = allSimilarity.filter((ele) => ele.similarity > acceptableDistance);
filteredSim.forEach((sim) => {
// Find all states assosiated with this sim
const validStates = modelOptions.filter((state) => {
if (state.grounding?.identifiers) {
const modelTemp = Object.entries(state.grounding?.identifiers);
const modelGroundingList = modelTemp.map((ele) => ele.join(':'));
const modelGroundingList = Object.entries(state.grounding?.identifiers).map((ele) =>
ele.join(':')
);
return modelGroundingList.includes(sim.source);
}
return false;
});
// Find all columns assosiated with this sim
const validCols = datasetOptions.filter((col) => {
const dataGroundingList = Object.keys(col.metadata?.groundings?.identifiers);
return dataGroundingList.includes(sim.target);
if (col.metadata?.groundings?.identifiers) {
const dataGroundingList = Object.entries(col.metadata?.groundings?.identifiers).map((ele) =>
ele.join(':')
);
return dataGroundingList.includes(sim.target);
}
return false;
});
// For all states and columns that have short distances throw them into results
validStates.forEach((state) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ export interface DKG {
export interface EntitySimilarityResult {
source: string;
target: string;
distance: number;
similarity: number;
}

export interface PermissionGroup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
public class EntitySimilarityResult {
private String source;
private String target;
private Float distance;
private Float similarity;
}
Loading