-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path18.CentralityAuthorCitation.py
50 lines (38 loc) · 1.87 KB
/
18.CentralityAuthorCitation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import snap , networkx as nx
import os, sys
path1 = os.path.join(os.getcwd(), sys.argv[1], "EgoNet","Author Citation Network",'AuthorCitationNetwork.hash')
FIn1 = snap.TFIn(path1)
mapping = snap.TStrIntSH (FIn1)
path1 = os.path.join(os.getcwd(), sys.argv[1],"EgoNet","Author Citation Network",'AuthorCitationNetwork.graph')
FIn = snap.TFIn(path1)
G = snap.TNGraph.Load(FIn)
#Degree Centrality
file = open(os.path.join(os.getcwd(), sys.argv[1],"EgoNet","Author Citation Network",'Author_Citation_DegCen.csv') , 'w',errors='ignore')
InDegV = snap.TIntPrV()
snap.GetNodeInDegV(G, InDegV)
OutDegV = snap.TIntPrV()
snap.GetNodeOutDegV(G, OutDegV)
file.write('Authors' +','+ 'IndegCentr' +','+ 'IndegCentr' + '\n')
for (item1 , item2) in zip(InDegV , OutDegV):
file.write(mapping.GetKey(item1.GetVal1()) + ',' + str(item1.GetVal2())+ ',' + str(item2.GetVal2()) + '\n')
file.close()
#Betweenness Centrality
file = open(os.path.join(os.getcwd(), sys.argv[1],"EgoNet","Author Citation Network",'Author_Citation_BetweensCen.csv') , 'w',errors='ignore')
file.write('Authors' +','+ 'BetweennessCent' + '\n')
Nodes = snap.TIntFltH()
Edges = snap.TIntPrFltH()
snap.GetBetweennessCentr(G, Nodes, Edges, 1.0)
for node in Nodes:
file.write(str(mapping.GetKey(node)) +','+ str(Nodes[node]) + '\n')
file.close()
#Eigen Centrality
file = open(os.path.join(os.getcwd(), sys.argv[1],"EgoNet","Author Citation Network",'Author_Citation_EigenCen.csv') , 'w',errors='ignore')
file.write('Authors' +','+ 'EigenCen' + '\n')
graph = nx.read_edgelist(os.path.join(os.getcwd(), sys.argv[1],"EgoNet","Author Citation Network",'AuthorCitationNetwork.csv'),nodetype=str , delimiter=' ')
g = nx.DiGraph(graph)
centrality = nx.eigenvector_centrality(g)
i=0
for node in centrality:
file.write(str(node) +','+ str(centrality[node]) + '\n')
i=i+1
file.close()