This file contains hidden or 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
function personTemplate(person) { | |
const { first_name, last_name, phone_number, city, age } = person; | |
// insert person | |
let graqlInsertQuery = `insert $person isa person has phone-number "${phone_number}"`; | |
const isNotCustomer = typeof first_name === "undefined"; | |
if (isNotCustomer) { | |
// person is not a customer | |
graqlInsertQuery += " has is-customer false"; |
This file contains hidden or 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
function contractTemplate(contract) { | |
const { company_name, person_id } = contract; | |
// match company | |
let graqlInsertQuery = `match $company isa company has name "${company_name}"; `; | |
// match person | |
graqlInsertQuery += `$customer isa person has phone-number "${person_id}"; `; | |
// insert contract | |
graqlInsertQuery += | |
"insert (provider: $company, customer: $customer) isa contract;"; | |
return graqlInsertQuery; |
This file contains hidden or 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
function callTemplate(call) { | |
const { caller_id, callee_id, started_at, duration } = call; | |
// match caller | |
let graqlInsertQuery = `match $caller isa person has phone-number "${caller_id}"; `; | |
// match callee | |
graqlInsertQuery += `$callee isa person has phone-number "${callee_id}"; `; | |
// insert call |
This file contains hidden or 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
function parseDataToObjects(input) { | |
const items = []; | |
return new Promise(function(resolve, reject) { | |
papa.parse( | |
fs.createReadStream(input.dataPath + ".csv"), | |
{ | |
header: true, // a Papaparse config option | |
step: function(result, parser) { | |
items.push(result.data[0]); |
This file contains hidden or 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
function parseDataToObjects(input) { | |
const items = []; | |
return new Promise(function(resolve, reject) { | |
const pipeline = chain([ | |
fs.createReadStream(input.dataPath + ".json"), | |
parser(), | |
streamArray() | |
]); | |
pipeline.on("data", function(result) { |
This file contains hidden or 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
function parseDataToObjects(input) { | |
const items = []; | |
return new Promise((resolve, reject) => { | |
const pipeline = new xmlStream( | |
fs.createReadStream(input.dataPath + ".xml") | |
); | |
pipeline.on(`endElement: ${input.selector}`, function(result) { | |
items.push(result); | |
}); |
This file contains hidden or 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
const Grakn = require("grakn"); | |
const fs = require("fs"); | |
... |
This file contains hidden or 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
const Grakn = require("grakn"); | |
const fs = require("fs"); | |
const papa = require("papaparse"); | |
... |
This file contains hidden or 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
const Grakn = require("grakn"); | |
const fs = require("fs"); | |
const { parser } = require("stream-json"); | |
const { streamArray } = require("stream-json/streamers/StreamArray"); | |
const { chain } = require("stream-chain"); | |
... |
This file contains hidden or 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
const Grakn = require("grakn"); | |
const fs = require("fs"); | |
const xmlStream = require("xml-stream"); | |
... |