In [ ]:
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
import matplotlib
matplotlib.rcParams['figure.figsize'] = (10.0, 8.0)
from graph_tool.all import *
In [2]:
wikipedia_datadir = '/var/www/html/data/wikipedia'
In [3]:
wikipedia_dataset="%s/enwiki-07032015-linkgraph_wtitle.gt"%wikipedia_datadir
In [6]:
GG=load_graph(wikipedia_dataset)
In [7]:
GG.num_vertices()
Out[7]:
In [8]:
GG.num_edges()
Out[8]:
In [9]:
freqs, bins=graph_tool.stats.vertex_hist(GG, deg='in')
plt.plot(np.log(bins[:-1]), np.log(freqs), 'go')
plt.title("in degree histogram")
Out[9]:
In [10]:
freqs, bins=graph_tool.stats.vertex_hist(GG, deg='out')
plt.plot(np.log(bins[:-1]), np.log(freqs), 'go')
plt.title("out degree histogram")
Out[10]:
In [11]:
god_page=graph_tool.util.find_vertex(GG, GG.vertex_properties['title'], 'God')[0]
god_page
Out[11]:
In [12]:
python_page=graph_tool.util.find_vertex(GG, GG.vertex_properties['title'], 'Python')[0]
python_page
Out[12]:
In [13]:
for nei in python_page.out_neighbours():
print(GG.vertex_properties['title'][nei])
In [14]:
v=GG.vertex(np.random.randint(0, GG.num_vertices()))
In [15]:
GG.vertex_properties['title'][v]
Out[15]:
In [16]:
god=graph_tool.util.find_vertex(GG, GG.vertex_properties['title'], 'God')[0]
In [17]:
vertices, edges=graph_tool.topology.shortest_path(GG, source=v, target=god)
In [18]:
for v in vertices:
print(GG.vertex_properties['title'][v], end='\t')