// Create a new db and fill it with the CISP info // TODO: remove this step and create a persistent DB object // Using lokiJS, because it is enough and fast var db = new loki('db.json'); // CISP database collection var cisp = db.addCollection('cisp2db'); cisp.ensureUniqueIndex("Description"); cisp.ensureUniqueIndex("Code"); // Legal words database collection var words = db.addCollection('vocabulaire2db'); words.ensureUniqueIndex("Word"); function extractWords (a) { console.log("Done extracting words"); // Array of obj -> Array of arrays var r = a.map(function (o) { return [ o.Code, o.Description ]; }); // Array of arrays -> Array of words r = r.reduce(function (pv,cv,i,a) { return cv.concat(pv); },[]); // Array of words -> Array of objs { 'Words': … } return r.map(function (w) { return { 'Word': w }; }); } // Download CSV file in the background $.ajax({ url: "./cisp2fr.csv", async: true, success: function (csvd) { var o = $.csv.toObjects(csvd); cisp.insert(o); words.insert(extractWords(o)); }, dataType: "text", complete: function () { main(); } }); function displayMany (a) { var out = a.map(function (o) { var d = cisp.by("Description", o.Word); var ds = d ? "
Code | "; table += "Description | "; table += "Thème | "; table += "Catégorie | "; table += "
---|