StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
StackGenVis/frontend/node_modules/composer/lib/resolve.js

61 lines
1.4 KiB

4 years ago
'use strict';
var utils = require('./utils');
/**
* Resolve the arguments by looking up tasks and their dependencies.
* This creates an array of composed functions to be run together.
*
* ```js
* // bind the composer to the resolve call
* var tasks = resolve.call(this, arr);
* ```
*
* @param {Array} `arr` flattened array of strings and functions to resolve.
* @return {Array} Return array of composed functions to run.
*/
module.exports = function(arr) {
var len = arr.length, i = 0;
var fns = [];
var options = {};
if (len && utils.isobject(arr[len - 1])) {
options = arr.pop();
len--;
}
while (len--) {
var str = arr[i++];
if (isGlob(str)) {
var obj = utils.mm.matchKeys(this.tasks, str);
var keys = Object.keys(obj);
if (!keys.length) {
throw new Error('glob pattern "' + str + '" did not match any tasks');
}
for (var j = 0; j < keys.length; j++) {
fns.push(getTaskFn(this.tasks, keys[j], options));
}
continue;
}
if (typeof str === 'string') {
str = getTaskFn(this.tasks, str, options);
}
fns.push(str);
}
return fns;
};
var re = /\[anonymous \(\d*\)\]/;
function isGlob(str) {
return utils.isGlob(str) && (!re.test(str));
}
function getTaskFn(tasks, key, options) {
var task = tasks[key];
if (!task) {
throw new Error('task "' + key + '" is not registered');
}
utils.extend(task.options, options);
return task.run.bind(task);
}