-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path15.CollaborationNetwork.py
67 lines (55 loc) · 1.84 KB
/
15.CollaborationNetwork.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
60
61
62
63
64
65
66
67
import csv
import time
import snap
import os,sys
import pandas as pd
start = time.time()
list1 = []
list2 = []
list3 = []
Tuple = ('' , '')
path = os.path.join(os.getcwd(),sys.argv[1],"EgoNet","Collaboration Network")
if not os.path.exists(path): #check if folder already exist, if it doesn't then create it
os.makedirs(path)
path1 = os.path.join(path,'CollaborationNetwork.csv')
pathtemp = os.path.join(path,'CollaborationNetworkTemp.csv')
chunksize = 100000
file = open(pathtemp , 'w')
path2 = os.path.join(os.getcwd(),sys.argv[1],"EgoNet","DOI_AuthorCSEgoNet.csv")
with open(path2 , 'r') as data:
reader = csv.reader(data , delimiter = ',')
for row in reader:
row.pop(0)
list1 = row
list2 = row
for Author in list1:
for Collab in list2:
if Author != Collab:
Tuple = (Author , Collab)
#Tuple_reverse = (Collab , Author)
#if Tuple not in list3:
list3.append(Tuple)
#list3.append(Tuple_reverse)
file.write(str(Tuple) + '\n')
file.close()
i=1
for df in pd.read_csv(pathtemp, chunksize=chunksize, iterator=True):
df = df.replace({"'":''}, regex=True)
df = df.replace({"\)":''}, regex=True)
df = df.replace({"\(":''}, regex=True)
df = df.replace({",":''}, regex=True)
df.to_csv(path1,sep = ' ', mode = 'ab', index = None, header=False)
i+=1
try:
mapping = snap.TStrIntSH()
LoadedGraph = snap.LoadEdgeListStr(snap.PUNGraph,path1, 0, 1, mapping)
path3 = os.path.join(path, "CollaborationNetwork.graph")
FOut = snap.TFOut(path3)
LoadedGraph.Save(FOut)
FOut.Flush()
path3 = os.path.join(path, "CollaborationNetwork.Hash")
FOut = snap.TFOut(path3)
mapping.Save(FOut)
FOut.Flush()
except:
print("Graph Files Not Created")