-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path9.ArticleCentrality.py
42 lines (30 loc) · 1.31 KB
/
9.ArticleCentrality.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
"""
Created on Sun Nov 24 2019
@author: Bilal Hayat Butt, Sufyan Faizi
@Description: The code is used to apply centrality analysis on article citation network
First, article citation network graph is loaded,
Second, indegree and out degree centrality of article citation network was calculated
"""
import snap, networkx as nx
import os, sys
path1 = os.path.join(sys.argv[4]+'.hash')
FIn1 = snap.TFIn(path1)
mapping = snap.TStrIntSH (FIn1)
path1 = os.path.join(os.getcwd(), sys.argv[1], sys.argv[2],sys.argv[3]+'.graph')
FIn = snap.TFIn(path1)
G = snap.TNGraph.Load(FIn)
path2 = os.path.join(os.getcwd(), sys.argv[1], sys.argv[2],sys.argv[3]+'.csv')
G1 = nx.read_edgelist(path2,delimiter=' ',nodetype=str)
file = open(os.path.join(os.getcwd(), sys.argv[1],sys.argv[2],'IndegreeAndOutdegree.csv'),"w")
file.write('DOI' +','+ 'Out_Degree' +','+ 'In_Degree' + '\n')
for NI in G.Nodes():
file.write(mapping.GetKey(NI.GetId()) + ',' + str(NI.GetOutDeg()) + ',' + str(NI.GetInDeg()) + '\n')
file.close()
'''
file = open(os.path.join(os.getcwd(), sys.argv[1],sys.argv[2],'katz.csv'),"w")
centrality = nx.katz_centrality(G1 , normalized=True , tol=1e-06)
file.write('DOI' +','+ 'KatzCentr' + '\n')
for n,c in sorted(centrality.items()):
file.write(str(n) + ',' + str(c) + '\n')
file.close()
'''