Skip to content

Commit

Permalink
creates fn to guess node mapping based on header name comparison, re #…
Browse files Browse the repository at this point in the history
  • Loading branch information
whatisgalen committed Apr 17, 2024
1 parent 8118cc9 commit f046d82
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ define([
this.ready = ko.computed(() => {
return self.selectedGraph() && self.fieldMapping().find((mapping) => mapping.node());
});
this.suggestField = function(i) {
function normalizeText(text) { return text.toLowerCase().replace(/\W+/g, ''); }
let bestMatch = null;
let highestScore = 0;
if (!!self.headers() && self.headers()[i] != 'resourceid') {
const header = normalizeText(self.headers()[i]);
self.nodes().forEach(function(node) {
if (node.name) {
const nameNorm = normalizeText(node.name);
const aliasNorm = normalizeText(node.alias);
const nameScore = stringSimilarity.compareTwoStrings(header, nameNorm);
const aliasScore = stringSimilarity.compareTwoStrings(header, aliasNorm);
const bestNodeScore = Math.max(nameScore, aliasScore);
if (bestNodeScore > highestScore) {
highestScore = bestNodeScore;
bestMatch = node;
}
}
});
if (bestMatch && highestScore > 0.8) { return bestMatch.alias; }
}
return null;
}

this.createTableConfig = function(col) {
return {
Expand Down

0 comments on commit f046d82

Please sign in to comment.