Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

modified get_emoticons util functions #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions nidaba/features/_util/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,25 @@ def python_docs_urls(s):
result = regex.findall(s)

return result


def get_emoticons(text):
"""
Return a dictionary of emoticons & their count in the given text.
:param text: String or List of words.
:return: Dictionary - emoticons as keys and their count as values.
"""
emoticons = (":-) :) :D :o) :] :3 :c) :> =] 8) =) :} :^) :っ) :-D 8-D 8D"
"x-D xD X-D XD =-D =D =-3 =3 B^D :-)) >:[ :-( :( :-c :c :-<"
":っC :< :-[ :[ :{ ;( :-|| :@ >:( :'-( :'( :'-) :')D :< D:"
"D8 D; D= DX v.v D-': >:O :-O:O:-o:o 8-0 O_O o-o O_o o_O o_o"
"O-O :* :^* ;^) :-, >:P :-P :P X-P x-p xp XP :-p :p =p :-Þ"
">:\ >:/ :-/ :-. :/ :\ =/ =\ :L =L :S >.< :| :-| :$ :-X :X"
":-# :# O:-) 0:-3 0:3 0:-) 0:) 0;^) >:) >;) >:-) }:-) }:)"
"3:-) 3:) o/\o ^5 >_>^ ^<_< |;-) |-O :-J :-& :& #-) %-) %)"
":-###.. :###.. <:-| ಠ_ಠ <*)))-{ ><(((*> ><> \o/ *\0/*"
"@}-;-'--- @>-->-- ~(_8^(I) 5:-) ~:-\ //0-0\\ *<|:-) =:o]"
",:-) 7:^] <3 </3").split()
if isinstance(text, str):
text = text.split()
return Counter(word for word in text if word in emoticons)
14 changes: 14 additions & 0 deletions nidaba/features/test/test_questions_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,17 @@ def test_python_docs_urls():

for url in urls:
assert url in result


def test_get_emoticons():
"""
Test the get_emoticons() _util function.
:return: None
"""
text = ('these :) are emoticons:D :) :D :) '
'This is my code :] x = text[2:], y = code[0:3][0:-3], z = lst[:3]'
'Ive been to the (st{o}re). Thats a nice joke 😆 😆 😆 😛 :D ')
assert question.get_emoticons(text) == {':)': 3, ':D': 2, ':]': 1}
code = ['This', 'is', 'my', 'code', ':]', 'x', '=', 'text[2:],', 'y',
'=', 'code[0:3][0:-3],', 'z', '=', 'lst[:3]', ':D']
assert question.get_emoticons(code) == {':]': 1, ':D': 1}