Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_emoji_names():
for name in emoji.unicode_codes.EMOJI_UNICODE.keys():
assert name.startswith(':') and name.endswith(':') and len(name) >= 3
def get_emoji_regexp():
"""Returns compiled regular expression that matches emojis defined in
``emoji.UNICODE_EMOJI_ALIAS``. The regular expression is only compiled once.
"""
global _EMOJI_REGEXP
# Build emoji regexp once
if _EMOJI_REGEXP is None:
# Sort emojis by length to make sure mulit-character emojis are
# matched first
emojis = sorted(unicode_codes.EMOJI_UNICODE.values(), key=len,
reverse=True)
pattern = u'(' + u'|'.join(re.escape(u) for u in emojis) + u')'
_EMOJI_REGEXP = re.compile(pattern)
return _EMOJI_REGEXP
def _generate_emojis(self, k=1):
"""Generate random list of emojis.
Emojis are sampled from a list of `n` emojis and `k*n` empty strings.
Args:
k (int, optional): Defaults to 20.
Returns:
list: List with emojis
"""
emojis = list(EMOJI_UNICODE.values())
n = len(emojis)
emojis = emojis + [''] * k*n
return np.random.choice(emojis, self.size)
def generate_emojis(self, k=1):
"""Generate random list of emojis.
Emojis are sampled from a list of `n` emojis and `k*n` empty strings.
Args:
k (int, optional): Defaults to 20.
Returns:
list: List with emojis
"""
emojis = list(EMOJI_UNICODE.values())
n = len(emojis)
emojis = emojis + [''] * k*n
return np.random.choice(emojis, self.size)
def __init__(self, sentence):
self.sentence = sentence
self.list_emoji = emoji.unicode_codes.EMOJI_UNICODE
self.emoji = ''
def replace(match):
mg = match.group(1).replace(delimiters[0], _DEFAULT_DELIMITER).replace(delimiters[1], _DEFAULT_DELIMITER)
if use_aliases:
return unicode_codes.EMOJI_ALIAS_UNICODE.get(mg, mg)
else:
return unicode_codes.EMOJI_UNICODE.get(mg, mg)