# Most cited degrees = [(x, len(filtered_g.predecessors(x))) for x in filtered_g.nodes()] top5 = sorted(degrees, key=itemgetter(1), reverse=True)[:5] print "Top cited works:" for item, citers in top5: print "%s - %s. Cited %s times" % (item, filtered_g.node[item].get( 'title', ''), citers) # Most same-journal citations degrees = [(x, len(filtered_g.successors(x))) for x in filtered_g.nodes()] top5 = sorted(degrees, key=itemgetter(1), reverse=True)[:5] print "Top same-journal citations:" for item, citers in top5: print "%s - %s. Citing a %s-sourced article %s times" % ( item, filtered_g.node[item].get('title', ''), journal, citers) print "Writing out GraphML graph to %s" % (journal + "-" + regex + ".gml") write_graphml(filtered_g, open(journal + "-" + regex + ".gml", "w")) print "Attempting to draw graph for viewing" import matplotlib.pyplot as plt plt.figure(figsize=(8, 8)) #nx.draw(filtered_g, node_colors=[float(filtered_g.level[x] % 4 *64) for x in filtered_g]) nx.draw(filtered_g, filtered_g.position, node_size=50, node_color=[float(filtered_g.degree(v) * 4) for v in filtered_g]) print "Saving graph image as %s" % (journal + "-" + regex + ".png") plt.savefig(journal + "-" + regex + ".png") plt.show()
for ctype in info['citations'].keys(): for c_id, citation_params in info['citations'][ctype]: if not g.has_node(c_id): citation_params['_xml_container'] = ctype g.add_node(c_id, **to_node_params(citation_params)) no_attribs.add_node(c_id) # add directed edge for this g.add_edge(nodeid, c_id) no_attribs.add_edge(nodeid, c_id) return g, no_attribs errorlist = open("unparsable.log", "w") if __name__ == "__main__": for journal in jlist: try: g, no_attribs = generate_network(journal) filename = re.sub('[^a-z.]+', '-', journal.lower()).strip('-') + '.graphml' n_filename = re.sub( '[^a-z.]+', '-', journal.lower()).strip('-') + '-nodesonly.graphml' print "Saving fully attrib'd graph as %s" % (filename) write_graphml(g, open(filename, "w")) print "Saving plain graph, no attributes as %s" % (n_filename) write_graphml(no_attribs, open(n_filename, "w")) except IndexError: print "ERROR Couldn't parse journal: %s" % journal errorlist.write("%s\n" % journal)
nlmxml=os.path.join(journal_dir, nlmxml) ) ) no_attribs.add_node(nodeid) for ctype in info['citations'].keys(): for c_id, citation_params in info['citations'][ctype]: if not g.has_node(c_id): citation_params['_xml_container'] = ctype g.add_node(c_id, **to_node_params(citation_params)) no_attribs.add_node(c_id) # add directed edge for this g.add_edge(nodeid, c_id) no_attribs.add_edge(nodeid, c_id) return g, no_attribs errorlist = open("unparsable.log", "w") if __name__ == "__main__": for journal in jlist: try: g, no_attribs = generate_network(journal) filename = re.sub('[^a-z.]+', '-', journal.lower()).strip('-') + '.graphml' n_filename = re.sub('[^a-z.]+', '-', journal.lower()).strip('-') + '-nodesonly.graphml' print "Saving fully attrib'd graph as %s" % (filename) write_graphml(g, open(filename, "w")) print "Saving plain graph, no attributes as %s" % (n_filename) write_graphml(no_attribs, open(n_filename, "w")) except IndexError: print "ERROR Couldn't parse journal: %s" % journal errorlist.write("%s\n" % journal)
for year_marker in xrange(year_max+1-year_min): filtered_g.add_node(year_marker+year_min) filtered_g.position[year_marker+year_min] = (dx * year_marker, 950) # Most cited degrees = [(x, len(filtered_g.predecessors(x))) for x in filtered_g.nodes()] top5 = sorted(degrees, key=itemgetter(1), reverse=True)[:5] print "Top cited works:" for item, citers in top5: print "%s - %s. Cited %s times" % (item, filtered_g.node[item].get('title',''), citers) # Most same-journal citations degrees = [(x, len(filtered_g.successors(x))) for x in filtered_g.nodes()] top5 = sorted(degrees, key=itemgetter(1), reverse=True)[:5] print "Top same-journal citations:" for item, citers in top5: print "%s - %s. Citing a %s-sourced article %s times" % (item, filtered_g.node[item].get('title',''), journal, citers) print "Writing out GraphML graph to %s" % (journal+"-"+regex+".gml") write_graphml(filtered_g, open(journal+"-"+regex+".gml", "w")) print "Attempting to draw graph for viewing" import matplotlib.pyplot as plt plt.figure(figsize=(8,8)) #nx.draw(filtered_g, node_colors=[float(filtered_g.level[x] % 4 *64) for x in filtered_g]) nx.draw(filtered_g, filtered_g.position, node_size=50, node_color=[float(filtered_g.degree(v)*4) for v in filtered_g]) print "Saving graph image as %s" % (journal+"-"+regex+".png") plt.savefig(journal+"-"+regex+".png") plt.show()