(self, logs, para)
return all_paths
Args:
            pids: a list, pid 集合
            logs: a list, 日志集合,包含pid和分词结果
            date: 保存date,用于将不同日期的模板保存到不同的文件中
            last_templates: 上一轮迭代的模板
            last_words_fre: 上一轮迭代的词频
            fre_word_path: 保存单词频率的文件路径

        Returns:
            all_paths: a dict, 包含了特征树的所有路径,每一条路径是一个模板
            words_frequency: a list, 包含了本轮迭代的词频结果
Args:
            pids: a list, pid 集合
            logs: a list, 日志集合,包含pid和分词结果
            date: 保存date,用于将不同日期的模板保存到不同的文件中
            last_templates: 上一轮迭代的模板
            last_words_fre: 上一轮迭代的词频
            fre_word_path: 保存单词频率的文件路径
Args : pids : a list pid 集合 logs : a list 日志集合 包含pid和分词结果 date : 保存date 用于将不同日期的模板保存到不同的文件中 last_templates : 上一轮迭代的模板 last_words_fre : 上一轮迭代的词频 fre_word_path : 保存单词频率的文件路径
def do(self, logs, para):
        """
        Args:
            pids: a list, pid 集合
            logs: a list, 日志集合,包含pid和分词结果
            date: 保存date,用于将不同日期的模板保存到不同的文件中
            last_templates: 上一轮迭代的模板
            last_words_fre: 上一轮迭代的词频
            fre_word_path: 保存单词频率的文件路径

        Returns:
            all_paths: a dict, 包含了特征树的所有路径,每一条路径是一个模板
            words_frequency: a list, 包含了本轮迭代的词频结果
        """

        template_path = para['template_path']
        fre_word_path = para['fre_word_path']
        leaf_num = para['leaf_num']
        CUTTING_PERCENT = para['CUTTING_PERCENT']
        plot_flag = para['plot_flag']

        if not logs:
            return {}

        self.paths = []
        self._nodes = []

        lines, pids = [], []
        words_frequency = {}

        for log in logs:
            (pid, words) = log
            if pid not in pids:
                pids.append(pid)
            lines.append(log)  # lines保存（pid,words）的元组，其实就是logs，这个变量的存在没有意义

            # 统计词频
            for w in words:
                # if len(w) == 1:  # 单个字母的词无意义
                #     continue
                if w not in words_frequency:
                    words_frequency[w] = 0

                words_frequency[w] += 1

        """ 按照词频进行排序,从高到低
        高频度的词具有较高的权重,应该处在父节点的位置
        """
        words_frequency = sorted(words_frequency.items(), key=lambda x: (x[1], x[0]), reverse=True)
        words_frequency = [x[0] for x in words_frequency]


        f = open(fre_word_path, 'w')
        for w in words_frequency:
            f.writelines(w+'\n')

        self._init_tree(pids)
        self.auto_temp(lines, words_frequency, para)
        #self.auto_temp(lines, words_frequency, leaf_num, CUTTING_PERCENT=CUTTING_PERCENT)

        if plot_flag == 1:
            #画树，dratTreee，画图，放到输出模板之前，是因为traversal_tree函数会修改is_end变量的值，存在bug！！
            self.drawTree()#画树，dratTreee，画图



        # 遍历特征树,每条路径作为一个模板
        all_paths = {}

        for pid in self.tree_list:
            all_paths[pid] = []




            path = self.traversal_tree(self.tree_list[pid])

            for template in path[1]:
                all_paths[pid].append(template)

            # 大集合优先
            # 有的模板是另外一个模板的子集,此时要保证大集合优先`
            all_paths[pid].sort(key=lambda x: len(x), reverse=True)
        # count=0

        typeList = []



        # 将每条模板存储到对应的pid文件夹中
        f = open(template_path, 'w')
        i = 1
        for pid in all_paths:
            for path in all_paths[pid]:
                # count+=1
                #print (i, pid)
                # print (i, pid, end=' ')
                # 首先把pid保存下来
                f.write(pid + " ") #不保存index
                #f.write(str(i)+' '+pid + " ")#保存index，从1开始
                for w in path:
                    #print (w)
                    # print (w, end=' ')
                    f.write(w + " ")
                # print ( '')
                f.write("\n")
                i += 1
        f.close()
        # print "\ntemplate_count:",count
        return all_paths
def do ( self , logs , para ) : template_path = para [ 'template_path' ] fre_word_path = para [ 'fre_word_path' ] leaf_num = para [ 'leaf_num' ] CUTTING_PERCENT = para [ 'CUTTING_PERCENT' ] plot_flag = para [ 'plot_flag' ] if not logs : return { } self . paths = [ ] self . _nodes = [ ] lines , pids = [ ] , [ ] words_frequency = { } for log in logs : ( pid , words ) = log if pid not in pids : pids . append ( pid ) lines . append ( log ) # lines保存（pid,words）的元组，其实就是logs，这个变量的存在没有意义 # 统计词频 for w in words : # if len(w) == 1:  # 单个字母的词无意义 #     continue if w not in words_frequency : words_frequency [ w ] = 0 words_frequency [ w ] += 1 """ 按照词频进行排序,从高到低
        高频度的词具有较高的权重,应该处在父节点的位置
        """ words_frequency = sorted ( words_frequency . items ( ) , key = lambda x : ( x [ 1 ] , x [ 0 ] ) , reverse = True ) words_frequency = [ x [ 0 ] for x in words_frequency ] f = open ( fre_word_path , 'w' ) for w in words_frequency : f . writelines ( w + '\n' ) self . _init_tree ( pids ) self . auto_temp ( lines , words_frequency , para ) #self.auto_temp(lines, words_frequency, leaf_num, CUTTING_PERCENT=CUTTING_PERCENT) if plot_flag == 1 : #画树，dratTreee，画图，放到输出模板之前，是因为traversal_tree函数会修改is_end变量的值，存在bug！！ self . drawTree ( ) #画树，dratTreee，画图 # 遍历特征树,每条路径作为一个模板 all_paths = { } for pid in self . tree_list : all_paths [ pid ] = [ ] path = self . traversal_tree ( self . tree_list [ pid ] ) for template in path [ 1 ] : all_paths [ pid ] . append ( template ) # 大集合优先 # 有的模板是另外一个模板的子集,此时要保证大集合优先` all_paths [ pid ] . sort ( key = lambda x : len ( x ) , reverse = True ) # count=0 typeList = [ ] # 将每条模板存储到对应的pid文件夹中 f = open ( template_path , 'w' ) i = 1 for pid in all_paths : for path in all_paths [ pid ] : # count+=1 #print (i, pid) # print (i, pid, end=' ') # 首先把pid保存下来 f . write ( pid + " " ) #不保存index #f.write(str(i)+' '+pid + " ")#保存index，从1开始 for w in path : #print (w) # print (w, end=' ') f . write ( w + " " ) # print ( '') f . write ( "\n" ) i += 1 f . close ( ) # print "\ntemplate_count:",count return all_paths