-
Notifications
You must be signed in to change notification settings - Fork 3
/
12.EgoNetCode.py
59 lines (47 loc) · 2 KB
/
12.EgoNetCode.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
51
52
53
54
55
56
57
58
59
# Authors Bilal Hayat Butt, Talha Aslam, Sufyan Faizi
# Description
import snap ,os, pandas as pd,sys
srcNode = ''
dstNode = ''
i=0
print("Reading Graph Files")
FIn1 = snap.TFIn(sys.argv[1]+".hash")
COCIMapping = snap.TStrIntSH (FIn1)
FIn = snap.TFIn(sys.argv[2]+".graph")
COCIGraph = snap.TNGraph.Load(FIn)
path = os.path.join(os.getcwd(), sys.argv[3], sys.argv[4], sys.argv[5]+'.csv')
CSMapping = snap.TStrIntSH()
CSGraph = snap.LoadEdgeListStr(snap.PNGraph, path, 0, 1, CSMapping)
path1 = os.path.join(os.getcwd(),sys.argv[3],"EgoNet","Article")
os.makedirs(path1)
path2 = os.path.join(path1,'Article.csv')
file = open(path2,'w')
for CSNode in CSGraph.Nodes():
COCINode = COCIGraph.GetNI(CSNode.GetId())
#COCINode = CSNode
for Id in COCINode.GetOutEdges():
print("edge (%s %s)" % (COCIMapping.GetKey(COCINode.GetId()), COCIMapping.GetKey(Id)))
srcNode = COCIMapping.GetKey(COCINode.GetId())
dstNode = COCIMapping.GetKey(Id)
file.write(srcNode + ' ' + dstNode + '\n')
for Id in COCINode.GetInEdges():
print("edge (%s %s)" % (COCIMapping.GetKey(COCINode.GetId()), COCIMapping.GetKey(Id)))
srcNode = COCIMapping.GetKey(COCINode.GetId())
dstNode = COCIMapping.GetKey(Id)
file.write(srcNode + ' ' + dstNode + '\n')
file.close()
try:
path1 = os.path.join(os.getcwd(),sys.argv[3],"EgoNet","Article","Article.csv")
#Create CSEgoNet Graph(binary)
mapping = snap.TStrIntSH()
G=snap.LoadEdgeListStr(snap.PNGraph, path1, 0, 1, mapping)
newpath4 = os.path.join(os.getcwd(), sys.argv[3],"EgoNet","Article", 'Article.graph')
FOut = snap.TFOut(newpath4)
G.Save(FOut)
FOut.Flush()
path5 =os.path.join(os.getcwd(), sys.argv[3], "EgoNet","Article", 'Article.hash')
FOut = snap.TFOut(path5)
mapping.Save(FOut)
FOut.Flush()
except:
print("Graph Files Not Created")