예제 #1
0
def training_ignor_class(request, tid):
    t = GroupTopic.objects.filter(tid=tid).first()
    st = time.time()
    sample = get_topicatbs(t)
    nbc = NaiveBayesClassifier(Drive())
    r = nbc.classify(sample)
    res = '%s %s' % (r, time.time() - st)
    return HttpResponse(res)
예제 #2
0
def findad(request, tid=''):
    t = None
    if tid:
        t = GroupTopic.objects.filter(tid=tid, other='').first()
    else:
        t = GroupTopic.objects.filter(type='', other='').first()
    
    
    if not t:
        return new_topic(request)
    
    st = time.time()
    sample = get_topicatbs(t)
    nbc = NaiveBayesClassifier(Drive())
    r = nbc.classify(sample)
    ct = time.time() - st
    
    try:
        t.type = max(r.items(), key=lambda x:x[1])[0]
        
        if 'ad' in r and 'ok' in r:
            p = r['ad'] / (r['ad'] + r['ok'])
            t.other = 'auto'
            st = time.time()
            if p > 0.60:
                # 广告
                t.other = t.other + " ad" 
                try:
#                     comment_topic(t.tid, 'mark %s' % p)
                    report_topic(t.tid)
                except:
                    t.other = 'failed'
        if 'po' in r and 'ok' in r:
            p = r['po'] / (r['po'] + r['ok'])
            if p > 0.60:
                # 色情
                t.other = t.other + " po" 
                try:
                    report_topic(t.tid, '1')
                except:
                    t.other = 'failed'
    except:
        t.other = 'failed'
    
    t.save()
    rt = time.time() - st
    res = {
           'title':t.title,
           'url':t.url,
           'tid':t.tid,
           'p':p,
           'type':t.type,
           'other':t.other,
           'class_time':ct,
           'report_time':rt
           }
    return HttpResponse(json.dumps(res))
예제 #3
0
def training_to_class(request, tid, cls):
    t = GroupTopic.objects.filter(tid=tid).first()
    st = time.time()
    res = None
    if t.other == 'train':
        res = 'trained'
    else:
        sample = get_topicatbs(t)
        nbc = NaiveBayesClassifier(Drive())
        nbc.training(sample, cls)
        t.other = 'train'
        t.type = cls
        t.save()
        res = '%s %s' % ('/'.join(sample), time.time() - st)
    return HttpResponse(res)
예제 #4
0
def tdm(request, txt):
    st = time.time()
    nbc = NaiveBayesClassifier(Drive())
#     test_classifer(nbc)
    c = nbc.whichclass(txt)
    return HttpResponse('%ss  %s'%(time.time()-st, c))