Skip to content

Instantly share code, notes, and snippets.

@fnielsen
Created November 22, 2011 00:19
Show Gist options
  • Save fnielsen/1384457 to your computer and use it in GitHub Desktop.
Save fnielsen/1384457 to your computer and use it in GitHub Desktop.
Co-author mining with shortest path in the Brede Wiki
# wget http://neuro.imm.dtu.dk/services/bredewiki/download/bredewiki-templates.sqlite3
import matplotlib.pyplot as plt
import networkx as nx
from pysqlite2 import dbapi2
connection = dbapi2.Connection('bredewiki-templates.sqlite3')
sql = "SELECT DISTINCT tid FROM brede WHERE (template='paper' OR template='conference_paper');"
cursor = connection.cursor()
cursor.execute(sql)
tids = [ row[0] for row in cursor.fetchall() ]
g = nx.Graph()
sql = "SELECT value FROM brede WHERE tid=? AND field='author'";
for tid in tids:
cursor.execute(sql, (tid,))
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])
path = nx.shortest_path(g, u"Finn Årup Nielsen", "Natalie Herslag")
for author in path: print(author)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment