(self, candidate_phrase,
                                       max_phrase_len=25, 
                                       func_word_num=1, stop_word_num=0)
return True
按照宽松规则筛选候选短语，对词性和停用词宽松
按照宽松规则筛选候选短语，对词性和停用词宽松
按照宽松规则筛选候选短语，对词性和停用词宽松
def _loose_candidate_phrases_rules(self, candidate_phrase,
                                       max_phrase_len=25, 
                                       func_word_num=1, stop_word_num=0):
        ''' 按照宽松规则筛选候选短语，对词性和停用词宽松 '''
        # 条件一：一个短语不能超过 12个 token
        if len(candidate_phrase) > 12:
            return False

        # 条件二：一个短语不能超过 25 个 char
        if len(''.join([item[0] for item in candidate_phrase])) > max_phrase_len:
            return False

        # 条件三：一个短语中不能出现超过一个虚词
        more_than_one_func_word_count = 0
        for item in candidate_phrase:
            if item[1] in self.pos_exception:
                more_than_one_func_word_count += 1
        if more_than_one_func_word_count > func_word_num:
            return False

        # 条件四：短语的前后不可以是虚词、停用词，短语末尾不可是动词
        if candidate_phrase[0][1] in self.pos_exception:
            return False
        if candidate_phrase[len(candidate_phrase)-1][1] in self.pos_exception:
            return False
        if candidate_phrase[len(candidate_phrase)-1][1] in ['v', 'd']:
            return False
        if candidate_phrase[0][0] in self.stop_words:
            return False 
        if candidate_phrase[len(candidate_phrase)-1][0] in self.stop_words:
            return False

        # 条件五：短语中不可以超过规定个数的停用词
        has_stop_words_count = 0
        for item in candidate_phrase:
            if item[0] in self.stop_words:
                has_stop_words_count += 1
        if has_stop_words_count > stop_word_num:
            return False
        return True
def _loose_candidate_phrases_rules ( self , candidate_phrase , max_phrase_len = 25 , func_word_num = 1 , stop_word_num = 0 ) : # 条件一：一个短语不能超过 12个 token if len ( candidate_phrase ) > 12 : return False # 条件二：一个短语不能超过 25 个 char if len ( '' . join ( [ item [ 0 ] for item in candidate_phrase ] ) ) > max_phrase_len : return False # 条件三：一个短语中不能出现超过一个虚词 more_than_one_func_word_count = 0 for item in candidate_phrase : if item [ 1 ] in self . pos_exception : more_than_one_func_word_count += 1 if more_than_one_func_word_count > func_word_num : return False # 条件四：短语的前后不可以是虚词、停用词，短语末尾不可是动词 if candidate_phrase [ 0 ] [ 1 ] in self . pos_exception : return False if candidate_phrase [ len ( candidate_phrase ) - 1 ] [ 1 ] in self . pos_exception : return False if candidate_phrase [ len ( candidate_phrase ) - 1 ] [ 1 ] in [ 'v' , 'd' ] : return False if candidate_phrase [ 0 ] [ 0 ] in self . stop_words : return False if candidate_phrase [ len ( candidate_phrase ) - 1 ] [ 0 ] in self . stop_words : return False # 条件五：短语中不可以超过规定个数的停用词 has_stop_words_count = 0 for item in candidate_phrase : if item [ 0 ] in self . stop_words : has_stop_words_count += 1 if has_stop_words_count > stop_word_num : return False return True