Skip to content

Commit

Permalink
fix import, re #10780
Browse files Browse the repository at this point in the history
  • Loading branch information
whatisgalen committed Aug 7, 2024
1 parent 8ac98b2 commit 3d7545c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define([
'bindings/datatable',
'bindings/dropzone',
'bindings/resizable-sidepanel',
], function(ko, koMapping, $, dropzone, fuzzyset, uuid, arches, JsonErrorAlertViewModel, importSingleCSVTemplate) {
], function(ko, koMapping, $, dropzone, FuzzySet, uuid, arches, JsonErrorAlertViewModel, importSingleCSVTemplate) {
const viewModel = function(params) {
const self = this;
this.loadDetails = params.load_details || ko.observable();
Expand Down Expand Up @@ -63,19 +63,26 @@ define([
let highestScore = 0;
if (!!self.headers() && self.headers()[i] != 'resourceid') {
const header = normalizeText(self.headers()[i]);
const fuzzySet = FuzzySet();
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;
}
fuzzySet.add(nameNorm);
fuzzySet.add(aliasNorm);
}
});
const results = fuzzySet.get(header);
if (results) {
const [bestScore, bestMatchName] = results[0]; // results are sorted by score
if (bestScore > highestScore) {
highestScore = bestScore;
bestMatch = self.nodes().find(node =>
normalizeText(node.name) === bestMatchName ||
normalizeText(node.alias) === bestMatchName
);
}
}
if (bestMatch && highestScore > 0.8) { return bestMatch.alias; }
}
return null;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"requirejs-plugins": "1.0.2",
"requirejs-text": "~2.0.16",
"select-woo": "jadu/selectWoo",
"string-similarity": "4.0.4",
"fuzzyset": "1.0.7",
"underscore": "^1.13.6",
"uuidjs": "^3.3.0",
"vue": "^3.4.21",
Expand Down Expand Up @@ -110,6 +110,7 @@
"jquery-validate": "node_modules/jquery-validation/dist/jquery.validate.min",
"d3": "node_modules/d3/src/index.js",
"dropzone": "node_modules/dropzone/dist/min/dropzone-amd-module.min",
"fuzzyset": "node_modules/fuzzyset/dist/fuzzyset.esm",
"ckeditor4": "node_modules/ckeditor4/ckeditor",
"ckeditor-jquery": "node_modules/ckeditor4/adapters/jquery",
"knockout": "node_modules/knockout/build/output/knockout-latest",
Expand Down

0 comments on commit 3d7545c

Please sign in to comment.