name=line.split()[0] if(name not in Dict): Dclass[name]=index extra_ct += 1 word_dir={} subd={'TOTAL':1,'PROB':0.0,'WD':word_dir,'NEW':0.0,'WCount':0} Dict[name]=subd index += 1 elif(name in Dict): cnt=Dict[name]['TOTAL'] cnt += 1 Dict[name]['TOTAL']=cnt list= line.lower().split() for i in range(len(list)): if list[i] not in (punc_list and stop_word_list and num_list) and len(list[i]) > 3: list[i] = stem(list[i]) if(list[i] not in total_dict): total_dict[list[i]]=1 if(list[i] not in Dict[name]['WD'] ): if(list[i] != name.lower()): Dict[name]['WD'][list[i]]=1 wcount=Dict[name]['WCount'] wcount += 1 Dict[name]['WCount']=wcount else: count=Dict[name]['WD'].get(list[i]) count += 1 count=Dict[name]['WD'][list[i]]=count
punc_list = [ '.', '?', '!', '@', '\"', '\,', '*', '#', '$', '(', ')', '-', ':', ';', '[', ']' ] num_list = [] num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for line in fintest: list1 = line.split() dict1 = {} for key, value in map_dict.items(): val = main_dict[key]['PROB'] for i in range(1, len(list1)): if list1[i] not in punc_list and stop_word_list and len( list1[i]) > 3 and list1[i] not in num_list: list1[i] = stem(list1[i]) if list1[i] in main_dict[key]['WD']: val += main_dict[key]['WD'][list1[i]] else: val += main_dict[key]['NEW'] dict1[key] = val maxValue = max(dict1.items(), key=operator.itemgetter(1))[1] for k, v in dict1.items(): if v == maxValue: foname.write(k) print(k) foname.write('\n') #except:
foname=open("output.txt",'w',encoding='utf-8',errors='ignore') main_dict=pickle.load(finame) map_dict=pickle.load(finame) stop_word_list = ['a','an','and','are','as','at','be','but','by','for','if','in','into','is','it','of','on','or','s','such','t','that','the','their','then','there','these','they','this','to','was','will','with'] punc_list = ['.','?','!','@','\"','\,','*','#','$','(',')','-',':',';','[',']'] num_list = [] num_list = [0,1,2,3,4,5,6,7,8,9] for line in fintest: list1=line.split() dict1={} for key,value in map_dict.items(): val=main_dict[key]['PROB'] for i in range(1,len(list1)): if list1[i] not in punc_list and stop_word_list and len(list1[i]) > 3 and list1[i] not in num_list : list1[i] = stem(list1[i]) if list1[i] in main_dict[key]['WD']: val+=main_dict[key]['WD'][list1[i]] else: val+=main_dict[key]['NEW'] dict1[key]=val maxValue=max(dict1.items(), key=operator.itemgetter(1))[1] for k,v in dict1.items(): if v==maxValue: foname.write(k) print(k) foname.write('\n') #except: