Hello,

I am a Python Newbie. I am trying to replicate the source code from
http://fivefilters.org/term-extraction

Source Code: https://code.launchpad.net/~keyvan/five ... xtraction/

I have the following:
WAMP
Python 2.7
MOD_WSGI
WEB.PY

When I try to execute the below code on my firefox web browser
( http://localhost/term ) the Apache access logs say it's an HTTP/1.1"
405 4 Error, however the page output says "None". This is the first
time we are trying to use Python code. What am I doing wrong?

[code]
    #!/home/protected/bin/python

    import web

    urls = (
        '/', 'hello',
       '/terms', 'terms'
    )
    app = web.application(urls, globals())

    class hello:
        def GET(self):
            return '<form action="terms" method="POST"><textarea
name="context" style="width:450px; height:300px;">Inevitably, then,
corporations do not restrict themselves merely to the arena of
economics. Rather, as John Dewey observed, "politics is the shadow
cast on society by big business". Over decades, corporations have
worked together to ensure that the choices offered by \'representative
democracy\' all represent their greed for maximised profits.\n\nThis
is a sensitive task. We do not live in a totalitarian society - the
public potentially has enormous power to interfere. The goal, then, is
to persuade the public that corporate-sponsored political choice is
meaningful, that it makes a difference. The task of politicians at all
points of the supposed \'spectrum\' is to appear passionately
principled while participating in what is essentially a charade.</
textarea><br />JSON callback: <input type="text" name="callback" /
><br /><input type="submit" value="Get terms" /></form>'

    class terms:
        def POST(self):
          import re
          import simplejson as json
          from topia.termextract import extract
          extractor = extract.TermExtractor()
          #extractor.filter = extract.permissiveFilter
          extractor.filter =
extract.DefaultFilter(singleStrengthMinOccur=1)
          def term_compare(x, y):
             if y[1]+y[2]*2 > x[1]+x[2]*2:
                return 1
             elif y[1]==x[1] and y[2]==x[2]:
                return 0
             else: # x<y
                return -1

          input = web.input(callback=None)
          content = input.context.lower()
          content = content.replace(u"\u201c", '"').replace(u"\u201d",
'"').replace(u"\u2018", "'").replace(u"\u2019",
"'").replace(u"\u2026", "")
          list = sorted(extractor(content), term_compare)
          list = list[:50]
          for i in range(len(list)-1, -1, -1):
             if len(list[i][0]) == 1 or list[i][2] > 2 or (list[i]
[0].find("http") >= 0) or not re.search('[a-z]', list[i][0]) or
re.search('[0-9]', list[i][0]):
                list.remove(list[i])
             else:
                list[i] = list[i][0]
          callback = input.callback
          if callback and re.match('^[a-zA-Z0-9._\[\]]+$', callback):
             return callback + '(' + json.dumps(list, indent=4) + ')'
          else:
             return json.dumps(list, indent=4)
          #return json.dumps(list, indent=4)
          #return json.dumps(extractor(i.context).sort(term_compare))

    if __name__ == "__main__":
        app.run()

    app = web.application(urls, globals(), autoreload=False)
    application = app.wsgifunc()
[/code]

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to