-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_hepCollaborations.py
executable file
·57 lines (46 loc) · 1.82 KB
/
get_hepCollaborations.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
#!/usr/bin/env python
from src.hepsearch import *
import pickle, os, csv
# MiembrosRedFAE2017.dat contains the info of the form filled by FAE members
# First, read the members file
members_file = read_csv('data/MiembrosRedFAE2017.dat','|')
#members_file.pop(0)
num_authors = len(members_file)
if not os.path.exists("output/"):
os.makedirs("output")
# Makes the list of nodes
out = csv.writer(open("output/NodesRedFAE2017.csv","w"))
nodes, included = [], []
id = 0
for member in members_file:
node_name = member[1][0] + "." + member[2].strip()
if member[3] != "":
node_name += "-" + member[3].strip()
if not node_name in included:
# Nodes list contains : [id, name, signatures]
nodes.append([id, node_name, member[16]])
# Nodes file contains: [id, name, gender, type, academic degree, SNI, City, Age]
if id == 0:
out.writerow(['Id', node_name, member[4], member[5], member[6], member[7], member[10], member[17]])
else:
out.writerow([id, node_name, member[4], member[5], member[6],member[7],member[10],member[17]])
id += 1
included.append(node_name)
else:
print "WARNING: %s may be duplicated" %node_name
empty_list = []
# Initialize the collaboration matrix
Matrix = [[empty_list for x in range(num_authors)] for y in range(num_authors)]
# Make the search of authors
nodes.pop(0);
for author in nodes:
for author2 in nodes:
if int(author[0]) < int(author2[0]):
list = make_query_authors(check_signature(author), check_signature(author2))
Matrix[int(author[0])][int(author2[0])] = list
Matrix[int(author2[0])][int(author[0])] = list
# Save the collaboration matrix in a file
file_name = 'data/connections.dat'
file_obj = open(file_name,'wb')
pickle.dump(Matrix,file_obj)
file_obj.close()