當前位置: 首頁>>代碼示例>>Python>>正文


Python Bayes.saves方法代碼示例

本文整理匯總了Python中reverend.thomas.Bayes.saves方法的典型用法代碼示例。如果您正苦於以下問題:Python Bayes.saves方法的具體用法?Python Bayes.saves怎麽用?Python Bayes.saves使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在reverend.thomas.Bayes的用法示例。


在下文中一共展示了Bayes.saves方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: retrain

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import saves [as 別名]
def retrain(request):
    # Retrain your brain
    user = User.objects.get(user=request.user)
    posts = Post.objects.filter(user=user)
    bayes = Brain.objects.get(user=user)
    brain = Bayes()
    #brain.loads(base64.decodestring(bayes.data))

    tagcount = 0
    # retrain the brain based on existing tags
    for post in posts:
        print post.title, "::",
        for tag in post.tags.all():
            text = "%s %s %s" % (post.title, post.author, post.summary)
            brain.train(tag, text)
            tagcount += 1
            print tag,
        print
    brain.save('%s.db' % user)
    bayes.data = base64.encodestring(brain.saves())
    bayes.save()

    message = 'Found %s tags' % tagcount
    params = {'Messages': [message,]}
    return response(request, 'mainapp/index.html', params)
開發者ID:hollerith,項目名稱:freeder,代碼行數:27,代碼來源:views.py

示例2: mark

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import saves [as 別名]
def mark(request, flag):
    
    id = request.GET.get('post', None)
    feed = request.GET.get('feed', None)
    category = request.GET.get('category') 
    tag = request.GET.get('tag') or None
    
    try:
        if feed:
           posts = Post.objects.filter(feed=feed)
        else:
           posts = Post.objects.filter(id=id)
    except Post.DoesNotExist:
        return HttpResponseRedirect('/')
    
    bayes = Brain.objects.get(user=request.user) #login required
    brain = Bayes()
    brain.loads(base64.decodestring(bayes.data))
    
    if flag in ('read', 'unread'):
        flag = flag == 'read'
        posts.update(read=flag) 
    else:
        for post in posts:
            text = "%s %s %s" % (post.title, post.author, post.summary)
            t1 = Tag.objects.get(id=flag)
            if t1 in post.tags.all() and not feed:
                post.tags.remove(t1) 
                brain.untrain(t1.name, text)
            else:
                post.tags.add(t1)
                brain.train(t1.name, text)
            post.save()    
        
    bayes.data = base64.encodestring(brain.saves())
    bayes.save()
        
    if category:
       return HttpResponseRedirect('/?category=%s' % category)
    elif feed:
       return HttpResponseRedirect('/?feed=%s' % feed)
    elif tag:
       return HttpResponseRedirect('/?tag=%s' % tag)
    else:
       return HttpResponseRedirect('/')
開發者ID:hollerith,項目名稱:freeder,代碼行數:47,代碼來源:views.py

示例3: read

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import saves [as 別名]
def read(request, id):
    try:
        post = Post.objects.get(id=id)
        post.read = True
        post.save()

        try:
            bayes = Brain.objects.get(user=request.user) #login required
            brain = Bayes()
            brain.loads(base64.decodestring(bayes.data))
            text = post.title + ' ' + post.author + post.summary
            brain.train('Interesting', text)        
            bayes.data = base64.encodestring(brain.saves())
            bayes.save()
        except Exception, e:
            print "Couldn't train %s because %s" % (post.title, e)

        return HttpResponseRedirect(post.link)
開發者ID:hollerith,項目名稱:freeder,代碼行數:20,代碼來源:views.py

示例4: brainit

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import saves [as 別名]
def brainit():
    brain = Bayes()
    data = base64.encodestring(brain.saves())
    return data
開發者ID:hollerith,項目名稱:freeder,代碼行數:6,代碼來源:models.py

示例5: Bayes

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import saves [as 別名]
posts = Post.objects.filter(user=user)
bayes = Brain.objects.get(user=user)
brain = Bayes()
#brain.loads(base64.decodestring(bayes.data))

# retrain the brain based on existing tags
def retrain():
  for post in posts:
    for tag in post.tags.all():
      text = "%s %s %s" % (post.title, post.author, post.summary)
      brain.train(tag, text)
      print "%s :: %s" % (tag, post.title)

retrain()

bayes.data = base64.encodestring(brain.saves())
bayes.save()

from BeautifulSoup import BeautifulSoup

from mainapp.models import Post
from reverend.thomas import Bayes

brain = Bayes()
brain.load('fish.db')

tag = 'Dead'
posts = Post.objects.filter(read=read)
posts = posts.filter(tags__in=tag)
#brain.train('Dead', post.summary)
t1 = Tag.objects.get(id=flag)
開發者ID:hollerith,項目名稱:freeder,代碼行數:33,代碼來源:utils.py


注:本文中的reverend.thomas.Bayes.saves方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。