Skip to content

Commit 13a83e5

Browse files
committed
get_emoticons function should return dict instead of set
1 parent c8280da commit 13a83e5

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

nidaba/features/_util/question.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def get_emoticons(text):
161161
"""
162162
Return a list of emoticons in the given text.
163163
:param text: String.
164-
:return: List of emoticons.
164+
:return: Dictionary - emoticons as keys and their count as values.
165165
"""
166166
emoticons = (":-) :) :D :o) :] :3 :c) :> =] 8) =) :} :^) :っ) :-D 8-D 8D"
167167
"x-D xD X-D XD =-D =D =-3 =3 B^D :-)) >:[ :-( :( :-c :c :-<"
@@ -174,4 +174,5 @@ def get_emoticons(text):
174174
":-###.. :###.. <:-| ಠ_ಠ <*)))-{ ><(((*> ><> \o/ *\0/*"
175175
"@}-;-'--- @>-->-- ~(_8^(I) 5:-) ~:-\ //0-0\\ *<|:-) =:o]"
176176
",:-) 7:^] <3 </3").split()
177-
return frozenset(emoticons).intersection(text.split())
177+
return dict((emoticon, text.count(emoticon)) for emoticon in emoticons
178+
if emoticon in text.split())

nidaba/features/test/test_questions_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_get_emoticons():
216216
Test the get_emoticons() _util function.
217217
:return: None
218218
"""
219-
text = 'these are emoticons :) :D :-) '
220-
assert question.get_emoticons(text) == {':)', ':D', ':-)'}
221-
code = 'this is code x = [:D], y = [0:3], ED8 = 12'
222-
assert question.get_emoticons(code) != {':D', '0:3', 'D8'}
219+
text = 'these are emoticons :) :D :)'
220+
assert question.get_emoticons(text) == {':)': 2, ':D': 1}
221+
code = 'this is code x = [:D], y = [0:3], ED8 = [:D]'
222+
assert question.get_emoticons(code) != {':D': 2, '0:3': 1}

0 commit comments

Comments
 (0)