Example #1
0
def levensht(name):
	
	with open(correct, "r")as mefile:
		stan = mefile.readlines()
	
	f = open(name,"w")

	d=0

	print len(stan)


	for doc in documents:
		with open(doc,"r") as myfile:
			doct = myfile.readlines()
		print len(doct)
		levnotacc = []
		levacc = []
		unacc =[]
		l=0
		for line in doct:
			if line == "\n":
				levnotacc+=[len(stan[l].split())]
				unacc += [(l,stan[l])]
			else:
				
				levacc += [Levenshtein.levenshtein(stan[l].split(),line.split())]
			
			l+=1


		f.write("FILE: %s\nEdit distance of accepted strings %s\nTotal Edit distance: %s\nNumber of unaccepted sentences: %s \nUnaccepted sentences\n" % (docnames[d],sum(levacc)/float(len(levacc)),sum(levacc+levnotacc)/float(len(levacc+levnotacc)),len(levnotacc)))
		for (n,ua) in unacc:
			f.write(str(n) + "\t" + ua + "\n")
		f.write("\n")
		d+= 1