]> code.communitydata.science - social-media-chapter.git/blob - code/data_processing/make_network.py
initial import of material for public archive into git
[social-media-chapter.git] / code / data_processing / make_network.py
1 '''Takes a CSV of retrieved articles, and creates an igraph
2 network from them (not even close to done)'''
3
4 class CitationNetwork(igraph.Graph):
5     def __init__(self, network_type):
6         super().__init__(directed=True)
7         self.temp_edges = []
8         self.temp_vertices = []
9         self.network_type = network_type
10
11     def add_vertices(self, to_node, from_nodes):
12         self.temp_vertices += [[from_node, to_node] for from_node in from_nodes]
13
14     def make_network(self):
15         # Get the unique set of nodes, and add them.
16         nodes = set([v for v in self.temp_vertices if v['eid'] not in self.vs['name']])
17         nodes = sorted(nodes)
18         self.add_vertices(nodes)
19         self.add_edges(self.temp_edges)
20         self.es['weight'] = 1
21
22     def collapse_weights(self):
23         self.simplify(combine_edges={"weight": "sum"})
24
25     def add_citations(eid, citations):
26         self.retrieved_eids.append(eid)

Community Data Science Collective || Want to submit a patch?