# -*- python -*- import __main__, dbagg, logging, iso8601, time, dbagg.web from twisted.web.woven import controller, widgets from twisted.web.util import redirectTo ################################################################################ class DumpBayesPage(dbagg.web.AggPage): templateFile = "dump_bayes.html.tmpl" def initialize(self, *args, **kwargs): self.log = logging.getLogger("%s"%self.__class__) self.conn = kwargs['conn'] self.sources = kwargs['sources'] self.items = kwargs['items'] self.classifier = kwargs['classifier'] def wmfactory_words(self, request): db = self.classifier.bayes.db words = {'pos':[], 'neg':[]} for word in db.keys(): pos_count, neg_count = db[word][0], db[word][1] if pos_count > 0: words['pos'].append({'word':word, 'count':"%s"%pos_count}) if neg_count > 0: words['neg'].append({'word':word, 'count':"%s"%neg_count}) words['pos'].sort(lambda x,y: cmp(y['count'], x['count'])) words['neg'].sort(lambda x,y: cmp(y['count'], x['count'])) return words ################################################################################ resource = DumpBayesPage(conn=__main__.conn, \ sources=__main__.sources, \ items=__main__.items, \ classifier=__main__.classifier)