예제 #1
0
def get_sentiment_inverse(user_id_1, user_id_2, common_hashtags=[]):
    """returns the sum of the inverses of the adoptions for each common hashtag
    for which the users share the same opinion
    """
    inverse = 0
    if not common_hashtags:
        common_hashtags = get_common_hashtags(user_id_1, user_id_2)

    for hashtag in common_hashtags:
        pol_1 = determine_polarity((_USER_TOPIC_DICT[user_id_1][hashtag][:3]))
        pol_2 = determine_polarity((_USER_TOPIC_DICT[user_id_2][hashtag][:3]))

        if pol_1 == pol_2:
            inverse += 1 / len(_TOPIC_USER_DICT[hashtag])

    return inverse
예제 #2
0
def get_sentiment_adamic_adar(user_id_1, user_id_2, common_hashtags=[]):
    """returns the sum of tha adamic adar distances for all common hashtags for
    which the users share the same opinion
    """
    adamic_adar_score = 0
    if not common_hashtags:
        common_hashtags = get_common_hashtags(user_id_1, user_id_2)

    for hashtag in common_hashtags:
        pol_1 = determine_polarity((_USER_TOPIC_DICT[user_id_1][hashtag][:3]))
        pol_2 = determine_polarity((_USER_TOPIC_DICT[user_id_2][hashtag][:3]))

        if pol_1 == pol_2:
            adamic_adar_score += 1 / math.log(len(_TOPIC_USER_DICT[hashtag]))

    return adamic_adar_score
예제 #3
0
def get_sentiment_disagreement(user_id_1, user_id_2, common_hashtags=[]):
    """returns the amount of common hashtags for which the two users expressed
    opposite sentiment. Excluding hashtags for which the users expressed
    objective opinion.
    """
    disagreement_score = 0
    if not common_hashtags:
        common_hashtags = get_common_hashtags(user_id_1, user_id_2)

    for hashtag in common_hashtags:
        pol_1 = determine_polarity((_USER_TOPIC_DICT[user_id_1][hashtag][:3]))
        pol_2 = determine_polarity((_USER_TOPIC_DICT[user_id_2][hashtag][:3]))

        if pol_1 and pol_1 == -pol_2:
            disagreement_score += 1

    return disagreement_score
예제 #4
0
def get_sentiment_agreement(user_id_1, user_id_2,
                            exclude=[], common_hashtags=[]):
    """returns the amount of common hashtags for which the two user expressed
    the same sentiment. The parameter exclude is a list of sentiments that
    should not be taken into consideration when summing up the results.
    For example if exclude equals [1, 0] then sentiment agreement will be
    accumulated over topics affiliated only with negative sentiment (-1).
    """
    agreement_score = 0
    if not common_hashtags:
        common_hashtags = get_common_hashtags(user_id_1, user_id_2)

    for hashtag in common_hashtags:
        pol_1 = determine_polarity((_USER_TOPIC_DICT[user_id_1][hashtag][:3]))
        pol_2 = determine_polarity((_USER_TOPIC_DICT[user_id_2][hashtag][:3]))

        if pol_1 == pol_2 and pol_1 not in exclude:
            agreement_score += 1

    return agreement_score
예제 #5
0
def get_sentiment_rarest(user_id_1, user_id_2, common_hashtags=[]):
    """returns the adoption of the rarest common hashtag excluding hashtags
    for which the users expressed objective opinion. Returns -1 if no common
    hashtag with polar agreement is found.
    """
    adoption = maxint
    if not common_hashtags:
        common_hashtags = get_common_hashtags(user_id_1, user_id_2)

    for hashtag in common_hashtags:
        pol_1 = determine_polarity((_USER_TOPIC_DICT[user_id_1][hashtag][:3]))
        pol_2 = determine_polarity((_USER_TOPIC_DICT[user_id_2][hashtag][:3]))

        if pol_1 and pol_1 == pol_2:
            adoption = min(adoption, len(_TOPIC_USER_DICT[hashtag]))

    if adoption != maxint:
        return adoption
    else:
        return -1
예제 #6
0
def get_size_of_common_hashtags(user_id_1, user_id_2, common_hashtags=[]):
    """returns the mean size of common hashtags by summing up the adoption of
    all hashtags for which the users share the same opinion and diving that
    by the sentiment agreement of the users
    """
    mean_size = 0
    if not common_hashtags:
        common_hashtags = get_common_hashtags(user_id_1, user_id_2)

    sentiment_agreement = get_sentiment_agreement(
            user_id_1, user_id_2, common_hashtags=common_hashtags)

    for hashtag in common_hashtags:
        pol_1 = determine_polarity((_USER_TOPIC_DICT[user_id_1][hashtag][:3]))
        pol_2 = determine_polarity((_USER_TOPIC_DICT[user_id_2][hashtag][:3]))

        if pol_1 == pol_2:
            mean_size += len(_TOPIC_USER_DICT[hashtag])

    if sentiment_agreement:
        return mean_size / sentiment_agreement
    else:
        return -1