-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for extracting multiple emojis in text and tests
- Loading branch information
1 parent
e5788e7
commit b295f19
Showing
6 changed files
with
163 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
""" Package Initialization file. """ | ||
|
||
from emosent.emosent import EMOJI_SENTIMENT_DICT, get_emoji_sentiment_rank | ||
from emosent.emosent import EMOJI_SENTIMENT_DICT, get_emoji_sentiment_rank, \ | ||
get_emoji_sentiment_rank_multiple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
python -m unittest tests/test_emosent.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,20 +7,20 @@ | |
|
||
with open( | ||
path.join(path.abspath(path.dirname(__file__)), 'README.md'), | ||
encoding='utf-8') as f: | ||
LONG_DESCRIPTION = f.read() | ||
encoding='utf-8' | ||
) as readme_file: | ||
LONG_DESCRIPTION = readme_file.read() | ||
|
||
setup( | ||
name='emosent-py', | ||
packages=['emosent'], | ||
version='0.1.6', | ||
version='0.1.7', | ||
license='MIT', | ||
description='Python module to get Sentiment Rankings for Unicode Emojis.', | ||
long_description=LONG_DESCRIPTION, | ||
long_description_content_type='text/markdown', | ||
author='Fintel Labs Inc.', | ||
author_email='[email protected]', | ||
url='https://fintel.ai', | ||
author='Omkar P', | ||
url='https://github.com/omkar-foss/emosent-py', | ||
download_url=( | ||
'https://github.com/FintelLabs/emosent-py/archive/master.zip' | ||
), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
""" | ||
Unit tests for this project. | ||
""" | ||
|
||
import unittest | ||
from emosent import get_emoji_sentiment_rank, get_emoji_sentiment_rank_multiple | ||
|
||
|
||
class TestEmosent(unittest.TestCase): | ||
|
||
def test_basic_ranking(self): | ||
print('\ntest_basic_ranking: It checks for basic ranking functionality\n') | ||
emoji = '❤' | ||
expected_result = { | ||
'unicode_codepoint': '0x2764', | ||
'occurrences': 8050, | ||
'position': 0.746943086, | ||
'negative': 355.0, | ||
'neutral': 1334.0, | ||
'positive': 6361.0, | ||
'unicode_name': 'HEAVY BLACK HEART', | ||
'unicode_block': 'Dingbats', | ||
'sentiment_score': 0.746 | ||
} | ||
result = get_emoji_sentiment_rank(emoji) | ||
self.assertDictEqual(result, expected_result) | ||
|
||
emoji = '' | ||
result = get_emoji_sentiment_rank(emoji) | ||
self.assertIsNone(result) | ||
|
||
emoji = ' ' | ||
result = get_emoji_sentiment_rank(emoji) | ||
self.assertIsNone(result) | ||
|
||
def test_emojis_text_extraction(self): | ||
print( | ||
'\ntest_emojis_text_extraction: It checks for multiple emojis in ' | ||
'text functionality\n' | ||
) | ||
text = 'that is amazing! 😂❤' | ||
expected_result = [ | ||
{ | ||
'text_position': 17, | ||
'emoji_sentiment_rank': { | ||
'unicode_codepoint': '0x1f602', | ||
'occurrences': 14622, | ||
'position': 0.805100583, | ||
'negative': 3614.0, | ||
'neutral': 4163.0, | ||
'positive': 6845.0, | ||
'unicode_name': 'FACE WITH TEARS OF JOY', | ||
'unicode_block': 'Emoticons', | ||
'sentiment_score': 0.221 | ||
} | ||
}, | ||
{ | ||
'text_position': 18, | ||
'emoji_sentiment_rank': { | ||
'unicode_codepoint': '0x2764', | ||
'occurrences': 8050, | ||
'position': 0.746943086, | ||
'negative': 355.0, | ||
'neutral': 1334.0, | ||
'positive': 6361.0, | ||
'unicode_name': 'HEAVY BLACK HEART', | ||
'unicode_block': 'Dingbats', | ||
'sentiment_score': 0.746 | ||
} | ||
} | ||
] | ||
result = get_emoji_sentiment_rank_multiple(text) | ||
self.assertListEqual(result, expected_result) | ||
|
||
text = '' | ||
result = get_emoji_sentiment_rank_multiple(text) | ||
self.assertListEqual(result, []) | ||
|
||
text = ' ' | ||
result = get_emoji_sentiment_rank_multiple(text) | ||
self.assertListEqual(result, []) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |