Skip to content

Instantly share code, notes, and snippets.

@fnielsen
Created November 17, 2011 17:50
Show Gist options
  • Save fnielsen/1373887 to your computer and use it in GitHub Desktop.
Save fnielsen/1373887 to your computer and use it in GitHub Desktop.
Co-author mining for papers in the Brede Wiki
import matplotlib.pyplot as plt
import networkx as nx
from pysqlite2 import dbapi2
connection = dbapi2.Connection('bredewiki-templates.sqlite3')
sql = "SELECT DISTINCT pid FROM brede WHERE (template='paper' OR template='conference_paper');"
cursor = connection.cursor()
cursor.execute(sql)
pids = [ row[0] for row in cursor.fetchall() ]
g = nx.Graph()
sql = "SELECT value FROM brede WHERE pid=? AND field='author'";
for pid in pids:
cursor.execute(sql, (pid,))
authors = [ row[0] for row in cursor.fetchall() ]
for n in range(len(authors)):
for m in range(len(authors)):
g.add_edge(authors[n], authors[m])
nx.draw(nx.connected_component_subgraphs(g)[3])
plt.show()
plt.savefig('coauthors.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment