Here is a quick script, that gives all the samples, can go ahead and create the entities needed, alongside the samples on a new app:
const _ = require('lodash');
const fetch = require('node-fetch');
const samples = require('./samples');
const TOKEN = 'CHANGE_ME';
const headers = {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
};
function postEntity(id) {
return fetch(
'https://api.wit.ai/entities?v=20170307',
{
method: 'POST',
headers,
body: JSON.stringify({id}),
}
);
}
function postSamples(samples) {
return fetch(
'https://api.wit.ai/samples?v=20170307',
{
method: 'POST',
headers,
body: JSON.stringify(samples),
}
);
}
function addEntities() {
const ids = new Set(
_.chain(samples).flatMap(s => s.entities).map(e => e.entity).value()
);
[...ids].reduce(
(p, id) => p.then(() => postEntity(id)),
Promise.resolve()
).then(_ => console.log('done!'));
}
function addSamples() {
postSamples(samples).then(
r => console.log('yes!', r),
r => console.log('no!', r)
);
}
// run addEntities() first, to add all entities
// run addSamples() second, to add all samples