本文整理匯總了Python中reverend.thomas.Bayes.loads方法的典型用法代碼示例。如果您正苦於以下問題:Python Bayes.loads方法的具體用法?Python Bayes.loads怎麽用?Python Bayes.loads使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類reverend.thomas.Bayes
的用法示例。
在下文中一共展示了Bayes.loads方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: mark
# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import loads [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('/')
示例2: read
# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import loads [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)
示例3: Bayes
# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import loads [as 別名]
"user": user,
"title": title,
"author": author,
"description": description,
"summary": summary,
"content": content,
"link": link,
},
)
# Autotagging new posts
if created:
try:
bayes = Brain.objects.get(user=user)
brain = Bayes()
brain.loads(base64.decodestring(bayes.data))
text = "%s %s %s" % (title, author, summary)
guess = brain.guess(text)
for t in guess:
if t[1] > 0.75:
tag = Tag.objects.filter(user=user).filter(name=t[0])
if tag:
print "Autotagging %s as %s" % (title, t[0])
post.tags.add(tag[0].id)
except Exception, e:
print "Problem autotagging %s, Exception says: %s" % (title, e)
dtMax = max(dtMax, post.dt_published)
post.current = True
if created and isDuplicate(post.title):
print "Skipping duplicate or old news"