-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildxvalidset.js
62 lines (45 loc) · 1.48 KB
/
buildxvalidset.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
58
59
60
61
/**
* buildxvalidset.js
* A tool for building data sets for cross validation.
*/
const fs = require("fs");
for(let i = 0; i < 10; i++) {
for(let j = 0; j < 10; j++) {
let lineReader, files = ['candidate', 'mutant', 'nominal'];
/* i selects the set of projects that will be the test set. */
for(let k = 0; k < files.length; k++) process(i, j, files[k]);
}
}
function process(fold, set, file) {
let label, traintest, omitted = 0, skipped = 0,
path = 'output/seq-' + file + set + '.seq',
seqs = fs.readFileSync(path, 'utf-8').split("\n");
if(fold === set) traintest = 'test';
else traintest = 'train';
console.log('Processing ' + traintest + ' file ' + path + ' of fold ' + fold + ' ...');
switch(file){
case 'mutant':
label = 'MISSING_TRY';
break;
case 'candidate':
case 'nominal':
default:
label = 'NOMINAL';
break;
}
for(let i = 0; i < seqs.length; i++) {
if(seqs[i] === '') continue;
if(!(seqs[i].includes('~UPDATED_START') || seqs[i].includes('~INSERTED_START'))) {
omitted++;
}
else if(file !== 'nominal' || Math.round(Math.random() * 100) < 20) {
fs.appendFileSync('xfold/' + traintest + fold + '.input', seqs[i] + '\n');
fs.appendFileSync('xfold/' + traintest + fold + '.expected', label + '\n');
}
else {
skipped++;
}
}
console.log('Omitted ' + omitted + ' sequences with no changes from ' + traintest + ' set.');
console.log('Skipped ' + skipped + ' sequences from ' + traintest + ' set.');
}