Skip to content

Commit 4c8e700

Browse files
committed
update partial
1 parent 221065d commit 4c8e700

1 file changed

Lines changed: 57 additions & 115 deletions

File tree

‎raw/Analyzing the Graph of Thrones.md‎

Lines changed: 57 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,13 @@
44

55
![](http://www.lyonwj.com/public/img/graphs-are-coming.jpg)
66

7-
A few months ago, mathematicians [Andrew
8-
Beveridge](https://twitter.com/mathbeveridge) and Jie Shan published [Network
9-
of Thrones](https://www.macalester.edu/~abeverid/thrones.html) in Math Horizon
10-
Magazine where they analyzed a network of character interactions from the
11-
novel “A Storm of Swords”, the third book in the popular “A Song of Ice and
12-
Fire” and the basis for the Game of Thrones TV series. In their paper they
13-
detail how they constructed the network of character interactions by using
14-
text analysis and entity extraction to find characters mentioned together in
15-
the text. They then applied social network analysis algorithms to the network
16-
to find the most important characters in the network and a community detection
17-
algorithm to find clusters of characters.
7+
几个月前,数学家[Andrew Beveridge](https://twitter.com/mathbeveridge)和Jie Shan在Math Horizon杂志上发表了[权利的游戏的网络](https://www.macalester.edu/~abeverid/thrones.html),其中,他们分析了小说“冰雨的风暴”,火爆的“冰与火之歌”(权利的游戏电视剧的基础)的第三卷中的角色互动网络。在他们的论文中,他们详细介绍了如何通过使用文本分析和实体抽取,来发现文本中提到的角色,从而构建角色互动网络。然后,他们应用社交网络分析算法到该网络中,以找到该网络中最重要的角色,并且应用社区检测算法来找到角色集群。
188

19-
The analysis and visualization was done using Gephi, a popular graph analytics
20-
tool. I thought it would be fun to try to duplicate the authors’ results using
21-
Neo4j.
9+
分析和可视化是通过使用Gephi,这一流行的图形分析工具,来完成的。我想,尝试使用Neo4j来复制作者的结果,将会很好玩。
2210

23-
# Import initial data into Neo4j
11+
# 导入初始数据到Neo4j
2412

25-
The data was made available on [the authors’
26-
website](https://www.macalester.edu/~abeverid/thrones.html) which you can
27-
download [here.](https://www.macalester.edu/~abeverid/data/stormofswords.csv)
28-
It looks like this:
13+
数据可以在[作者的网站](https://www.macalester.edu/~abeverid/thrones.html)上找到,你可以在[这里](https://www.macalester.edu/~abeverid/data/stormofswords.csv)下载。它看起来像这样:
2914

3015
```python
3116

@@ -37,25 +22,16 @@ It looks like this:
3722

3823
```
3924

40-
Here we have an adjacency list of characters and their number of interactions
41-
throughout the text. We will use a simple data model `(:Character
42-
{name})-[:INTERACTS {weight}]->(:Character {name})`. Nodes with the label
43-
`Character` to represent characters from the text, with a single relationship
44-
type `INTERACTS` connecting characters who have interacted in the text. We’ll
45-
store the character’s name as property `name` on the node and the number of
46-
interactions between two characters as a property `weight` on the
47-
relationships.
25+
这里,我们拥有整个文本中角色的邻接表和他们的互动次数。我们将使用一个简单的数据模型`(:Character {name})-[:INTERACTS {weight}]->(:Character {name})`。带有标签的节点`Character`表示文本中的角色,单个关系类型`INTERACTS`从该角色连接到另一个文本中交互的角色。我们将把角色名作为node属性`name`存储,把两个角色之间的交互数作为relationships属性`weight`存储。
4826

49-
We first must create a constraint to assert the integrity of our schema:
27+
首先,我们必须创建一个约束来断言我们架构的完整性:
5028

5129
```python
5230

5331
CREATE CONSTRAINT ON (c:Character) ASSERT c.name IS UNIQUE;
5432
```
5533

56-
Once the constraint is created (this statement will also build an index which
57-
will improve the performance of lookups by character name) we can use the
58-
Cypher `LOAD CSV` statement to import the data:
34+
一旦创建了约束(该语句也将构建一个索引,它将提高通过角色名查找的性能),我们可以使用Cypher的`LOAD CSV`语句来导入数据:
5935

6036
```python
6137

@@ -66,18 +42,19 @@ Cypher `LOAD CSV` statement to import the data:
6642
ON CREATE SET r.weight = toInt(row.Weight)
6743
```
6844

69-
We have a very simple datamodel:
45+
我们有一个非常简单的数据模型:
7046

7147
```python
7248

7349
CALL apoc.meta.graph()
7450
```
7551

76-
![](http://www.lyonwj.com/public/img/got-datamodel.png) **The graph of thrones
77-
datamodel. Character nodes are connected by an `INTERACTS` relationship.**
52+
![](http://www.lyonwj.com/public/img/got-datamodel.png)
53+
54+
**权利的游戏图的数据模型。角色节点通过`INTERACTS`关系连接。 relationship.**
55+
56+
我们可以看到整个图形,但这并没有给我们关于最重要人物或他们如何交互的许多信息:
7857

79-
We can visualize the entire graph, but this doesn’t give us much information
80-
about the most important characters or how they interact:
8158

8259
```python
8360

@@ -87,17 +64,13 @@ about the most important characters or how they interact:
8764

8865
![](http://www.lyonwj.com/public/img/got-graph-full.png)
8966

90-
# Analyzing the network
67+
# 分析网络
9168

92-
We’ll use Cypher, the graph query language to explore the graph of thrones,
93-
applying some tools from network analysis along the way. Many of the ideas
94-
explored here are explained in detail in the excellent [Networks, Crowds, and
95-
Markets: Reasoning About a Highly Connected
96-
World.](https://www.cs.cornell.edu/home/kleinber/networks-book/)
69+
我们将使用Cypher,这一图形查询语言来探索权利的游戏的图,在此过程中应用来自于网络分析的一些工具。这里探索的许多思路在优秀的[网络,人群和市场:思考高度连接的世界](https://www.cs.cornell.edu/home/kleinber/networks-book/)中进行了详细的解释。
9770

98-
## Number of characters
71+
## 角色数
9972

100-
Let’s start with something simple. How many characters appear in our graph?
73+
让我们先从简单的部分入手。在我们的图中,出现了多少个角色?
10174

10275
```python
10376

@@ -114,10 +87,9 @@ Let’s start with something simple. How many characters appear in our graph?
11487

11588
```
11689

117-
## Summary statistics
90+
## 概要统计
11891

119-
Summary statistics for number of other characters each character has
120-
interacted with:
92+
每个角色交互的其他角色数的概要统计:
12193

12294
```python
12395

@@ -136,10 +108,9 @@ interacted with:
136108

137109
```
138110

139-
## Diameter of the network
111+
## 网络直径
140112

141-
The diameter (or geodesic) of a network is defined as the longest shortest
142-
path in the network.
113+
一个网络的直径(或者测地线)被定义为网络中的最长最短路径。
143114

144115
```python
145116

@@ -167,13 +138,11 @@ path in the network.
167138

168139
```
169140

170-
We can see there are many paths of length six in the network.
141+
我们可以看到,在网络中,有许多长度为6的路径。
171142

172-
## Shortest path
143+
## 最短路径
173144

174-
We can use the `shortestPath` function in Cypher to find the shortest path
175-
between any two characters in the graph. Let’s find the shortest path from
176-
Catelyn Stark to Kahl Drogo:
145+
我们可以使用Cypher中的`shortestPath`函数来查找图中任意两个角色的最短路径。让我们找找从Catelyn Stark到Kahl Drogo的最短路径:
177146

178147
```python
179148

@@ -185,10 +154,9 @@ Catelyn Stark to Kahl Drogo:
185154

186155
![](http://www.lyonwj.com/public/img/shortestpath-got.png)
187156

188-
## All Shortest Paths
157+
## 所有最短路径
189158

190-
There might be other paths of the same length connecting Catelyn and Drogo. We
191-
can find these with the `allShortestPaths` Cypher function:
159+
可能还有其他具有相同长度的连接Catelyn和Drogo的路径。我们可以使用`allShortestPaths` Cypher函数来查找:
192160

193161
```python
194162

@@ -200,10 +168,9 @@ can find these with the `allShortestPaths` Cypher function:
200168

201169
![](http://www.lyonwj.com/public/img/allshortestpaths-got.png)
202170

203-
# Pivotal nodes
171+
# 关键节点
204172

205-
A node is said to be pivotal if it lies on all shortest paths between two
206-
other nodes in the network. We can find all pivotal nodes in the network:
173+
如果节点位于网络中的其它两个节点之间的所有最短路径之中,那么该节点被认为是关键的。我们可以找到网络中的所有关键节点:
207174

208175
```python
209176

@@ -242,10 +209,7 @@ other nodes in the network. We can find all pivotal nodes in the network:
242209

243210
```
244211

245-
If we look through the result table for interesting results we can see that
246-
Robb is a pivotal node for Drogo and Ramsay. This means that all shortest
247-
paths connecting Drogo and Ramsay pass through Robb. We can verify this
248-
visually by looking at all shortest paths connecting Drogo and Ramsay:
212+
如果我们翻阅了有趣结果的结果表,那么可以看到,对于Drogo和Ramsay来说,Robb是一个关键节点。这意味着,所有连接Drogo和Ramsay的最短路径都经过Robb。我们可以通过看看连接Drogo和Ramsay的所有最短路径,可视化的验证这点:
249213

250214
```python
251215

@@ -256,18 +220,13 @@ visually by looking at all shortest paths connecting Drogo and Ramsay:
256220

257221
![](http://www.lyonwj.com/public/img/pivotal-path.png)
258222

259-
# Centrality measures
223+
# 中心性度量
260224

261-
[Centrality measures](https://en.wikipedia.org/wiki/Centrality) give us
262-
relative measures of importance in the network. There are many different
263-
centrality measures and each measures a different type of “importance”.
225+
[中心性度量](https://en.wikipedia.org/wiki/Centrality)为我们提供了网络中重要性的相对措施。有许多不同的中心性度量,而每种度量不同类型的“重要性”。
264226

265-
## Degree Centrality
227+
## 度中心性(Degree Centrality)
266228

267-
Degree centrality is simply the number of connections that a node has in the
268-
the network. In the context of the graph of thrones, the degree centrality of
269-
a character is the number of other characters that character interacted with.
270-
We can calculate degree centrality using Cypher like this:
229+
度中心性仅是一个节点在网络中的连接数。在权利的游戏的图的上下文中,一个角色的度中心性是该角色交互的其他角色数。我们可以像这样使用Cypher来计算度中心性:
271230

272231
```python
273232

@@ -303,17 +262,11 @@ We can calculate degree centrality using Cypher like this:
303262

304263
```
305264

306-
And we see that Tyrion has interacted with the most characters in the network.
307-
Given his scheming, I think this makes sense.
265+
而且我们看到,Tyrion与网络中的角色具有最多的互动。鉴于他的心计,我觉得这是有道理的。
308266

309-
## Weighted Degree Centrality
267+
## 加权度中心性
310268

311-
We are storing the number of interactions between a pair of characters as a
312-
property `weight` on the `INTERACTS` relationship. Summing this weight across
313-
all `INTERACTS` relationships for the character gives us their _weighted
314-
degree centrality_, or the total number of interactions in which they
315-
participated. Again, we can use Cypher to calculate this metric for all
316-
characters:
269+
我们存储一对角色之间的交互数,作为`INTERACTS关系上的`weight`属性。对角色的所有`INTERACTS关系上的该权重求和,我们可以获得他们的_加权度中心性_,或者他们参与的交互总数。同样,我们可以使用Cypher来为所有的角色计算该度量:
317270

318271
```python
319272

@@ -349,11 +302,9 @@ characters:
349302

350303
```
351304

352-
## Betweenness Centrality
305+
## 中介中心性(Betweenness Centrality)
353306

354-
The [betweenness
355-
centrality](https://en.wikipedia.org/wiki/Betweenness_centrality) of a node in
356-
a network is the number of shortest paths between two other members in the
307+
一个网络中的一个节点的[中介中心性(Betweenness Centrality)](https://en.wikipedia.org/wiki/Betweenness_centrality) 是,the number of shortest paths between two other members in the
357308
network on which a given node appears. Betweenness centality is an important
358309
metric because it can be used to identify “brokers of information” in the
359310
network or nodes that connect disparate clusters.
@@ -405,18 +356,18 @@ from Cypher:
405356

406357
```
407358

408-
## Closeness centrality
359+
## 接近中心性(Closeness centrality)
409360

410-
[Closeness
411-
centrality](https://en.wikipedia.org/wiki/Centrality#Closeness_centrality) is
361+
[接近中心性(Closeness centrality)](https://en.wikipedia.org/wiki/Centrality#Closeness_centrality) is
412362
the inverse of the average distance to all other characters in the network.
413363
Nodes with high closeness centality are often highly connected within clusters
414364
in the graph, but not necessarily highly connected outside of the cluster.
415365

416-
![](http://www.lyonwj.com/public/img/closeness-centrality.png) **Nodes with
366+
![](http://www.lyonwj.com/public/img/closeness-centrality.png)
367+
368+
**Nodes with
417369
high closeness centrality are connected to many other nodes in a network.
418-
[Image credit](https://www.linkedin.com/pulse/wtf-do-you-actually-know-who-
419-
influencers-walter-pike)**
370+
[Image credit](https://www.linkedin.com/pulse/wtf-do-you-actually-know-who-influencers-walter-pike)**
420371

421372
```python
422373

@@ -454,18 +405,16 @@ influencers-walter-pike)**
454405

455406
```
456407

457-
# Using python-igraph
408+
# 使用python-igraph
458409

459410
One of the things I love about Neo4j is how well it works with other tools,
460411
things like R and Python data science tools. We could continue to use apoc to
461-
run [PageRank](https://neo4j-contrib.github.io/neo4j-apoc-
462-
procedures/#_pagerank_algorithm) and [community detection](https://neo4j-
463-
contrib.github.io/neo4j-apoc-procedures/#_graph_algorithms) algorithms, but
412+
run [PageRank](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_pagerank_algorithm) and [community detection](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_graph_algorithms) algorithms, but
464413
let’s switch to using [python-igraph](http://igraph.org/python/) to calculate
465414
some analyses. Python-igraph is a port of the R igraph graph analytics
466415
library. To install, just use `pip install python-igraph`.
467416

468-
### Building an igraph instance from Neo4j
417+
### 从Neo4j构建一个igraph实例
469418

470419
To use igraph on our graph of thrones data, the first thing we need to do is
471420
pull data out of Neo4j and build an igraph instnace in Python. We can do this
@@ -495,8 +444,7 @@ algorithms implemented in igraph.
495444
The first algorithm we’ll use in igraph is
496445
[PageRank](https://en.wikipedia.org/wiki/PageRank). PageRank is an algorithm
497446
originally used by Google to rank the importance of web pages and is a type of
498-
[eigenvector
499-
centrality](https://en.wikipedia.org/wiki/Centrality#Eigenvector_centrality).
447+
[eigenvector centrality](https://en.wikipedia.org/wiki/Centrality#Eigenvector_centrality).
500448

501449
![](http://www.lyonwj.com/public/img/page-rank.png) **PageRank: The size of
502450
each node is proportional to the number and size of the other nodes pointing
@@ -564,9 +512,7 @@ PageRank score:
564512

565513
### Community detection
566514

567-
![](http://www.lyonwj.com/public/img/community-1.png) **[Image
568-
credit](http://digitalinterface.blogspot.com/2013/05/community-detection-in-
569-
graphs.html)**
515+
![](http://www.lyonwj.com/public/img/community-1.png) **[Image credit](http://digitalinterface.blogspot.com/2013/05/community-detection-in-graphs.html)**
570516

571517
Community detection algorithms are used to find clusters in the graph. We’ll
572518
use the [walktrap method](http://arxiv.org/abs/physics/0512106) as implemented
@@ -636,7 +582,7 @@ with and the members of each community:
636582

637583
```
638584

639-
## Visualization - putting it all together
585+
## 可视化 - 把它们放在一起
640586

641587
![](http://www.lyonwj.com/public/img/graph-of-thrones.png) **The graph of
642588
thrones. Node size is proportional to betweenness centrality, colors indicate
@@ -654,9 +600,7 @@ visualizations. [Vis.js](http://visjs.org/) is one such library that allows
654600
for building interactive graph visualizations. To make the process of pulling
655601
data from Neo4j and building graph visualizations with vis.js I’ve been
656602
working on [neovis.js](https://github.com/johnymontana/neovis.js), which
657-
combines vis.js and the [Neo4j official Javascript
658-
driver](http://www.lyonwj.com/2016/06/26/graph-of-thrones-neo4j-social-
659-
network-analysis/). Neovis.js provides a simple API that allows for
603+
combines vis.js and the [Neo4j official Javascript driver](http://www.lyonwj.com/2016/06/26/graph-of-thrones-neo4j-social-network-analysis/). Neovis.js provides a simple API that allows for
660604
configuring the visualization. For example, the following Javascript is all
661605
that is necessary to produce the visualization above:
662606

@@ -686,23 +630,21 @@ that is necessary to produce the visualization above:
686630
viz.render();
687631
```
688632

689-
Note that we have specified:
633+
请注意,我们已经指定:
690634

691-
* We want to include nodes with the label `Character` in the visualization, using the property `name` as their caption
635+
* 在可视化中,我们想要包含带标签`Character`的节点,使用合适的`name`作为其标题
692636
* Node size should be proportional to the value of their `betweenness` property
693-
* We want to include `INTERACTS` relationships in the visualization
637+
* 在可视化中,我们想要包含`INTERACTS`关系
694638
* The thickness of the relationships should be proportional to the value of the `weight` property
695639
* The nodes should be colored according to the value of the propety `community` which identifies the clusters in the network
696640
* To pull the data from a Neo4j server on `localhost`
697641
* To display the visualization in a DOM element with the id `viz`
698642

699-
Neovis.js takes care of pulling the data from Neo4j and creating the
700-
visualization based on our minimal configuration.
643+
Neovis.js需要从Neo4j拉取数据,并且基于我们的最低配置创建可视化。
701644

702-
## Resources
645+
## 资源
703646

704647
* A. Beveridge and J. Shan, [“Network of Thrones”](http://www.maa.org/sites/default/files/pdf/Mathhorizons/NetworkofThrones%20%281%29.pdf) Math Horizons Magazine , Vol. 23, No. 4 (2016), pp. 18-22.
705648
* J. Kleinberg and D. Easley, [Networks, Crowds, and Markets: Reasoning About a Highly Connected World.](https://www.cs.cornell.edu/home/kleinber/networks-book/) Cambridge University Press (2010)
706649

707-
All code is [available on Github.](https://github.com/johnymontana/graph-of-
708-
thrones/blob/master/network-of-thrones.ipynb)
650+
所有代码[可以在Github上找到](https://github.com/johnymontana/graph-of-thrones/blob/master/network-of-thrones.ipynb)。

0 commit comments

Comments
 (0)