{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "⊕ [Migrating CSV, JSON and XML Data with Client Python | GRAKN.AI](https://dev.grakn.ai/docs/examples/phone-calls-migration-python)\n",
    "\n",
    "⊕ [Cannot create Grakn Table · Issue #4 · RasaHQ/tutorial-knowledge-base](https://github.com/RasaHQ/tutorial-knowledge-base/issues/4)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-19T11:26:14.825351Z",
     "start_time": "2019-11-19T11:26:10.703466Z"
    }
   },
   "outputs": [],
   "source": [
    "from grakn.client import GraknClient\n",
    "with GraknClient(uri=\"sagas:48555\") as client:\n",
    "    client.keyspaces().delete(\"phone_calls\")\n",
    "\n",
    "# $ grakn console --keyspace phone_calls --file files/phone-calls/schema.gql"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-19T11:34:49.564983Z",
     "start_time": "2019-11-19T11:34:49.541690Z"
    }
   },
   "outputs": [],
   "source": [
    "from grakn.client import GraknClient\n",
    "import csv\n",
    "\n",
    "def build_phone_call_graph(inputs):\n",
    "    with GraknClient(uri=\"sagas:48555\") as client:\n",
    "        with client.session(keyspace = \"phone_calls\") as session:\n",
    "            for input in inputs:\n",
    "                print(\"Loading from [\" + input[\"data_path\"] + \"] into Grakn ...\")\n",
    "                load_data_into_grakn(input, session)\n",
    "\n",
    "def load_data_into_grakn(input, session):\n",
    "    items = parse_data_to_dictionaries(input)\n",
    "\n",
    "    for item in items:\n",
    "        with session.transaction().write() as transaction:\n",
    "            graql_insert_query = input[\"template\"](item)\n",
    "            print(\"Executing Graql Query: \" + graql_insert_query)\n",
    "            transaction.query(graql_insert_query)\n",
    "            transaction.commit()\n",
    "\n",
    "    print(\"\\nInserted \" + str(len(items)) + \" items from [ \" + input[\"data_path\"] + \"] into Grakn.\\n\")\n",
    "\n",
    "def company_template(company):\n",
    "    return 'insert $company isa company, has name \"' + company[\"name\"] + '\";'\n",
    "\n",
    "def person_template(person):\n",
    "    # insert person\n",
    "    graql_insert_query = 'insert $person isa person, has phone-number \"' + person[\"phone_number\"] + '\"'\n",
    "    if person[\"first_name\"] == \"\":\n",
    "        # person is not a customer\n",
    "        graql_insert_query += \", has is-customer false\"\n",
    "    else:\n",
    "        # person is a customer\n",
    "        graql_insert_query += \", has is-customer true\"\n",
    "        graql_insert_query += ', has first-name \"' + person[\"first_name\"] + '\"'\n",
    "        graql_insert_query += ', has last-name \"' + person[\"last_name\"] + '\"'\n",
    "        graql_insert_query += ', has city \"' + person[\"city\"] + '\"'\n",
    "        graql_insert_query += \", has age \" + str(person[\"age\"])\n",
    "    graql_insert_query += \";\"\n",
    "    return graql_insert_query\n",
    "\n",
    "def contract_template(contract):\n",
    "    # match company\n",
    "    graql_insert_query = 'match $company isa company, has name \"' + contract[\"company_name\"] + '\";'\n",
    "    # match person\n",
    "    graql_insert_query += ' $customer isa person, has phone-number \"' + contract[\"person_id\"] + '\";'\n",
    "    # insert contract\n",
    "    graql_insert_query += \" insert (provider: $company, customer: $customer) isa contract;\"\n",
    "    return graql_insert_query\n",
    "\n",
    "def call_template(call):\n",
    "    # match caller\n",
    "    graql_insert_query = 'match $caller isa person, has phone-number \"' + call[\"caller_id\"] + '\";'\n",
    "    # match callee\n",
    "    graql_insert_query += ' $callee isa person, has phone-number \"' + call[\"callee_id\"] + '\";'\n",
    "    # insert call\n",
    "    graql_insert_query += (\" insert $call(caller: $caller, callee: $callee) isa call; \" +\n",
    "                           \"$call has started-at \" + call[\"started_at\"] + \"; \" +\n",
    "                           \"$call has duration \" + str(call[\"duration\"]) + \";\")\n",
    "    return graql_insert_query\n",
    "\n",
    "def parse_data_to_dictionaries(input):\n",
    "    items = []\n",
    "    with open(input[\"data_path\"] + \".csv\") as data: # 1\n",
    "        for row in csv.DictReader(data, skipinitialspace = True):\n",
    "            item = { key: value for key, value in row.items() }\n",
    "            items.append(item) # 2\n",
    "    return items"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-19T11:35:53.474807Z",
     "start_time": "2019-11-19T11:34:52.186413Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading from [files/phone-calls/data/companies] into Grakn ...\n",
      "Executing Graql Query: insert $company isa company, has name \"Telecom\";\n",
      "\n",
      "Inserted 1 items from [ files/phone-calls/data/companies] into Grakn.\n",
      "\n",
      "Loading from [files/phone-calls/data/people] into Grakn ...\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+7 171 898 0853\", has is-customer true, has first-name \"Melli\", has last-name \"Winchcum\", has city \"London\", has age 55;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+370 351 224 5176\", has is-customer true, has first-name \"Celinda\", has last-name \"Bonick\", has city \"London\", has age 52;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+81 308 988 7153\", has is-customer true, has first-name \"Chryste\", has last-name \"Lilywhite\", has city \"London\", has age 66;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+54 398 559 0423\", has is-customer true, has first-name \"D'arcy\", has last-name \"Byfford\", has city \"London\", has age 19;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+7 690 597 4443\", has is-customer true, has first-name \"Xylina\", has last-name \"D'Alesco\", has city \"Cambridge\", has age 51;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+263 498 495 0617\", has is-customer true, has first-name \"Roldan\", has last-name \"Cometti\", has city \"Oxford\", has age 59;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+63 815 962 6097\", has is-customer true, has first-name \"Cob\", has last-name \"Lafflin\", has city \"Cambridge\", has age 56;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+81 746 154 2598\", has is-customer true, has first-name \"Olag\", has last-name \"Heakey\", has city \"London\", has age 45;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+261 860 539 4754\", has is-customer true, has first-name \"Mandie\", has last-name \"Assender\", has city \"London\", has age 18;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+62 107 530 7500\", has is-customer true, has first-name \"Elenore\", has last-name \"Stokey\", has city \"Oxford\", has age 35;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+86 921 547 9004\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+48 894 777 5173\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+86 922 760 0418\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+33 614 339 0298\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+30 419 575 7546\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+7 414 625 3019\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+57 629 420 5680\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+351 515 605 7915\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+36 318 105 5629\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+63 808 497 1769\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+62 533 266 3426\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+351 272 414 6570\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+86 825 153 5518\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+86 202 257 8619\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+27 117 258 4149\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+48 697 447 6933\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+48 195 624 2025\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+1 254 875 4647\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+7 552 196 4096\", has is-customer false;\n",
      "Executing Graql Query: insert $person isa person, has phone-number \"+86 892 682 0628\", has is-customer false;\n",
      "\n",
      "Inserted 30 items from [ files/phone-calls/data/people] into Grakn.\n",
      "\n",
      "Loading from [files/phone-calls/data/contracts] into Grakn ...\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+7 171 898 0853\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+370 351 224 5176\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+81 308 988 7153\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+54 398 559 0423\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+7 690 597 4443\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+263 498 495 0617\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+63 815 962 6097\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+81 746 154 2598\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+261 860 539 4754\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "Executing Graql Query: match $company isa company, has name \"Telecom\"; $customer isa person, has phone-number \"+62 107 530 7500\"; insert (provider: $company, customer: $customer) isa contract;\n",
      "\n",
      "Inserted 10 items from [ files/phone-calls/data/contracts] into Grakn.\n",
      "\n",
      "Loading from [files/phone-calls/data/calls] into Grakn ...\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T22:24:19; $call has duration 122;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T01:34:48; $call has duration 514;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+33 614 339 0298\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T20:21:17; $call has duration 120;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+33 614 339 0298\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T22:10:34; $call has duration 144;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T20:24:59; $call has duration 556;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T22:23:25; $call has duration 336;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+351 272 414 6570\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T05:34:19; $call has duration 405;\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+263 498 495 0617\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T22:58:02; $call has duration 5665;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T08:55:18; $call has duration 822;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+54 398 559 0423\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T09:10:25; $call has duration 8494;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+7 414 625 3019\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T20:31:39; $call has duration 12;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+57 629 420 5680\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T10:47:21; $call has duration 29;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+261 860 539 4754\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T06:21:55; $call has duration 2851;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T03:37:06; $call has duration 573;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+1 254 875 4647\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T08:19:36; $call has duration 66;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+63 815 962 6097\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T19:44:03; $call has duration 3682;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T13:27:42; $call has duration 32;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T00:56:31; $call has duration 1434;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+7 414 625 3019\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T18:47:17; $call has duration 166;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+86 202 257 8619\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T17:27:52; $call has duration 112;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T03:38:09; $call has duration 1142;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+86 202 257 8619\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T14:57:25; $call has duration 1665;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-27T05:08:53; $call has duration 365;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+36 318 105 5629\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T01:44:31; $call has duration 96;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T12:27:48; $call has duration 766;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+27 117 258 4149\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-27T11:28:11; $call has duration 710;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T23:24:30; $call has duration 151;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T14:04:33; $call has duration 5710;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+81 308 988 7153\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T04:12:07; $call has duration 9923;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+261 860 539 4754\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T22:54:31; $call has duration 4264;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T21:17:48; $call has duration 202;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T22:55:06; $call has duration 151;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T10:16:51; $call has duration 2895;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T15:37:45; $call has duration 251;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T11:34:35; $call has duration 139;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+351 272 414 6570\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T03:13:47; $call has duration 140;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+62 107 530 7500\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T19:18:32; $call has duration 3660;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+30 419 575 7546\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T21:42:00; $call has duration 582;\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T01:00:38; $call has duration 141;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T03:16:48; $call has duration 89;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T19:47:20; $call has duration 21;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+48 697 447 6933\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T23:47:19; $call has duration 144;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T04:54:04; $call has duration 163;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+62 533 266 3426\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T02:11:53; $call has duration 2681;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+36 318 105 5629\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T14:14:42; $call has duration 492;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+351 272 414 6570\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-27T04:00:59; $call has duration 384;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+7 414 625 3019\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T05:58:16; $call has duration 2575;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-27T18:02:22; $call has duration 546;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+1 254 875 4647\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T18:41:52; $call has duration 869;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+36 318 105 5629\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T04:41:12; $call has duration 139;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T06:44:17; $call has duration 53;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-27T12:32:32; $call has duration 457;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T03:42:30; $call has duration 157;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T21:20:56; $call has duration 207;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T15:32:57; $call has duration 500;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T23:45:04; $call has duration 30;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T19:17:54; $call has duration 161;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T02:01:08; $call has duration 306;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+57 629 420 5680\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T21:03:04; $call has duration 129;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T07:55:23; $call has duration 594;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T02:24:36; $call has duration 125;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+62 533 266 3426\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T09:21:22; $call has duration 100;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+36 318 105 5629\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T13:00:15; $call has duration 172;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+63 815 962 6097\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T23:11:52; $call has duration 6789;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+48 894 777 5173\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T07:41:23; $call has duration 66;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T17:26:29; $call has duration 950;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+7 414 625 3019\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T23:28:04; $call has duration 144;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+7 171 898 0853\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-27T17:33:06; $call has duration 4868;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+7 171 898 0853\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-15T10:03:34; $call has duration 6298;\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T20:26:23; $call has duration 2606;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-28T05:06:44; $call has duration 886;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+54 398 559 0423\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T04:48:41; $call has duration 3458;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+27 117 258 4149\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T22:32:19; $call has duration 609;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T03:50:51; $call has duration 68;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+351 272 414 6570\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T09:20:33; $call has duration 212;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T16:52:29; $call has duration 156;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T09:21:38; $call has duration 60;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T22:11:35; $call has duration 681;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T15:12:44; $call has duration 124;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T05:39:03; $call has duration 124;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T18:08:42; $call has duration 163;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+1 254 875 4647\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T13:06:40; $call has duration 45;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+62 107 530 7500\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T05:05:43; $call has duration 3924;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T21:40:47; $call has duration 79;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+48 894 777 5173\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T04:16:21; $call has duration 79;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T03:22:12; $call has duration 988;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+86 202 257 8619\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T00:41:44; $call has duration 164;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+48 697 447 6933\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T18:55:03; $call has duration 212;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+30 419 575 7546\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T15:20:43; $call has duration 283;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+7 690 597 4443\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T00:06:19; $call has duration 2357;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+351 272 414 6570\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T13:27:01; $call has duration 157;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+1 254 875 4647\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T07:53:09; $call has duration 295;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+81 746 154 2598\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T07:13:25; $call has duration 9460;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-15T22:08:23; $call has duration 2308;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T02:24:15; $call has duration 1018;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+263 498 495 0617\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T17:22:34; $call has duration 10499;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T18:17:49; $call has duration 47;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T07:29:13; $call has duration 1036;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+81 308 988 7153\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-27T08:22:32; $call has duration 6468;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+33 614 339 0298\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T01:58:04; $call has duration 77;\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+263 498 495 0617\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T23:16:49; $call has duration 2519;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+1 254 875 4647\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-15T07:02:32; $call has duration 914;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+81 308 988 7153\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T04:57:20; $call has duration 4455;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+62 107 530 7500\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-28T01:57:20; $call has duration 5272;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+36 318 105 5629\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-14T17:18:49; $call has duration 1111;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T21:11:41; $call has duration 290;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T22:57:07; $call has duration 169;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+86 825 153 5518\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T19:43:24; $call has duration 276;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+48 894 777 5173\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T14:43:15; $call has duration 4;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T22:48:50; $call has duration 655;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+48 697 447 6933\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T13:54:54; $call has duration 146;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+30 419 575 7546\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T20:34:51; $call has duration 22;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T21:14:56; $call has duration 1177;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+7 690 597 4443\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T21:01:36; $call has duration 6227;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T11:04:36; $call has duration 67;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+1 254 875 4647\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-15T22:31:03; $call has duration 71;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+86 202 257 8619\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T02:01:36; $call has duration 60;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T05:22:05; $call has duration 2544;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+62 107 530 7500\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T18:51:01; $call has duration 7444;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+81 308 988 7153\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T03:49:07; $call has duration 1696;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+54 398 559 0423\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T15:58:58; $call has duration 9465;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+30 419 575 7546\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T17:02:25; $call has duration 442;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+81 746 154 2598\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T16:46:05; $call has duration 3928;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+7 690 597 4443\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T08:11:36; $call has duration 10309;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+62 533 266 3426\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T15:41:04; $call has duration 76;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T01:13:18; $call has duration 997;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+36 318 105 5629\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T08:53:14; $call has duration 90;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T11:47:59; $call has duration 124;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+48 894 777 5173\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-15T21:44:00; $call has duration 1122;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T17:24:29; $call has duration 520;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+62 107 530 7500\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T12:10:49; $call has duration 3251;\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+48 697 447 6933\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-28T08:52:06; $call has duration 599;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T06:03:28; $call has duration 160;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T19:51:51; $call has duration 79;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+7 171 898 0853\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T12:08:28; $call has duration 6538;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T02:19:22; $call has duration 508;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T00:35:41; $call has duration 809;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T15:16:47; $call has duration 2457;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+33 614 339 0298\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T09:48:54; $call has duration 93;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+54 398 559 0423\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T03:19:40; $call has duration 1259;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+81 746 154 2598\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T08:08:28; $call has duration 6475;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-14T22:01:01; $call has duration 547;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+81 746 154 2598\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T20:04:51; $call has duration 4941;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T03:35:49; $call has duration 134;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+7 171 898 0853\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T11:38:53; $call has duration 9705;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+81 746 154 2598\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-28T00:37:16; $call has duration 6945;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T23:25:20; $call has duration 3225;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+62 533 266 3426\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-14T23:33:20; $call has duration 27;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+30 419 575 7546\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T07:52:06; $call has duration 174;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T09:42:58; $call has duration 143;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+63 815 962 6097\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T02:17:35; $call has duration 5413;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+81 308 988 7153\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T06:19:03; $call has duration 3552;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+86 202 257 8619\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T08:28:51; $call has duration 170;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T06:33:20; $call has duration 108;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T10:37:27; $call has duration 556;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+7 414 625 3019\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T11:17:09; $call has duration 1051;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T21:49:34; $call has duration 802;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+62 533 266 3426\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T11:41:10; $call has duration 1903;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+7 414 625 3019\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T15:26:33; $call has duration 175;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+36 318 105 5629\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T06:23:45; $call has duration 166;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+1 254 875 4647\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T04:08:43; $call has duration 501;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T23:50:37; $call has duration 52;\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+30 419 575 7546\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T01:11:29; $call has duration 1959;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+48 697 447 6933\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T18:43:42; $call has duration 29;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T19:07:10; $call has duration 3196;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+86 202 257 8619\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T06:05:16; $call has duration 4362;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+63 815 962 6097\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T16:57:41; $call has duration 4016;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+86 202 257 8619\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T19:45:03; $call has duration 422;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+48 894 777 5173\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T20:00:30; $call has duration 720;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T21:33:26; $call has duration 402;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T06:56:03; $call has duration 44;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-28T09:45:40; $call has duration 78;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-27T13:01:03; $call has duration 113;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+57 629 420 5680\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T12:20:01; $call has duration 128;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+36 318 105 5629\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T08:07:59; $call has duration 1171;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+48 697 447 6933\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T19:41:35; $call has duration 126;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T01:48:26; $call has duration 176;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+261 860 539 4754\"; $callee isa person, has phone-number \"+7 690 597 4443\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-14T23:40:40; $call has duration 4389;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+7 414 625 3019\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-17T23:24:18; $call has duration 2391;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+86 922 760 0418\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-15T04:32:48; $call has duration 44;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+86 825 153 5518\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-28T14:57:53; $call has duration 160;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+63 815 962 6097\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T07:34:42; $call has duration 9303;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 171 898 0853\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T01:37:19; $call has duration 141;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+63 808 497 1769\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-22T08:48:48; $call has duration 83;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+62 533 266 3426\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-15T12:12:59; $call has duration 426;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T14:12:40; $call has duration 51;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+54 398 559 0423\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-21T22:45:47; $call has duration 8861;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+33 614 339 0298\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T22:18:08; $call has duration 162;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+27 117 258 4149\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-25T00:26:05; $call has duration 69;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+263 498 495 0617\"; $callee isa person, has phone-number \"+62 533 266 3426\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T03:03:46; $call has duration 12;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+62 107 530 7500\"; $callee isa person, has phone-number \"+86 892 682 0628\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T14:12:03; $call has duration 68;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+48 195 624 2025\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-26T21:20:35; $call has duration 136;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+86 921 547 9004\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-24T09:38:52; $call has duration 80;\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+1 254 875 4647\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-20T12:02:37; $call has duration 9;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 308 988 7153\"; $callee isa person, has phone-number \"+48 894 777 5173\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-28T06:12:49; $call has duration 156;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+370 351 224 5176\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-16T22:31:25; $call has duration 543;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+7 690 597 4443\"; $callee isa person, has phone-number \"+48 697 447 6933\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T00:12:47; $call has duration 132;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+81 746 154 2598\"; $callee isa person, has phone-number \"+351 515 605 7915\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-19T08:10:14; $call has duration 76;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+54 398 559 0423\"; $callee isa person, has phone-number \"+81 746 154 2598\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-18T22:47:52; $call has duration 5356;\n",
      "Executing Graql Query: match $caller isa person, has phone-number \"+63 815 962 6097\"; $callee isa person, has phone-number \"+7 552 196 4096\"; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018-09-23T01:14:56; $call has duration 53;\n",
      "\n",
      "Inserted 200 items from [ files/phone-calls/data/calls] into Grakn.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "inputs = [\n",
    "    {\n",
    "        \"data_path\": \"files/phone-calls/data/companies\",\n",
    "        \"template\": company_template\n",
    "    },\n",
    "    {\n",
    "        \"data_path\": \"files/phone-calls/data/people\",\n",
    "        \"template\": person_template\n",
    "    },\n",
    "    {\n",
    "        \"data_path\": \"files/phone-calls/data/contracts\",\n",
    "        \"template\": contract_template\n",
    "    },\n",
    "    {\n",
    "        \"data_path\": \"files/phone-calls/data/calls\",\n",
    "        \"template\": call_template\n",
    "    }\n",
    "]\n",
    "\n",
    "build_phone_call_graph(inputs=inputs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-20T15:41:59.841551Z",
     "start_time": "2019-11-20T15:41:58.430555Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Query:\n",
      " match\n",
      "  $customer isa person, has phone-number $phone-number;\n",
      "  $company isa company, has name \"Telecom\";\n",
      "  (customer: $customer, provider: $company) isa contract;\n",
      "  $target isa person, has phone-number \"+86 921 547 9004\";\n",
      "  (caller: $customer, callee: $target) isa call, has started-at $started-at;\n",
      "  $min-date == 2018-09-14T17:18:49; $started-at > $min-date;\n",
      "get $phone-number;\n",
      "\n",
      "Result:\n",
      " ['+370 351 224 5176', '+54 398 559 0423', '+62 107 530 7500', '+7 690 597 4443', '+263 498 495 0617', '+81 308 988 7153', '+81 746 154 2598', '+63 815 962 6097']\n"
     ]
    }
   ],
   "source": [
    "from grakn.client import GraknClient\n",
    "\n",
    "with GraknClient(uri=\"sagas:48555\") as client:\n",
    "    with client.session(keyspace = \"phone_calls\") as session:\n",
    "        with session.transaction().read() as transaction:\n",
    "            query = [\n",
    "                'match',\n",
    "                '  $customer isa person, has phone-number $phone-number;',\n",
    "                '  $company isa company, has name \"Telecom\";',\n",
    "                '  (customer: $customer, provider: $company) isa contract;',\n",
    "                '  $target isa person, has phone-number \"+86 921 547 9004\";',\n",
    "                '  (caller: $customer, callee: $target) isa call, has started-at $started-at;',\n",
    "                '  $min-date == 2018-09-14T17:18:49; $started-at > $min-date;',\n",
    "                'get $phone-number;'\n",
    "            ]\n",
    "\n",
    "            print(\"\\nQuery:\\n\", \"\\n\".join(query))\n",
    "            query = \"\".join(query)\n",
    "\n",
    "            iterator = transaction.query(query)\n",
    "            answers = iterator.collect_concepts()\n",
    "            result = [ answer.value() for answer in answers ]\n",
    "\n",
    "            print(\"\\nResult:\\n\", result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-19T20:19:29.537043Z",
     "start_time": "2019-11-19T20:19:25.748148Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Query:\n",
      " match \n",
      "  $suspect isa person, has city \"London\", has age > 50;\n",
      "  $company isa company, has name \"Telecom\";\n",
      "  (customer: $suspect, provider: $company) isa contract;\n",
      "  $pattern-callee isa person, has age < 20;\n",
      "  (caller: $suspect, callee: $pattern-callee) isa call, has started-at $pattern-call-date;\n",
      "  $target isa person, has phone-number $phone-number, has is-customer false;\n",
      "  (caller: $suspect, callee: $target) isa call, has started-at $target-call-date;\n",
      "  $target-call-date > $pattern-call-date;\n",
      "get $phone-number;\n",
      "\n",
      "Result:\n",
      " ['+86 892 682 0628', '+86 202 257 8619', '+63 808 497 1769', '+86 922 760 0418', '+86 825 153 5518', '+27 117 258 4149', '+48 894 777 5173', '+351 515 605 7915', '+351 272 414 6570', '+30 419 575 7546', '+1 254 875 4647', '+33 614 339 0298']\n"
     ]
    }
   ],
   "source": [
    "with GraknClient(uri=\"sagas:48555\") as client:\n",
    "    with client.session(keyspace = \"phone_calls\") as session:\n",
    "      with session.transaction().read() as transaction:\n",
    "        query = [\n",
    "          'match ',\n",
    "          '  $suspect isa person, has city \"London\", has age > 50;',\n",
    "          '  $company isa company, has name \"Telecom\";',\n",
    "          '  (customer: $suspect, provider: $company) isa contract;',\n",
    "          '  $pattern-callee isa person, has age < 20;',\n",
    "          '  (caller: $suspect, callee: $pattern-callee) isa call, has started-at $pattern-call-date;',\n",
    "          '  $target isa person, has phone-number $phone-number, has is-customer false;',\n",
    "          '  (caller: $suspect, callee: $target) isa call, has started-at $target-call-date;',\n",
    "          '  $target-call-date > $pattern-call-date;',\n",
    "          'get $phone-number;'\n",
    "        ]\n",
    "\n",
    "        print(\"\\nQuery:\\n\", \"\\n\".join(query))\n",
    "        query = \"\".join(query)\n",
    "\n",
    "        iterator = transaction.query(query)\n",
    "        answers = iterator.collect_concepts()\n",
    "        result = [ answer.value() for answer in answers ]\n",
    "\n",
    "        print(\"\\nResult:\\n\", result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-19T20:32:29.893740Z",
     "start_time": "2019-11-19T20:32:29.863439Z"
    }
   },
   "outputs": [],
   "source": [
    "client=GraknClient(uri=\"sagas:48555\")\n",
    "session=client.session(keyspace = \"phone_calls\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-19T20:34:51.391657Z",
     "start_time": "2019-11-19T20:34:49.041179Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Query:\n",
      " match \n",
      "  $suspect isa person, has city \"London\", has age > 50;\n",
      "  $company isa company, has name \"Telecom\";\n",
      "  (customer: $suspect, provider: $company) isa contract;\n",
      "  $pattern-callee isa person, has age < 20;\n",
      "  (caller: $suspect, callee: $pattern-callee) isa call, has started-at $pattern-call-date;\n",
      "  $target isa person, has phone-number $phone-number, has is-customer false;\n",
      "  (caller: $suspect, callee: $target) isa call, has started-at $target-call-date;\n",
      "  $target-call-date > $pattern-call-date;\n",
      "get $phone-number;\n",
      "... get answers\n",
      "\n",
      "Result:\n",
      " ['+351 272 414 6570', '+30 419 575 7546', '+1 254 875 4647', '+33 614 339 0298', '+86 892 682 0628', '+63 808 497 1769', '+86 922 760 0418', '+86 825 153 5518', '+27 117 258 4149', '+48 894 777 5173', '+351 515 605 7915', '+86 202 257 8619']\n"
     ]
    }
   ],
   "source": [
    "with session.transaction().read() as transaction:\n",
    "    query = [\n",
    "      'match ',\n",
    "      '  $suspect isa person, has city \"London\", has age > 50;',\n",
    "      '  $company isa company, has name \"Telecom\";',\n",
    "      '  (customer: $suspect, provider: $company) isa contract;',\n",
    "      '  $pattern-callee isa person, has age < 20;',\n",
    "      '  (caller: $suspect, callee: $pattern-callee) isa call, has started-at $pattern-call-date;',\n",
    "      '  $target isa person, has phone-number $phone-number, has is-customer false;',\n",
    "      '  (caller: $suspect, callee: $target) isa call, has started-at $target-call-date;',\n",
    "      '  $target-call-date > $pattern-call-date;',\n",
    "      'get $phone-number;'\n",
    "    ]\n",
    "\n",
    "    print(\"\\nQuery:\\n\", \"\\n\".join(query))\n",
    "    query = \"\".join(query)\n",
    "\n",
    "    iterator = transaction.query(query)\n",
    "    answers = iterator.collect_concepts()\n",
    "    print('... get answers')\n",
    "    result = [ answer.value() for answer in answers ]\n",
    "\n",
    "    print(\"\\nResult:\\n\", result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
