Skip to content

Commit bb99d8c

Browse files
committed
Update notebook
1 parent e06db2b commit bb99d8c

File tree

1 file changed

+77
-38
lines changed

1 file changed

+77
-38
lines changed

got-analysis/game-of-graphs.ipynb

+77-38
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,45 @@
1313
"id": "b1358e7b",
1414
"metadata": {},
1515
"source": [
16-
"First, we need to run Memgraph. The easiest way to do this, is to run Memgraph Platform with Docker.\n",
16+
"\n",
17+
"## Prerequisites <a name=\"prerequisites\"></a>\n",
18+
"\n",
19+
"For this tutorial, we need to install:\n",
20+
"\n",
21+
"- [Docker](https://docs.docker.com/get-docker/) - to run Memgraph, since Memgraph is a native Linux application and cannot be installed on Windows and macOS\n",
22+
"- [Memgraph Platform](https://memgraph.com/docs/memgraph/installation) - the complete streaming graph application platform; follow the instructions to install Memgraph Platform with Docker for your OS\n",
23+
"- [GQLAlchemy](https://pypi.org/project/gqlalchemy/)\n",
24+
"\n",
25+
"> ### Memgraph Platform installation using Docker\n",
26+
">\n",
27+
"> After we install Docker, we can run the Memgraph Platform container by running:\n",
28+
">\n",
29+
">```\n",
30+
">docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 memgraph/memgraph-platform\n",
31+
">```\n",
32+
">\n",
33+
">**Memgraph Platform** contains:\n",
34+
">\n",
35+
">- **MemgraphDB** - the database that holds your data\n",
36+
">- **Memgraph Lab** - visual user interface for running queries and visualizing graph data (running at >`localhost:3000`)\n",
37+
">- **mgconsole** - command-line interface for running queries\n",
38+
">- **MAGE** - graph algorithms and modules library\n",
39+
"\n",
40+
"We will use the **GQLAlchemy**'s object graph mapper (OGM) to connect to Memgraph and quickly execute **Cypher** queries. GQLAlchemy also serves as a Python driver/client for Memgraph. We can install it using:\n",
41+
"\n",
1742
"```\n",
18-
"docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 memgraph/memgraph-platform\n",
19-
"```"
43+
"pip install gqlalchemy\n",
44+
"```\n",
45+
"\n",
46+
"> You may need to install [CMake](https://cmake.org/download/) before installing GQLAlchemy."
47+
]
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"id": "9d6dfef6",
52+
"metadata": {},
53+
"source": [
54+
"## Connect to Memgraph with GQLAlchemy"
2055
]
2156
},
2257
{
@@ -160,6 +195,8 @@
160195
"id": "05ebf808",
161196
"metadata": {},
162197
"source": [
198+
"## Load the dataset\n",
199+
"\n",
163200
"The simplest way to load a dataset into Memgraph is by using **Memgraph Lab** which is currently running on `localhost:3000`. The first thing you're going to see on that address is the **Quick Connect**. You just have to click `Connect`!"
164201
]
165202
},
@@ -299,6 +336,8 @@
299336
"id": "9a13b90e",
300337
"metadata": {},
301338
"source": [
339+
"## Map nodes and relationships\n",
340+
"\n",
302341
"We can create a schema for this model inside the Python code by defining the classes that inherit from the `Node` and `Relationship` classes."
303342
]
304343
},
@@ -309,7 +348,7 @@
309348
"metadata": {},
310349
"outputs": [],
311350
"source": [
312-
"from gqlalchemy import Node, Relationship, Field\n",
351+
"from gqlalchemy import Node, Relationship\n",
313352
"\n",
314353
"class Character(Node):\n",
315354
" name: str\n",
@@ -561,26 +600,29 @@
561600
"name": "stdout",
562601
"output_type": "stream",
563602
"text": [
564-
"['Lord Snow']\n"
603+
"{'Lord Snow'}\n"
565604
]
566605
}
567606
],
568607
"source": [
608+
"season_1 = {'Winter Is Coming ', 'The Kingsroad ', 'Lord Snow', \n",
609+
" 'Cripples Bastards and Broken Things ', 'The Wolf and the Lion ', \n",
610+
" 'A Golden Crown ', 'You Win or You Die', 'The Pointy End ', \n",
611+
" 'Baelor ', 'Fire and Blood'}\n",
612+
"\n",
569613
"results = memgraph.execute_and_fetch(\n",
570614
" \"\"\"\n",
571615
" MATCH (e:Episode)-[p:PART_OF]->(s:Season {number: 1})\n",
572616
" RETURN e;\n",
573617
" \"\"\"\n",
574618
")\n",
575619
"\n",
576-
"season_1_deaths = []\n",
620+
"season_1_deaths = set()\n",
577621
"\n",
578622
"for result in results:\n",
579-
" season_1_deaths.append(result[\"e\"].name)\n",
623+
" season_1_deaths.add(result[\"e\"].name)\n",
580624
"\n",
581-
"set_season_1_deaths = set(season_1_deaths)\n",
582-
"missing = list(sorted(season_1 - set_season_1_deaths))\n",
583-
"print(missing)"
625+
"print(season_1 - season_1_deaths)"
584626
]
585627
},
586628
{
@@ -601,7 +643,7 @@
601643
"name": "stdout",
602644
"output_type": "stream",
603645
"text": [
604-
"['The Prince of Winterfell']\n"
646+
"{'The Prince of Winterfell'}\n"
605647
]
606648
}
607649
],
@@ -612,13 +654,12 @@
612654
" RETURN e;\n",
613655
" \"\"\"\n",
614656
")\n",
615-
"season_2_deaths = []\n",
657+
"season_2_deaths = set()\n",
658+
"\n",
616659
"for result in results:\n",
617-
" season_2_deaths.append(result[\"e\"].name)\n",
660+
" season_2_deaths.add(result[\"e\"].name)\n",
618661
"\n",
619-
"set_season_2_deaths = set(season_2_deaths)\n",
620-
"missing_2 = list(sorted(season_2 - set_season_2_deaths))\n",
621-
"print(missing_2)"
662+
"print(season_2 - season_2_deaths)"
622663
]
623664
},
624665
{
@@ -639,7 +680,7 @@
639680
"name": "stdout",
640681
"output_type": "stream",
641682
"text": [
642-
"['The Bear and the Maiden Fair']\n"
683+
"{'The Bear and the Maiden Fair'}\n"
643684
]
644685
}
645686
],
@@ -650,13 +691,12 @@
650691
" RETURN e;\n",
651692
" \"\"\"\n",
652693
")\n",
653-
"season_3_deaths = []\n",
694+
"season_3_deaths = set()\n",
695+
"\n",
654696
"for result in results:\n",
655-
" season_3_deaths.append(result[\"e\"].name)\n",
697+
" season_3_deaths.add(result[\"e\"].name)\n",
656698
"\n",
657-
"set_season_3_deaths = set(season_3_deaths)\n",
658-
"missing_3 = list(sorted(season_3 - set_season_3_deaths))\n",
659-
"print(missing_3)"
699+
"print(season_3 - season_3_deaths)"
660700
]
661701
},
662702
{
@@ -677,7 +717,7 @@
677717
"name": "stdout",
678718
"output_type": "stream",
679719
"text": [
680-
"['Blood of My Blood']\n"
720+
"{'Blood of My Blood'}\n"
681721
]
682722
}
683723
],
@@ -688,13 +728,12 @@
688728
" RETURN e;\n",
689729
" \"\"\"\n",
690730
")\n",
691-
"season_6_deaths = []\n",
731+
"season_6_deaths = set()\n",
732+
"\n",
692733
"for result in results:\n",
693-
" season_6_deaths.append(result[\"e\"].name)\n",
734+
" season_6_deaths.add(result[\"e\"].name)\n",
694735
"\n",
695-
"set_season_6_deaths = set(season_6_deaths)\n",
696-
"missing_6 = list(sorted(season_6 - set_season_6_deaths))\n",
697-
"print(missing_6)"
736+
"print(season_6 - season_6_deaths)"
698737
]
699738
},
700739
{
@@ -1371,16 +1410,16 @@
13711410
"name": "stdout",
13721411
"output_type": "stream",
13731412
"text": [
1374-
"Daenerys Targaryen | BC: 0.2641671685970773\n",
1375-
"Lannister soldier | BC: 0.11163138590238252\n",
1376-
"Sons of the Harpy agent | BC: 0.04326120746568804\n",
1377-
"Jon Snow | BC: 0.041527339730212685\n",
1378-
"Wildling | BC: 0.03782396045716543\n",
1379-
"Stark Soldier | BC: 0.028609456095599384\n",
1380-
"Baratheon of Dragonstone soldier | BC: 0.027533816622595353\n",
1381-
"Cersei Lannister | BC: 0.02644509282920999\n",
1382-
"Stark soldier | BC: 0.02432818459201448\n",
1383-
"Nights Watch brother | BC: 0.022719177729567427\n"
1413+
"Daenerys Targaryen | BC: 0.26416716859707734\n",
1414+
"Lannister soldier | BC: 0.11163138590238253\n",
1415+
"Sons of the Harpy agent | BC: 0.04326120746568793\n",
1416+
"Jon Snow | BC: 0.04152733973021257\n",
1417+
"Wildling | BC: 0.037823960457165504\n",
1418+
"Stark Soldier | BC: 0.02860945609559936\n",
1419+
"Baratheon of Dragonstone soldier | BC: 0.027533816622595367\n",
1420+
"Cersei Lannister | BC: 0.026445092829209968\n",
1421+
"Stark soldier | BC: 0.02432818459201446\n",
1422+
"Nights Watch brother | BC: 0.02271917772956741\n"
13841423
]
13851424
}
13861425
],

0 commit comments

Comments
 (0)