Example #1
0
 def ret(self, cat, *a, **kw):
     if not cat and self.current_category:
         cat = self.current_category
         return fn(self, cat, *a, **kw)
     elif cat and Category.exists(cat):
         cat = Category.get(cat)
         return fn(self, cat, *a, **kw)            
     elif cat and not Category.exists(cat):
         print "category %s not found. try 'categories'?" % cat
     else:
         print "must specify a category. try 'categories'?"
Example #2
0
    def do_actions(self, noargs):
        if not Category.all():
            print "no categories"
            return

        count = 0
        for x in Category.all():
            if x.action().exists():
                count += 1
                print x.name

        if not count:
            print 'no actions defined'
Example #3
0
    def _classify(self):
        self.current_category = self.current_probability = None

        if not Category.all():
            print "Can't classify because I have no categories"
            return

        if not self.current_message:
            return

        cat, prob = Category.classify(str(self.current_message))

        self.current_category = cat
        self.current_probability = prob

        return self.current_category
Example #4
0
def main(imap_folder_name):
    "Mostly copy-pasted form drymail-train; probably need to be cleaned up"

    with config.IMAP_connection() as im:
        for msg_num, msg in each_imap_message(im,imap_folder_name):
            cat, prob = Category.classify(str(msg))

            print "%s(%f): %s" % (cat.name, prob,
                                  msg.get('Subject', '(none)').replace('\n',' '))
Example #5
0
    def do_newcategory(self, cat):
        "create a new category"
        if not self.validcat.match(cat):
            print "invalid category name. must match %s" % validcat_expr
            return

        newcat = Category.create(cat)
        print (('Created "%s". Note that this new category is empty,'
                +'and will need to be trained')
               % newcat.name)
Example #6
0
def main(category_name, imap_folder_name):
    cat = Category.get(category_name)

    with config.IMAP_connection() as im:
        for msg_num, msg in each_imap_message(im, imap_folder_name):
            print ('Training "%s"'
                   % msg.get('Subject', '(none)').replace('\n',' '))
            cat.train(str(msg))

    return 'not implemented'
Example #7
0
    def test_clear_jointable_on_delete_habtm_with_custom_args(self):
        join_tablename = 'posts_categories'
        post = yield Blogpost(title='headline').save()
        category = yield Category(name="personal").save()

        yield post.categories.set([category])
        cat_id = category.id
        yield category.delete()
        res = yield self.config.select(join_tablename,
                                       where=['category_id = ?', cat_id],
                                       limit=1)
        self.assertIsNone(res)
Example #8
0
    def do_supertrain(self, cat):
        """train the current message on the given category until the
        classifier says that's what it is"""
        train_count = 0
        while True:
            train_count += 1

            (newcat, prob) = Category.classify(str(self.current_message))
            if newcat == cat:
                break

            print "Training %d... (%s %.2f%%)" % (train_count, newcat.name, prob*100)
            cat.train(str(self.current_message))
        self._classify()
Example #9
0
 def _complete_categories(self, text, line, begidx, endidx):
     return [ x.name for x in Category.all()
              if x.name.startswith(text) ]
Example #10
0
 def do_categories(self, noargs):
     """just return the list of currently known categories"""
     for x in Category.all():
         print x.name