#!/usr/bin/python2.4
import cgi
import cgitb; cgitb.enable()
from count import wordcount
def main():
form = cgi.FieldStorage()
print "Content-Type: text/html"
print
fog = Fog(form)
fog.ui()
class Fog:
def __init__(self, form):
self.debug = 0
self.contents = {}
self.comment = form.getvalue("comment", "")
self.sentencecount, self.words = wordcount(self.comment)
if self.debug: self.contents["message"] = '
' + `form` + '
\n\n'
else: self.contents["message"] = ''
try:
self.contents["state"] = int(form.getvalue("s", 1))
except:
self.contents["state"] = 0
if 'back' in form:
self.contents["state"] -= 1
if 'next' in form:
self.contents["state"] += 1
if self.contents["state"] == 1 or self.contents["state"] > 3 or not self.comment or not self.sentencecount:
self.contents["state"] = 1
if not self.sentencecount and 'next' in form:
self.contents["message"] += '
Please enter the sample with sentences in the text box below:
'
self.contents["message"] += '
An example:
'
self.contents["message"] += '
Helsinki is the capital of Finland. Did you you know that?
' % len(self.words)
for word in self.unique(self.words.keys()):
self.contents["message"] += '%s' % (word, word)
self.contents["message"] += '' % self.comment
def unique(self, list):
""" Return (sorted) unique elements """
d = {}
for x in list:
d[x] = 1
subset = d.keys()
subset.sort(self.bigstrings)
return subset
def bigstrings(self, x, y):
""" comparison function to return largest string """
if len(x) < len(y):
return 1
if len(x) > len(y):
return -1
if len(x) == len(y):
return 0
def valueadd(self, d, l):
""" Adds the dict d values for the corresponding keys in the list l """
total = 0
for i in l:
if i in d:
total += d[i]
return total
def third(self, form):
wcount = len(self.words)
hardwords = form.getlist("hardwords")
q = form.getvalue("q", 0.4)
q = float(q) # check
if self.debug: self.contents["message"] += '
'
self.contents["message"] += '' % self.comment
self.contents["message"] += desc
self.contents["next"] = 'Start over'
def ui(self):
if "back" not in self.contents:
self.contents["back"] = 'Back'
if "next" not in self.contents:
self.contents["next"] = 'Next'
print template % self.contents
template = """
Gunning Fog Index - (%(state)d of 3)
Easy reading range is 6-10. The average person reads at the level 9.
Anything above 17th level is difficult for university students.
Limitations
A low style of writing can result from a slavish use of readability indexes
as a monotonous succession of short sentences and simple words can make your
writing dull and dull writing does not hold the reader's attention.
the indexes frequently give conflicting results
Best use of this Index
Use the formulas as a general guide
Formulas will not replace the clear and logical thinking that is the foundation of all clear writing