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.
This commit is contained in:
26
code/data_processing/make_network.py
Normal file
26
code/data_processing/make_network.py
Normal file
@@ -0,0 +1,26 @@
|
||||
'''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)
|
||||
Reference in New Issue
Block a user