Last active
May 25, 2019 22:16
-
-
Save scastrec/db57574c5ef5022a4d149de9abec68ff to your computer and use it in GitHub Desktop.
A simple script to create simple entities for Dialogflow from json source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Waiting input: | |
* @param : json filename | |
* @param : json key for entities | |
*/ | |
var fs = require('fs'); | |
//var file = fs.readFileSync('data/' + argv.file, 'utf8'); | |
const file = process.argv[2]; | |
const key = process.argv[3]; | |
const reduce = function reduce(data, key){ | |
let res = []; | |
let map = {}; | |
data.forEach(element => { | |
if(!map[element.name]){ | |
map[element.name] = true; | |
res.push({ | |
value: element.name, | |
synonyms: [ | |
element.name | |
] | |
}); | |
} | |
}); | |
return res; | |
} | |
// load json file | |
let rawdata = fs.readFileSync(file); | |
let json = JSON.parse(rawdata); | |
let result = reduce(json, key); | |
console.log(result); | |
// write file | |
fs.writeFileSync('entities-'+key+'.json', JSON.stringify(result)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment