Skip to content

Instantly share code, notes, and snippets.

@sorsaffari
sorsaffari / loadCsvIntoGrakn.js
Last active September 25, 2018 00:53
Loading CSV data into a Grakn keyspace using the Node.js Client
const Grakn = require("grakn");
const fs = require("fs");
const papa = require("papaparse");
const inputs = [
{ dataPath: "./data/companies", template: companyTemplate },
{ dataPath: "./data/people", template: personTemplate },
{ dataPath: "./data/contracts", template: contractTemplate },
{ dataPath: "./data/calls", template: callTemplate }
];
@sorsaffari
sorsaffari / phone_calls_query_1.js
Last active September 21, 2018 09:24
Grakn with Node.js: Match query - example #1
const Grakn = require("grakn");
const grakn = new Grakn("localhost:48555");
const session = grakn.session("phone_calls");
ExecuteMatchQuery();
async function ExecuteMatchQuery() {
const tx = await session.transaction(Grakn.txType.READ);
let query = [
@sorsaffari
sorsaffari / phone_calls_query_2.js
Last active September 21, 2018 12:26
Grakn with Node.js: Match query - example #2
const Grakn = require("grakn");
const grakn = new Grakn("localhost:48555");
const session = grakn.session("phone_calls");
ExecuteMatchQuery();
async function ExecuteMatchQuery() {
const tx = await session.transaction(Grakn.txType.READ);
let query = [
@sorsaffari
sorsaffari / phone_calls_query_3.js
Last active September 21, 2018 09:26
Grakn with Node.js: Match query - example #3
const Grakn = require("grakn");
const grakn = new Grakn("localhost:48555");
const session = grakn.session("phone_calls");
ExecuteMatchQuery();
async function ExecuteMatchQuery() {
const tx = await session.transaction(Grakn.txType.READ);
let query = [
@sorsaffari
sorsaffari / phone_calls_query_4.js
Last active September 21, 2018 09:28
Grakn with Node.js: Match query - example #4
const Grakn = require("grakn");
const grakn = new Grakn("localhost:48555");
const session = grakn.session("phone_calls");
ExecuteMatchQuery();
async function ExecuteMatchQuery() {
const tx = await session.transaction(Grakn.txType.READ);
let query = [
@sorsaffari
sorsaffari / phone_calls_schema.gql
Last active September 25, 2018 15:34
The schema for the phone_calls knowledge graph
define
contract sub relationship,
relates provider,
relates customer;
call sub relationship,
relates caller,
relates callee,
has started-at,
@sorsaffari
sorsaffari / phone_calls_load_data_1.js
Last active September 20, 2018 19:20
Phone Calls | Loading Data: requiring grakn and declaring inputs
const Grakn = require("grakn");
const inputs = [
{
dataPath: "./data/companies",
template: companyTemplate
},
{
dataPath: "./data/people",
template: personTemplate
@sorsaffari
sorsaffari / phone_calls_load_data_2.js
Last active September 20, 2018 19:26
Phone Calls | Loading Data: the main function
async function buildPhoneCallGraph(inputs) {
const grakn = new Grakn("localhost:48555");
const session = grakn.session("phone_calls");
for (input of inputs) {
await loadDataIntoGrakn(parsingInput, session);
}
session.close();
}
@sorsaffari
sorsaffari / phone_calls_load_data_3.js
Created September 14, 2018 10:45
Phone Calls | Loading Data: construct insert query, execute and commit
async function loadDataIntoGrakn(input, session) {
const items = await parseDataToObjects(input);
for (item of items) {
const tx = await session.transaction(Grakn.txType.WRITE);
const graqlInsertQuery = input.template(item);
await tx.query(graqlInsertQuery);
await tx.commit();
}
}
@sorsaffari
sorsaffari / phone_calls_load_data_4.js
Created September 14, 2018 10:48
Phone Calls | Loading Data: template to construct insert query for a company
function companyTemplate(company) {
return `insert $company isa company has name "${company.name}";`;
}