Loading data into a Grakn Knowledge Graph using the Java client

Soroush Saffari
Oct 31, 2018 · 7 min read

This tutorial may be out of date against the latest version of Grakn. For the most up-to-date version of this tutorial, please refer to the Grakn Documentation.

A Quick Look into the phone_calls Schema

The visualised schema for the phone_calls knowledge graph: blue nodes are attributes, red nodes are entities and the green nodes are relationships

Migrate Data into Grakn

Getting Started

Create a new Maven project

Set Grakn as a dependency

pom.xml to include Grakn as a dependency

Configure logging

Create the Migration Class

Including the Data Files

Specifying details for each data file

Input instance for a Company

{ name: "Telecom" }
insert $company isa company has name "Telecom";

Input instance for a Person

{ phone_number: "+44 091 xxx" }
insert $person has phone-number "+44 091 xxx";
{ firs-name: "Jackie", last-name: "Joe", city: "Jimo", age: 77, phone_number: "+00 091 xxx"}
insert $person has phone-number "+44 091 xxx" has first-name "Jackie" has last-name "Joe" has city "Jimo" has age 77;

Input instance for a Contract

{ company_name: "Telecom", person_id: "+00 091 xxx" }
match $company isa company has name "Telecom"; $customer isa person has phone-number "+00 091 xxx"; insert (provider: $company, customer: $customer) isa contract;

Input instance for a Call

{ caller_id: "+44 091 xxx", callee_id: "+00 091 xxx", started_at: 2018–08–10T07:57:51, duration: 148 }
match $caller isa person has phone-number "+44 091 xxx"; $callee isa person has phone-number "+00 091 xxx"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018–08–10T07:57:51; $call has duration 148;

Connect and Migrate

Loading the data into phone_calls

DataFormat-specific implementation

Parsing CSV

Reading JSON

Parsing XML

Putting it all together

Time to Load

To Recap



Creators of TypeDB and TypeQL