added optional argoment to specify target emojis in sentiment_vector_to_emojis
This commit is contained in:
parent
598d0f8315
commit
247de9dce2
@ -111,14 +111,24 @@ def emoji_distance(e1,e2):
|
||||
# In[27]:
|
||||
|
||||
|
||||
def sentiment_vector_to_emoji(v1, only_emoticons=True):
|
||||
def sentiment_vector_to_emoji(v1, only_emoticons=True, custom_target_emojis=None):
|
||||
|
||||
target_sentiment_emojis = (list_sentiment_emoticon_vectors if only_emoticons else list_sentiment_vectors)
|
||||
target_emojis = (list_emoticon_emojis if only_emoticons else list_emojis)
|
||||
|
||||
# filter target emojis by custom emojis, if some are given:
|
||||
if custom_target_emojis is not None:
|
||||
binary_filter_mask = np.isin(target_emojis, custom_target_emojis)
|
||||
target_sentiment_emojis = target_sentiment_emojis[binary_filter_mask]
|
||||
target_emojis = target_emojis[binary_filter_mask]
|
||||
|
||||
#more efficient approach for min distance
|
||||
distances = (list_sentiment_emoticon_vectors if only_emoticons else list_sentiment_vectors) - v1
|
||||
distances = target_sentiment_emojis - v1
|
||||
distances = np.linalg.norm(distances, axis=1)
|
||||
#find min entry
|
||||
min_entry = np.argmin(distances)
|
||||
|
||||
return (list_emoticon_emojis if only_emoticons else list_emojis)[min_entry]
|
||||
return target_emojis[min_entry]
|
||||
|
||||
#version for dics
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user