{"size": 1344, "ext": "js", "max_stars_repo_path": "scripts/learn.js", "max_stars_repo_name": "parmentf/node-ector-backend", "max_stars_repo_stars_event_min_datetime": "2020-07-02T16:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-02T16:48:45.000Z", "max_issues_repo_path": "scripts/learn.js", "max_issues_repo_name": "parmentf/node-ector-backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scripts/learn.js", "max_forks_repo_name": "parmentf/node-ector-backend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 36.3243243243, "max_line_length": 338, "alphanum_fraction": 0.619047619}
#!/usr/bin/env node

const fetch = require('node-fetch');
const progress =require('progress-string');
const diff = require('ansi-diff-stream')();

const subjects = ['Agent_conversationnel','Paris', 'Nancy'];
const bar = progress({width: 42, total: subjects.length});
let taught = 0;

const urls = subjects
    .map(subject => `http://fr.dbpedia.org/sparql?query=select+*+%0D%0Awhere+%7B%0D%0A+%3Chttp%3A%2F%2Ffr.dbpedia.org%2Fresource%2F${subject}%3E+%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2Fabstract%3E+%3Fabstract+.%0D%0A+filter%28lang%28%3Fabstract%29+%3D+%27fr%27%29%0D%0A%7D&format=application%2Fsparql-results%2Bjson&timeout=0&debug=on`);
    
const teachAbstract = url => fetch(url)
    .then(response => response.json())
    .then(json => json.results.bindings[0].abstract.value)
    .then(abstract => fetch(`http://localhost:5000/v1/learn/`,
        {
            mode: 'cors',
            method: 'POST',
            body:    JSON.stringify({
                source: 'wikipedia',
                entry: abstract
            }),
            headers: { 'Content-Type': 'application/json' },
        }))
    .then(() => diff.write(`[${bar(++taught)}] (${taught}/${subjects.length})`));


Promise
    .all(urls.map(teachAbstract))
    .then(() => {
        console.log(`subjects taught: ${subjects}`);
    });

diff.pipe(process.stdout);
