How to use equal_list method in lisa

Best Python code snippet using lisa_python

domain_classify.py

Source:domain_classify.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-23import os4import re5import scws6import sys7import csv8import opencc9from global_utils_do import *1011sys.path.append('../../trans')12from trans import trans, traditional2simplified1314# cc = opencc.OpenCC('t2s', opencc_path='/usr/bin/opencc')15s = load_scws()1617def classify_by_biostring(bio_string):#根据用户bio_string划分1819 # bio_string_s = cc.convert(bio_string.decode('utf-8'))20 bio_string_s = bio_string.decode('utf-8')21 2223 kwdlist = bio_string_s.encode('utf-8')#cut(s, bio_string_s.encode('utf-8'))24 lawyerw_weight = sum([1 for keyword in lawyerw if keyword in kwdlist]) # 律师25 adminw_weight = sum([1 for keyword in adminw if keyword in kwdlist]) # 组织26 mediaw_weight = sum([1 for keyword in mediaw if keyword in kwdlist]) # 媒体27 businessw_weight = sum([1 for keyword in businessw if keyword in kwdlist]) # 商业人士28 govw_weight = sum([1 for keyword in govw if keyword in kwdlist]) # 政府官员29 mediaworkerw_weight = sum([1 for keyword in mediaworkerw if keyword in kwdlist]) # 媒体人士30 universityw_weight = sum([1 for keyword in universityw if keyword in kwdlist]) # 高校3132 max_weight = 033 label = 'other'34 #equal_list = []35 36 if max_weight < businessw_weight:37 max_weight = businessw_weight38 label = 'business'39## equal_list = ['business']40## else:41## pass4243 if max_weight < adminw_weight:44 max_weight = adminw_weight45 label = 'admin'46## equal_list = ['admin']47## elif max_weight == adminw_weight:#如果相等48## equal_list.append('admin')49## else:50## pass5152 if max_weight < mediaw_weight:53 max_weight = mediaw_weight54 label = 'media'55## equal_list = ['media']56## elif max_weight == mediaw_weight:#如果相等57## equal_list.append('media')58## else:59## pass6061 if max_weight < lawyerw_weight:62 max_weight = lawyerw_weight63 label = 'lawyer'64## equal_list = ['lawyer']65## elif max_weight == lawyerw_weight:#如果相等66## equal_list.append('lawyer')67## else:68## pass6970 if max_weight < govw_weight:71 max_weight = govw_weight72 gov = 'politician'73## equal_list = ['politician']74## elif max_weight == govw_weight:#如果相等75## equal_list.append('politician')76## else:77## pass7879 if max_weight < mediaworkerw_weight:80 max_weight = mediaworkerw_weight81 label = 'mediaworker'82## equal_list = ['mediaworker']83## elif max_weight == mediaworkerw_weight:#如果相等84## equal_list.append('mediaworker')85## else:86## pass8788 if max_weight < universityw_weight:89 max_weight = universityw_weight90 label = 'university'91## equal_list = ['university']92## elif max_weight == universityw_weight:#如果相等93## equal_list.append('university')94## else:95## pass9697## if len(equal_list) > 2:98## label = 'other'99## elif len(equal_list) == 2:100## l1 = equal_list[0]101## l2 = equal_list[1]102## if DICT_LENGTH[l1] > DICT_LENGTH[l2]:103## label = l2104## elif DICT_LENGTH[l1] < DICT_LENGTH[l2]:105## label = l1106## else:107## pass108## else:109## pass110111 return label112113def classify_inner_outer(location):114115 # bio_string_s = traditional2simplified(location.decode('utf-8'))116 bio_string_s = location.decode('utf-8')117 new_location = bio_string_s.encode('utf-8')118 flag = 0119 for city in inner_city:120 if city in new_location:121 flag = 1122 break123124 return flag125126def domain_main(user_data):#twitter用户身份分类主函数127 '''128 输入数据:129 user_data用户数据字典:{'uid':{'description':description,'username':username,'location':location,'number_of_text':number of text}...}130 description:twitter用户背景信息中的description。注意:有部分内容是英文,需要转换成中文131 username:twitter用户背景信息中的username132 location:twitter用户背景信息中的location。注意:有部分内容是英文,需要转换成中文133 number_of_text:用户最近7天发帖数量134135 输出数据:136 user_label用户身份字典:{'uid':label,'uid':label...}137 '''138 if len(user_data) == 0:139 return {}140141 user_label = dict()142 for k,v in user_data.iteritems():143 label = 'other'144 try:145 description = v['description']146 except KeyError:147 description = ''148 try:149 username = v['username']150 except KeyError:151 username = ''152 try:153 location = v['location']154 except KeyError:155 location = '' 156 try:157 number_of_text = v['number_of_text']158 except KeyError:159 number_of_text = 0160 161 bio_string = username + '_' + description162 #根据bio_string划分163 if len(bio_string) > 1:164 label = classify_by_biostring(bio_string)165166 if label == 'admin':#组织167 if location:168 flag = classify_inner_outer(location)169 if flag == 1:#境内170 label = 'inner_admin'171 else:172 label = 'outer_admin'173 else:174 label = 'admin'175 elif label == 'media':#媒体176 if location:177 flag = classify_inner_outer(location)178 if flag == 1:#境内179 label = 'inner_media'180 else:181 label = 'outer_media'182 else:183 label = 'media'184 else:185 pass186 187 if label != 'other':188 user_label[k] = label189 continue190191 #根据发帖数量判定192 if number_of_text >= ACTIVE_COUNT:193 label = 'active'194 user_label[k] = label195196 return user_label197 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful