def get_seed_main(): flag_dict = dict() for name in classes: flag_dict[name] = [] error = 0 for area in classes: uidlist = readUidByArea(area) ufriends = readFriendsByArea(area) for uid in uidlist: try: for f in ufriends[uid]: v_t = read_by_xapian(xs,f) if v_t != 'other': flag = user_domain_classifier_v2(v_t) if flag != 'other': flag_dict[name].append(f) except: error +=1 pass flag_dict[area].append(uid) protou=open('./protou_combine/protou.txt','w') count = 0 for k,v in flag_dict.items(): if count == 0: protou.write(k+':') count = count + 1 else: protou.write('\n'+k+':') for uid in v: protou.write(' '+str(uid))
def domain_classfiy(uid_weibo):#领域分类主函数 ''' 用户领域分类主函数 输入数据示例: uid_weibo:字典 {uid1:[weibo1,weibo2,weibo3,...]} 输出数据示例: domain:标签字典 {uid1:[label1,label2,label3],uid2:[label1,label2,label3]...} 注:label1是根据粉丝结构分类的结果,label2是根据认证类型分类的结果,label3是根据用户文本分类的结果 re_label:推荐标签字典 {uid1:label,uid2:label2...} ''' weibo_text = dict() uidlist = [] for k,v in uid_weibo.items(): item = '' for i in range(0,len(v)): text = re_cut(v[i]['text']) item = item + ',' + text weibo_text[k] = item uidlist.append(k) users = get_user(uidlist) print 'len(users):',len(users) print len(uidlist) domain = dict() r_domain = dict() text_result = dict() user_result = dict() for k,v in users.items(): uid = k result_label = [] sorted_mbr = dict() field1 = getFieldFromProtou(k, protou_dict=train_users)#判断uid是否在种子用户里面 if field1 != 'Null':#该用户在种子用户里面 result_label.append(field1) else: f= get_friends([k])#返回用户的粉丝列表 friends = f[str(uid)] if len(friends): field1,sorted_mbr = user_domain_classifier_v1(friends, fields_value=txt_labels, protou_dict=proto_users) else: field1 = 'other' sorted_mbr = {'university':0, 'homeadmin':0, 'abroadadmin':0, 'homemedia':0, 'abroadmedia':0, 'folkorg':0, \ 'lawyer':0, 'politician':0, 'mediaworker':0, 'activer':0, 'grassroot':0, 'other':0, 'business':0} result_label.append(field1) r = read_by_xapian(xs,uid) if r == 'other': field2 = 'other' else: field2 = user_domain_classifier_v2(r) result_label.append(field2) field_dict,result = domain_classfiy_by_text({k: weibo_text[k]})#根据用户文本进行分类 field3 = field_dict[k] result_label.append(field3) domain[str(uid)] = result_label user_result[str(uid)] = sorted_mbr#有问题 text_result[str(uid)] = result[k]#有问题 if r == 'other': re_label = get_recommend_result('other',result_label)#没有认证类型字段 else: re_label = get_recommend_result(r['verified_type'],result_label) r_domain[str(uid)] = re_label return domain,re_label