-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathutil.js
57 lines (54 loc) · 1.32 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const mapOptionToCommand = {
quiet: 'q',
type: 's',
kernel: 't',
degree: 'd',
gamma: 'g',
coef0: 'r',
cost: 'c',
nu: 'n',
epsilon: 'p',
cacheSize: 'm',
tolerance: 'e',
shrinking: 'h',
probabilityEstimates: 'b',
weight: 'w'
};
module.exports = {
getCommand: function getCommand(options) {
var str = '';
var keys = Object.keys(options);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (options[key] == null) continue;
if (mapOptionToCommand[key] == null) throw new Error('Bad option');
if (str) str += ' ';
switch (key) {
case 'probabilityEstimates':
case 'shrinking':
str += `-${mapOptionToCommand[key]} ${options[key] ? 1 : 0}`;
break;
case 'quiet': {
if (options[key]) {
str += `-${mapOptionToCommand[key]} 1`;
}
break;
}
case 'weight': {
const weightKeys = Object.keys(options.weight);
for (let j = 0; j < weightKeys.length; j++) {
if (j !== 0) str += ' ';
str += `-w${weightKeys[j]} ${options.weight[weightKeys[j]]}`;
}
break;
}
default: {
str += `-${mapOptionToCommand[key]} ${options[key]}`;
break;
}
}
}
return str;
}
};