1
0
Files
social-media-chapter/code/data_processing/make_network.py
Benjamin Mako Hill dd420c77de initial import of material for public archive into git
We're creating a fresh archive because the history for our old chapter includes
API keys, data files, and other material we can't share.
2018-01-21 17:15:51 -08:00

27 lines
926 B
Python

'''Takes a CSV of retrieved articles, and creates an igraph
network from them (not even close to done)'''
class CitationNetwork(igraph.Graph):
def __init__(self, network_type):
super().__init__(directed=True)
self.temp_edges = []
self.temp_vertices = []
self.network_type = network_type
def add_vertices(self, to_node, from_nodes):
self.temp_vertices += [[from_node, to_node] for from_node in from_nodes]
def make_network(self):
# Get the unique set of nodes, and add them.
nodes = set([v for v in self.temp_vertices if v['eid'] not in self.vs['name']])
nodes = sorted(nodes)
self.add_vertices(nodes)
self.add_edges(self.temp_edges)
self.es['weight'] = 1
def collapse_weights(self):
self.simplify(combine_edges={"weight": "sum"})
def add_citations(eid, citations):
self.retrieved_eids.append(eid)