Introduction to Game of Thrones¶
Introduction¶
Game of Thrones is an 8 season (10 episodes/season) popular HBO series.
The show is said to be relatively complex. The alluring, if somewhat frustrating, element of Game of Thrones is that just when you think you see a thread, the show proves you wrong. Central characters are killed, psychopaths claim power, weddings become bloodbaths, and bad guys develop consciences as time passes. The twists and turns of the plot lock us in, and the developments that are impossible to anticipate give us a dopamine rush that keeps us coming back for more. (source )
But some acts of betrayal - whether threats, abandonment, or murder itself -
come as total surprises not only to the viewers, but the foolishly trusting characters
themselves. Over the course of eight seasons, virtually hundreds of betrayals
took
place, all in the name of the pursuit of power. Here, we take a look back at the ten
most shocking moments of betrayal in the series.
One of the most well known betrayals is that of Lord Varys
against Daenerys
. Daenerys is one of the last surviving members (along with her older brother, Viserys) of House Targaryen, who,
until fourteen years before the events of the first novel, had ruled Westeros
from the Iron Throne for nearly three hundred years prior to being ousted.
Varys was born as a slave in the Free City of Lys and joined a travelling acting troupe.
The ultimate betrayal takes place in series 8 where Lord Varys
is killed by Daenerys
. At least he made it to the last season .
Uploading Data¶
In this exercise we will study the different betrayals. Where
each betrayal has a perpetrator
and a victim
. Studying this in Excel
is a big challenge.
A data-set with such a high level of interconnections is best studied in a
graphical database. The data can be downloaded
csv
LOAD CSV WITH HEADERS FROM "file:///trones.csv" AS line
WITH line
MERGE (Perpetrator:Character{name:line.Perpetrator, house:line.PerpHouse})
MERGE (Victim:Character{name:line.Victim, house:line.VictimHouse})
MERGE (Perpetrator)-[betrayal:Betrayal{`Betrayal Description`:line.Betrayal,
`Relationship perp-victim`:line.`Relationship Perp-Victim`,
`Immediate Consequence`: CASE WHEN line.`Immediate Consequence` IS NOT NULL THEN
line.`Immediate Consequence`
ELSE '' END,
Location: CASE WHEN line.Geography IS NOT NULL THEN line.Geography
ELSE '' END}]->(Victim)
Inspecting the data:
MATCH (n)-[r]->(p)
RETURN n,r,p
Our scheme is much simpler then the fraud detection case study:
CALL db.schema.visualization()

Stuyding the betrayals¶
How many betrayals exists in our graph ?
MATCH (n)-[r]->()
RETURN COUNT(r)
Find all Nodes of type house with name “Lannister”
MATCH (c:Character)
WHERE c.house='Lannister'
RETURN c
Find all the people who betrayed ned stark (and their betrayls)
MATCH (p2)-[r]->(c:Character{name:'Ned'})
RETURN p2,c,r
This person is Cersei
, how many people did she betray ?
MATCH (c:Character {name:'Cersei'})-[r]->(p)
RETURN COUNT(DISTINCT p) as CercsaiBetrayed
(note the use of the keyword DISTINCT
)
Who are the top 3 perpetrators ?
MATCH (perpetrator:Character)-[b:Betrayal]->(victim:Character)
RETURN perpetrator, COUNT(perpetrator) AS numBetrayed
ORDER BY numBetrayed DESC LIMIT 3
perpetrator |
numBetrayed |
---|---|
{name:Varys,house:X} |
7 |
{name:Petyr,house:Baelish} |
6 |
{name:Cersei,house:Lannister} |
5 |
Who betrayed the most ? And whom did he betray ?
MATCH (n)-[b:Betrayal]->(m)
WITH n, count((n)-[]->()) as num
ORDER by num DESC LIMIT 1
MATCH (n)-[r]->(b)
return n,r,b
The most unreliable person seems to be Lord Varys
:

Note the use of the WITH
keyword. The query consists of two queries where the results
of the first are passed on to the second. The first query finds all the betrayals and
the second finds all the betrayals originating from this person.
Who is innocent in the house of Lannister ?
MATCH (a)
WHERE NOT (a:Character)-[:Betrayal]->() AND a.house = 'Lannister'
return a
This person is Cersei
, she is Queen of the Seven Kingdoms of Westeros.

There are different Cypher-queries possible to achieve the same result:
MATCH (a)<-[:Betrayal]-(b)
WITH a,COUNT(a) AS number
ORDER BY number DESC LIMIT 1
MATCH (a)<-[:Betrayal]-(b)
RETURN b,a

Find the characters which betrayed their own house and their betrayals
MATCH (traitor:Character )-[r]->(victim)
WHERE traitor.house=victim.house
WITH traitor, COUNT(*) as numBetrayed
ORDER BY numBetrayed DESC LIMIT 2
MATCH (v:Character)<-[r]-(traitor)
RETURN v,r,traitor
And the most dangerous person is Tyrion of the house of Lannister:

How are two characters connected ? (for example Sansa and Ned)
MATCH p=(b:Character{name:'Sansa'})-[*]->(a:Character{name:'Ned'})
RETURN p
Last change: Oct 30, 2023