本文整理汇总了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)
示例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('/')
示例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)
示例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
示例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)