All pastes #332549 Raw Edit

Untitled

public text v1 · immutable
#332549 ·published 2007-01-30 02:06 UTC
rendered paste body
import time

t = time.time()
#257 inputs
#255 chars, 1 words to space ratio, 1 spelling mistake %
CHAR_SET = {}
CHAR_RANGE = range(256)


for i in CHAR_RANGE:
	CHAR_SET[i] = 0.0

del CHAR_RANGE


def getFreq(file):
	totalchars = 0
	f = open(file, "r")
	data = f.readlines()
	charfreq = CHAR_SET.copy()
	for line in data:
		for character in line:
			if charfreq.has_key(ord(character)):
				charfreq[ord(character)] += 1
				totalchars += 1
			else:
				print "WTF!!!"


	spacing = float(charfreq[9] + charfreq[32])
	for i in charfreq.keys():
		charfreq[i] = charfreq[i] / totalchars


	words = 0.0
	for line in data:
		words += len(line.split(" "))

	
	words_space_ratio = words / spacing
	

	rawdata = str(charfreq.values())
	return rawdata[1:len(rawdata)-1].replace(",", "") + " "  + str(words_space_ratio)



print getFreq("/home/bruk/Work/Projects/ANN/libfann.py")
done = time.time() - t
print done