Who’s calling? Grakn. Model and Load a schema into a knowledge graph

Soroush Saffari
Sep 26, 2018 · 6 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.

The Dataset

The insights

The Schema

Time to talk Graql

define

contract sub relationship,
relates provider,
relates customer;
call sub relationship,
relates caller,
relates callee;
company sub entity,
plays provider;
person sub entity,
plays customer,
plays caller,
plays callee;
define

contract sub relationship,
relates provider,
relates customer;
call sub relationship,
relates caller,
relates callee,
has started-at,
has duration;
company sub entity,
plays provider,
has name;
person sub entity,
plays customer,
plays caller,
plays callee,
has first-name,
has last-name,
has phone-number,
has city,
has age,
has is-customer;
define

contract sub relationship,
relates provider,
relates customer;
call sub relationship,
relates caller,
relates callee,
has started-at,
has duration;
company sub entity,
plays provider,
has name;
person sub entity,
plays customer,
plays caller,
plays callee,
has first-name,
has last-name,
has phone-number,
has city,
has age,
has is-customer;

name sub attribute datatype string;
started-at sub attribute datatype date;
duration sub attribute datatype long;
first-name sub attribute datatype string;
last-name sub attribute datatype string;
phone-number sub attribute datatype string;
city sub attribute datatype string;
age sub attribute datatype long;
is-customer sub attribute datatype boolean;

Load and test the schema

Schema for phone_calls
./grakn server start
./grakn console --keyspace phone_calls --file path/to/the/schema.gql
./grakn console --keyspace phone_calls
match $x sub thing; get;
{$x label thing;}
{$x label entity;}
{$x label relationship;}
{$x label attribute;}
{$x label company sub entity;}
{$x label person sub entity;}
{$x label call sub relationship;}
{$x label "@has-attribute" sub relationship;}
{$x label contract sub relationship;}
{$x label name sub attribute;}
{$x label started-at sub attribute;}
{$x label age sub attribute;}
{$x label city sub attribute;}
{$x label last-name sub attribute;}
{$x label first-name sub attribute;}
{$x label duration sub attribute;}
{$x label phone-number sub attribute;}
{$x label is-customer sub attribute;}
{$x label "@has-started-at" sub "@has-attribute";}
{$x label "@has-first-name" sub "@has-attribute";}
{$x label "@has-city" sub "@has-attribute";}
{$x label "@has-name" sub "@has-attribute";}
{$x label "@has-duration" sub "@has-attribute";}
{$x label "@has-age" sub "@has-attribute";}
{$x label "@has-last-name" sub "@has-attribute";}
{$x label "@has-phone-number" sub "@has-attribute";}
{$x label "@has-is-customer" sub "@has-attribute";}

To Recap

Next: Migrate data into Grakn and Query for insights

Time to make a choice

Vaticle

Creators of TypeDB and TypeQL