Emoji Polarity Analyzers

parent 1cff93de
This diff could not be displayed because it is too large.
......@@ -33,7 +33,7 @@ class Analyzer(ABC):
resultOfAnalisys= []
for i in analyzeResult:
resultOfAnalisys.append(i)
if isinstance(resultOfAnalisys[0], Sequence):
if len(resultOfAnalisys) >0 and isinstance(resultOfAnalisys[0], Sequence):
sequence.children[tag] = resultOfAnalisys
else:
sequence.metadata[tag] = resultOfAnalisys
......
......@@ -44,7 +44,6 @@ class ComplexityAnalyzer(Analyzer):
min_max_list: the minimum of maximum tree depths.
max_max_list: the maximum of maximum tree depths.
mean_max_list: the mean of maximum tree depths.
"""
......@@ -53,7 +52,7 @@ class ComplexityAnalyzer(Analyzer):
Create a complexity analyzer from an input object.
Args:
rutaArchivoCrea: the file that contains the most frequence words of spanish language
rutaArchivoCrea: the path of the file that contains the most frequence words of spanish language
isMetadata: boolean, if the result of the analyzer is stored in metadata (True) or in children(False)
"""
self.nlp = nlp
......
from typing import Optional
from textflow.Analyzer import Analyzer
import emoji
class EmojiPolarityAnalyzer(Analyzer):
"""
A class that provides methods to analyze the polarity of the text of a sequence.
Attributes:
positiveEmoji: a list with the positive emojis
negativeEmoji: a list with the negative emojis
"""
def __init__(self, positiveEmojiPath = "textflow\emoticons\emojiPositive.txt", negativeEmojiPath = 'textflow\emoticons\emojiNegative.txt'):
"""
Create a text emoji polarity analyzer from an input object.
Args:
positiveEmojiPath = the path of the file that contains the positive text emojis.
negativeEmojiPath = the path of the file that contains the negative text emojis.
"""
positiveEmoji = []
negativeEmoji = []
with open(positiveEmojiPath) as archivo:
positiveEmoji = archivo.readlines()
with open(negativeEmojiPath) as archivo:
negativeEmoji = archivo.readlines()
self.positiveEmoji = []
self.negativeEmoji = []
for posEmoji in positiveEmoji:
self.positiveEmoji.append(chr(int(posEmoji.replace("\n", "").replace(" ", "")[2:], 16)).encode('unicode-escape').decode('unicode-escape'))
for negEmoji in negativeEmoji:
self.negativeEmoji.append(chr(int(negEmoji.replace("\n", "").replace(" ", "")[2:], 16)).encode('unicode-escape').decode('unicode-escape'))
def analyze(self, sequence, tag, levelOfAnalyzer, levelOfResult:Optional[str] = ""):
"""
Analyze a sequence with a text emoji polarity function.
Args:
sequence: the Sequence we want to analyze.
tag: the label to store the analysis result.
levelOfAnalyzer: the path of the sequence level to analyze inside of the result.
levelOfResult: the path of the sequence level to store the result.
"""
super().analyze(self.emojiPolarity,sequence, tag, levelOfAnalyzer, levelOfResult, True)
def emojiPolarity(self, arrayText):
"""
Function that analyzes the polarity of a list of texts.
Args:
arrayText: list that contains the texts that we want to analyze
Returns:
A list with the dictionaries. Each dictionary contains the result
of the analysis of the corresponding text.
"""
arrayResults =[]
for text in arrayText:
dicNumEmoji = {"positive": 0, "negative": 0}
emojiFounded = {"positive": set(), "negative": set()}
listEmojis=emoji.emoji_lis(text)
for dictEmoji in listEmojis:
if dictEmoji['emoji'] in self.positiveEmoji:
dicNumEmoji['positive'] += 1
emojiFounded['positive'].add(dictEmoji['emoji'])
elif dictEmoji['emoji'] in self.negativeEmoji:
dicNumEmoji['negative'] += 1
emojiFounded['negativetive'].add(dictEmoji['emoji'])
if(dicNumEmoji['positive'] > 0 or dicNumEmoji['negative'] >0):
percentagePolarity = {"positive": dicNumEmoji['positive']/(dicNumEmoji['positive']+dicNumEmoji['negative']), "negative": dicNumEmoji['negative']/(dicNumEmoji['positive']+dicNumEmoji['negative'])}
else:
percentagePolarity = {"positive": 0, "negative": 0}
tep = {
"numEmojisPolarity": dicNumEmoji,
"percentageEmojisPolarity": percentagePolarity,
"distinctEmojiFounded": emojiFounded
}
arrayResults.append(tep)
return arrayResults
from typing import Optional
from textflow.Analyzer import Analyzer
import re
class TextEmojiPolarityAnalyzer(Analyzer):
"""
A class that provides methods to analyze the polarity of the text of a sequence.
Attributes:
positiveEmoji: a list with the positive text emojis
negativeEmoji: a list with the negative text emojis
"""
def __init__(self, positiveEmojiPath = "textflow\emoti-sp\emojiTextPositive.txt", negativeEmojiPath = 'textflow\emoti-sp\emojiTextNegative.txt'):
"""
Create a text emoji polarity analyzer from an input object.
Args:
positiveEmojiPath = the path of the file that contains the positive text emojis.
negativeEmojiPath = the path of the file that contains the negative text emojis.
"""
self.positiveEmoji = []
self.negativeEmoji = []
with open(positiveEmojiPath) as archivo:
self.positiveEmoji = archivo.readlines()
with open(negativeEmojiPath) as archivo:
self.negativeEmoji = archivo.readlines()
def analyze(self, sequence, tag, levelOfAnalyzer, levelOfResult:Optional[str] = ""):
"""
Analyze a sequence with a text emoji polarity function.
Args:
sequence: the Sequence we want to analyze.
tag: the label to store the analysis result.
levelOfAnalyzer: the path of the sequence level to analyze inside of the result.
levelOfResult: the path of the sequence level to store the result.
"""
super().analyze(self.textEmojiPolarity,sequence, tag, levelOfAnalyzer, levelOfResult, True)
def textEmojiPolarity(self, arrayText):
"""
Function that analyzes the polarity of a list of texts.
Args:
arrayText: list that contains the texts that we want to analyze
Returns:
A list with the dictionaries. Each dictionary contains the result
of the analysis of the corresponding text.
"""
arrayResults =[]
for text in arrayText:
dicNumEmoji = {"positive": 0, "negative": 0}
textEmojiFounded = {"positive": [], "negative": []}
for positiveEmoji in self.positiveEmoji:
coincidencias = re.findall(re.escape(positiveEmoji.replace("\n", "")), text)
if len(coincidencias) > 0:
dicNumEmoji['positive'] += len(coincidencias)
textEmojiFounded['positive'].append(positiveEmoji.replace("\n", ""))
for negativeEmoji in self.negativeEmoji:
coincidencias = re.findall(re.escape(negativeEmoji.replace("\n", "")), text)
if len(coincidencias) > 0:
dicNumEmoji['negative'] += len(coincidencias)
textEmojiFounded['negative'].append(negativeEmoji.replace("\n", ""))
if(dicNumEmoji['positive'] > 0 or dicNumEmoji['negative'] >0):
percentagePolarity = {"positive": dicNumEmoji['positive']/(dicNumEmoji['positive']+dicNumEmoji['negative']), "negative": dicNumEmoji['negative']/(dicNumEmoji['positive']+dicNumEmoji['negative'])}
else:
percentagePolarity = {"positive": 0, "negative": 0}
tep = {
"numTextEmojisPolarity": dicNumEmoji,
"percentageTextEmojiPolarity": percentagePolarity,
"distinctTextEmojiFounded": textEmojiFounded
}
arrayResults.append(tep)
return arrayResults
:(
=(
:-(
:'-(
:'(
>:[
:-c
:c
:-<
:<
:-[
:[
:{
:-||
:@
Q.Q
D:<
D:
D8
D;
D=
DX
v.v
D-':
:|
:-|
:/
:\
=/
=\
:L
=L
:S
>.<
>:\
>:/
:-###..
:##..
<:-|
(>_<)
(>_<)>
('_')
(/_;)
(T_T)
(;_;)
(ToT)
:)
=)
:D
:d
;)
:-)
:))
:)))
(;
:P
:p
:0)
:]
:3
:c)
:>
=]
8)
=)
:}
:^)
:-D
:-d
8-D
8-d
8D
x-D
xD
X-D
XD
xd
=-D
=D
=-3
=3
B^D
:'-)
:')
:*
:^*
( '}{' )
;-)
*-)
*)
;-]
;]
;D
;^)
:-,
#-)
^_^
>^_^<
<^!^>
(^.^)
(^_^.)
(^_^)
(^^)
(^J^)
(^-^)
(*^^)v
(^^)v
(^_^)v
( ^)o(^ )
(^O^)
(^o^)
U+1F610
U+1F480
U+1F637
U+1F632
U+1F620
U+1F627
U+1FAE4
U+1F47B
U+1F616
U+1F47A
U+1F629
U+1F971
U+1F641
U+1F62D
U+1F47F
U+1F623
U+1F628
U+1F640
U+1F5A4
U+1F625
U+1F614
U+1F630
U+1F922
U+1F63E
U+2620
U+1F622
U+1F479
U+1F615
U+2639
U+1F61E
U+1F97A
U+1F61F
U+1F92C
U+1F635
U+1F62F
U+1F621
U+1F915
U+1F624
U+1F912
U+1F626
U+1F44E
U+1F974
U+1F927
U+1F63F
U+200D
U+1F62A
U+1F494
U+1F4AB
U+1F62B
U+1F611
U+1F613
U+1F635
U+1F925
U+1F92E
U+1F921
U+1F612
U+1F631
U+1F4A2
U+1F62E
U+1F633
U+1F4A9
\ No newline at end of file
U+1F972
U+1F979
U+1F49C
U+1F497
U+1F91E
U+1F491
U+1F92A
U+1F38A
U+1F468
U+1FAE0
U+1FA75
U+1FAE1
U+1F61C
U+1F63A
U+1F48B
U+1F61D
U+2764
U+1F63B
U+263A
U+1F643
U+1F92D
U+1FAF6
U+1F638
U+1F90D
U+1FA79
U+1F63D
U+1F639
U+200D
U+1F604
U+1F90E
U+1FAE2
U+270C
U+1F60D
U+1F49B
U+1F61A
U+1F61B
U+1F468
U+1F525
U+1F60C
U+1F911
U+1F44C
U+1F48B
U+1F917
U+1F491
U+1F619
U+1F924
U+2728
U+2764
U+1F918
U+1F499
U+1F49E
U+1F496
U+1F970
U+1F60A
U+1F60E
U+1F92B
U+1F648
U+1F64A
U+1F60F
U+2763
U+1F60B
U+1F605
U+1FAE3
U+1FAF0
U+1FA77
U+1F49F
U+1F48F
U+1F44D
U+1F469
U+1F389
U+1F63C
U+1F49A
U+1F607
U+1F973
U+1F642
U+1F919
U+1FA76
U+1F914
U+1F48C
U+1F923
U+1F649
U+1F44F
U+1F600
U+1F601
U+1F493
U+1F4AF
U+1F498
U+1F618
U+1F608
U+1F602
U+1F49D
U+1F91F
U+1F929
U+1F9E1
U+1F469
U+1F495
U+1F609
U+1F606
U+1F617
U+1F603
U+FE0F
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment