(rawlog_path,template_path,break_threshold=0)
计算每个模板匹配的日志的个数
计算每个模板匹配的日志的个数
计算每个模板匹配的日志的个数
def matchTemplatesAndSave(rawlog_path,template_path,break_threshold=0):
    '''
        计算每个模板匹配的日志的个数
    '''
    new_path=template_path+'order_logTemplate.txt'#words排序后的templates
    tag_temp_dir = {}
    tag_log_dir={}
    tag_count = {}
    # 1.初始化template_list
    print ("reading templates from",template_path+'logTemplate.txt')
    match = Match(template_path+'logTemplate.txt')
    result_dict={}
    for i in range(len(match.template_list)):
        # f=file(template_path+'template'+str(i+1)+'.txt','w')
        result_dict[i+1]=[]
    print ("# of templates:",len(match.template_list))
    cur_ID=0
    f = file(template_path + 'logSequence.txt','w')
    out_list=[]
    n=1
    with open(rawlog_path) as IN:
        for line in IN:
            n+=1
            if n%2000 == 0:
                print( 'cur',n)
            cur_ID+=1
            #2.匹配模板
            line = line.strip()
            l=line.split()
            cur_time=l[0]
            tag=match.matchTemplateByType(line)
            # if tag not in tag_temp_dir:
            #     tag_log_dir[tag]=' '.join(l[1:])
            #     tag_temp_dir[tag]=match.template_list[tag-1]
                #print tag_log_dir[tag]
                #print tag_temp_dir[tag]
                #print ''
                # print ' '.join(l)
                # print "tag:"+str(tag),
                # print match.template_list[tag-1],'\n'

            result_dict[tag].append(cur_ID)
            out_list.append(str(cur_time)+' '+str(tag)+'\n')
            # f.writelines(str(cur_time)+' '+str(tag)+'\n')
            if break_threshold!=0 and cur_ID > break_threshold:
                break

    for line in out_list:
        f.writelines(line)
def matchTemplatesAndSave ( rawlog_path , template_path , break_threshold = 0 ) : new_path = template_path + 'order_logTemplate.txt' #words排序后的templates tag_temp_dir = { } tag_log_dir = { } tag_count = { } # 1.初始化template_list print ( "reading templates from" , template_path + 'logTemplate.txt' ) match = Match ( template_path + 'logTemplate.txt' ) result_dict = { } for i in range ( len ( match . template_list ) ) : # f=file(template_path+'template'+str(i+1)+'.txt','w') result_dict [ i + 1 ] = [ ] print ( "# of templates:" , len ( match . template_list ) ) cur_ID = 0 f = file ( template_path + 'logSequence.txt' , 'w' ) out_list = [ ] n = 1 with open ( rawlog_path ) as IN : for line in IN : n += 1 if n % 2000 == 0 : print ( 'cur' , n ) cur_ID += 1 #2.匹配模板 line = line . strip ( ) l = line . split ( ) cur_time = l [ 0 ] tag = match . matchTemplateByType ( line ) # if tag not in tag_temp_dir: #     tag_log_dir[tag]=' '.join(l[1:]) #     tag_temp_dir[tag]=match.template_list[tag-1] #print tag_log_dir[tag] #print tag_temp_dir[tag] #print '' # print ' '.join(l) # print "tag:"+str(tag), # print match.template_list[tag-1],'\n' result_dict [ tag ] . append ( cur_ID ) out_list . append ( str ( cur_time ) + ' ' + str ( tag ) + '\n' ) # f.writelines(str(cur_time)+' '+str(tag)+'\n') if break_threshold != 0 and cur_ID > break_threshold : break for line in out_list : f . writelines ( line )