def unmark_stopword(self, id, word): if not c.user: return redirect(url(controller='login', action='signin', id=None, return_to=url.current())) w = meta.Session.query(model.Stopword).filter_by(user_id=c.user.id, feed_id=id, word=word).first() if not w: h.flash("can't remove '%s', because it is not on the list." % word) log.debug("w: %s" % w) meta.Session.delete(w) from sqlalchemy.exceptions import IntegrityError meta.Session.commit() h.flash("removed '%s' from stopwords list." % word) return self.redo(id)
def change_intervall(self, id): word = request.params.get('word') settings = meta.Session\ .query(model.BayesFeedSetting)\ .filter_by(user_id = c.user.id, feed_id=id).first() if settings: meta.Session.add(settings) else: settings = model.BayesFeedSetting() settings.user_id = c.user.id settings.feed_id = id meta.Session.add(settings) settings.summarize_at = word meta.Session.commit() h.flash('changed intervall to %s' % word) return h.go_back()
def __mark_as__(self, entry, pool, guesser, force=False): """ when forced the entry is updated even if the db says it is already """ log.debug("entry.id: %s" % entry.id) classy = meta.Session\ .query(model.Classification)\ .filter_by(user_id = c.user.id, entry_id=entry.id).first() if not classy: classy = model.Classification() classy.user_id = c.user.id classy.entry_id = entry.id classy.pool = pool meta.Session.add(classy) untrain_id = None else: if classy.pool == pool and not force: h.flash("entry was already classified as %s" % pool) return h.go_back(h.url_for(controller='feed', action='show_feed', id=entry.feed_id)) classy.pool = pool meta.Session.add(classy) untrain_id = entry.id meta.Session.commit() guesser.trainer.train(pool, __relevant__(entry), entry.id) if pool == 'spam': other_pool = 'ham' elif pool == 'ham': other_pool = 'spam' else: raise "bad pool" # if untraind_id: # guesser.trainer.untrain(other_pool, __relevant__(entry), untrain_id) guesser.save() if not force: h.flash("now known as %s: %s" % (pool, entry.id)) return h.go_back(h.url_for(controller='feed', action='show_feed', id=entry.feed_id))
def mark_stopword(self, id, word): if not c.user: return redirect(url(controller='login', action='signin', id=None, return_to=url.current())) w = model.Stopword() w.user_id = c.user.id w.feed_id = id w.word = word meta.Session.add(w) from sqlalchemy.exceptions import IntegrityError try: meta.Session.commit() h.flash("%s? Never heard about it." % word) except IntegrityError: h.flash("i already know that '%s' is a stop word." % word) meta.Session.rollback() return self.redo(id)
def redo(self, id): if not c.user: return redirect(url(controller='login', action='signin', id=None, return_to=url.current())) c.feed = meta.find(model.Feed, id) query = meta.Session\ .query(model.Classification)\ .join(model.FeedEntry)\ .filter_by(feed_id=id) guesser = Guesser(c.feed, c.user, config) guesser.clear() cnt = 0 needles_cnt = 0 for entry in query: # h.flash("%s :%s" % (entry.pool, __relevant__(entry.entry))) # guesser.trainer.train(entry.pool, __relevant__(entry.entry)) if guesser.is_spam(entry.entry, use_classified=False) and (entry.pool == 'spam'): needles_cnt += 1 elif not guesser.is_spam(entry.entry, use_classified=False) and (entry.pool == 'ham'): needles_cnt += 1 self.__mark_as__(entry.entry, entry.pool, guesser, True) cnt+=1 guesser.save() log.debug("FOOOOOO") if needles_cnt > 0: h.flash("%d entries were needlessly trained (total: %s)" % (needles_cnt, cnt)) else: h.flash("learned %s entries" % cnt) return h.go_back()
def update(self, id): #~ feed = meta.Session.query(model.Feed).get(id) feed = meta.find(model.Feed, id) cnt_added = feed.fetch() h.flash("added %s entries" % cnt_added) return h.go_back()