This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xs = [ float(i)/64.0 for i in range(-150, 41) ] | |
ys = [ float(i)/16.0 for i in range(-25,26) ] | |
for y in ys: | |
s = '' | |
for x in xs: | |
z = 0j; i = 0 | |
while i < 10: | |
z = z**2 + x+y*1j | |
if abs(z) > 2: | |
break # Get out of inner loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
documents = [ dict( | |
email=open("conference/%d.txt" % n).read().strip(), | |
category='conference') for n in range(1,372) ] | |
documents.extend([ dict( | |
email=open("job/%d.txt" % n).read().strip(), | |
category='job') for n in range(1,275)]) | |
documents.extend([ dict( | |
email=open("spam/%d.txt" % n).read().strip(), | |
category='spam') for n in range(1,799) ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code inspired and developed from: | |
# http://streamhacker.com/2010/05/10/text-classification-sentiment-analysis-naive-bayes-classifier/ | |
from __future__ import division | |
import nltk.classify, nltk.corpus, nltk.classify.util | |
from pylab import * | |
filebase = '/home/fn' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib, urllib2 | |
import simplejson as json | |
import dateutil.parser | |
import datetime | |
import matplotlib.dates | |
import matplotlib.finance | |
from matplotlib import pyplot as plt | |
import nltk.corpus | |
import numpy as np | |
import re |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $Id: Nielsen2012Python_case.py,v 1.2 2012/09/02 16:55:25 fn Exp $ | |
# Define a url as a Python string (note we are only getting 100 documents) | |
url = "http://wikilit.referata.com/" + \ | |
"wiki/Special:Ask/" + \ | |
"-5B-5BCategory:Publications-5D-5D/" + \ | |
"-3FHas-20author%3DAuthor(s)/-3FYear/" + \ | |
"-3FPublished-20in/-3FAbstract/-3FHas-20topic%3DTopic(s)/" + \ | |
"-3FHas-20domain%3DDomain(s)/" + \ | |
"format%3D-20csv/limit%3D-20100/offset%3D0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python2.6 | |
'Finn Årup Nielsen' | |
u'Finn Årup Nielsen' | |
unicode('Finn Årup Nielsen', 'utf-8') | |
# So what is wrong with that?} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import math, sys # Importing modules. | |
def formatresult(res): # Define function. Remember colon! | |
"""This is the documentation for a function.""" | |
return "The result is %f" % res # Percentage for formating | |
if len(sys.argv) < 3: # Conditionals should be indended | |
print("Too few input argument") |