Created
July 11, 2018 12:55
-
-
Save Proteusiq/dbf45b2dce4141d8c3b9b12383dde525 to your computer and use it in GitHub Desktop.
emojipy.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
import re | |
from collections import Counter | |
# eyes [nose] mouth | mouth [nose] eyes pattern | |
emoticons = r"(?:[<>]?[:;=8][\-o\*\']?[\)\]\(\[dDpP/\:\}\{@\|\\]|[\)\]\(\[dDpP/\:\}\{@\|\\][\-o\*\']?[:;=8][<>]?)" | |
emoticon_re = re.compile(emoticons, re.VERBOSE | re.I | re.UNICODE) | |
def has_emoji(texts,get_emoji=False): | |
set_emoji = set(emoticon_re.findall(texts)) | |
for text in texts.split(): | |
if text in set_emoji: | |
if get_emoji: | |
return set_emoji | |
else: | |
return True | |
return False | |
def count_emoji(texts): | |
seen_emoji = emoticon_re.findall(texts) | |
if seen_emoji: | |
return Counter(seen_emoji) | |
else: | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment