def generate_final_opinion_candidates_list(opinion_candidate_list_raw, final_opinion_candidates_list, frequency_threshold): """Generate final opinion candidates list from raw opinion candidate list. Args: opinion_candidate_list_raw (dict): key = term, value = lists of extracted terms. final_opinion_candidates_list (list): list of final opinion candidates frequency_threshold (int): minimum freq. for qualifying term """ for extracted_term_list in opinion_candidate_list_raw.values(): positive_pol = 0 negative_pol = 0 if len(extracted_term_list) >= frequency_threshold: for ex_term in extracted_term_list: curr_polarity = ex_term.term_polarity if curr_polarity is not None: if curr_polarity == Polarity.POS: positive_pol = positive_pol + 1 if curr_polarity == Polarity.NEG: negative_pol = negative_pol + 1 # set polarity according majority vote term_polarity = Polarity.UNK if positive_pol > negative_pol and positive_pol > 0: term_polarity = Polarity.POS elif negative_pol >= positive_pol and negative_pol > 0: term_polarity = Polarity.NEG term = extracted_term_list[0] qualified_term = QualifiedTerm(term.term, term.pos, len(extracted_term_list), term_polarity) final_opinion_candidates_list.append(qualified_term) return final_opinion_candidates_list
def generate_final_aspect_candidates_list(aspect_candidate_list_raw, final_aspect_candidates_list, frequency_threshold): """Generate final aspect candidates list from map. Args: aspect_candidate_list_raw (dict): key = term, value = lists of candidate terms. final_aspect_candidates_list (list): list of final aspect candidates frequency_threshold (int): minimum freq. for qualifying term """ term_polarity = Polarity.UNK for extracted_term_list in aspect_candidate_list_raw.values(): if len(extracted_term_list) >= frequency_threshold: term = extracted_term_list[0] qualified_term = QualifiedTerm(term.term, term.pos, len(extracted_term_list), term_polarity) final_aspect_candidates_list.append(qualified_term) return final_aspect_candidates_list