Ejemplo n.º 1
0
def set_opinion_term_polarity(terms_list):
    """Set opinion term polarity.

    Args:
        terms_list (list): list of opinion terms
    """
    first = terms_list[0]
    new_term = first.term

    positive_pol = 0
    negative_pol = 0
    curr_polarity = None
    for term in terms_list:
        try:
            curr_polarity = term.term_polarity
        except Exception as e:
            print("extracted_term missing term_polarity: " + str(e))
        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
    new_term_polarity = Polarity.UNK
    if positive_pol >= negative_pol and positive_pol > 0:
        new_term_polarity = Polarity.POS
    elif negative_pol >= positive_pol and negative_pol > 0:
        new_term_polarity = Polarity.NEG

    return OpinionTerm(new_term, new_term_polarity)
Ejemplo n.º 2
0
def read_generic_lex_from_file(file_name):
    """Read generic opinion lex for term acquisition.

    Args:
        file_name (string): name of csv file
    """
    with open(file_name) as f:
        reader = csv.DictReader(f)
        dict_list = {}
        for row in reader:
            if row["UsedForAcquisition"] == 'Y':
                key_term = row["Term"] if len(row) > 0 else ""
                terms = []
                if len(row) > 0:
                    terms = key_term.split()
                polarity = Polarity[row["Polarity"]]
                dict_list[key_term] = OpinionTerm(terms, polarity)
    return dict_list