forked from radu1690/Explanations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplanations.js
79 lines (64 loc) · 2.06 KB
/
explanations.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var rosaenlgPug = require('rosaenlg');
var pluralize = require('pluralize')
var graph2Object = require("./graphToObject")
var language// = 'en'; //en or it
var conseq_language// = 'cons_en' //cons_en or cons_it
var rosae_language// = 'en_US' //en_US or it_IT
function random(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min
}
function randomElement(items){
if(Array.isArray(items)){
return items[Math.floor(Math.random()*items.length)]
}else{
return items
}
}
function setLanguage(lang){
language = 'en';
conseq_language = 'cons_en'
rosae_language = 'en_US'
if(lang!=null){
if (!lang.localeCompare('italian')){
language = 'it';
conseq_language = 'cons_it'
rosae_language = 'it_IT'
}else if(lang.localeCompare('english')){
console.log('Language ' + lang + ' is not supported')
console.log("Defualt English set")
}
}
}
function main(){
//arguments: 2: pugTemplate (.pug), 3: explanationGraph (.csv delimiter with ','), 4: language (english or italian, defualt english)
const args = process.argv;
//console.log(args);
var dir_template = args[2];
var dir_explanationGraph = args[3];
const fs = require('fs');
/* try{
var template = fs.readFileSync(dir_template);
}catch(e){
console.log("Template file not found ("+dir_template)+")";
return;
} */
//console.log(explanationGraph);
//console.log(template.toString());
setLanguage(args[4])
graph2Object.main(dir_explanationGraph)
.then(data =>{
var output = rosaenlgPug.renderFile(dir_template, {
language: rosae_language,
explanation: data,
pluralize: pluralize,
random: randomElement
});
//console.log(data)
//console.log(data.entity)
//console.log(data.entity.negative)
//console.log(data.entity.alternatives)
console.log(output)
})
.catch(err => console.error(err))
}
main()