Emot: Emoji and Emoticon Detection
Emot is a Python library designed for high-performance detection and extraction of emojis and emoticons from text, particularly useful for large-scale datasets. It utilizes advanced dynamic pattern generation based on an internal database. The current version, 3.1, released in August 2021, focuses on performance and bulk processing capabilities. The library provides details like the value, meaning, location, and presence (flag) of detected symbols.
Common errors
-
ImportError: cannot import name 'UNICODE_EMO' from 'emot.emo_unicode'
cause Attempting to import internal module components directly which are not part of the public API or have been removed/renamed in newer versions.fixAvoid direct imports from internal modules. Use the top-level `emot` module and its documented methods, typically after initializing the `emot.core.emot()` object for versions 3.0 and above. Correct usage is `import emot`. -
TypeError: 'module' object is not callable (e.g., emot.emoji(text) fails)
cause Attempting to call `emot.emoji()` or `emot.emoticons()` directly on the imported module in versions 3.0 and later.fixFor `emot` v3.0+, you must first initialize an `emot` object: `emot_obj = emot.core.emot()`. Then, call the methods on this object: `emot_obj.emoji(text)`.
Warnings
- breaking The return type of `emoji()` and `emoticons()` methods changed significantly in v2.0. It shifted from a list of dictionaries to a single dictionary where keys (like 'value', 'location', 'mean') hold lists, and a new boolean 'flag' was introduced.
- breaking Starting from v3.0, `emot` requires explicit object instantiation via `emot.core.emot()`. Direct calls like `emot.emoji(text)` are no longer supported. Additionally, Python 2.x support was dropped, requiring Python 3.x.
- gotcha Emojis with skin tone modifiers (e.g., 👨🏽) might be incorrectly parsed as two separate emojis (e.g., '👨' and ':medium_skin_tone:') leading to double-counting or unexpected results.
Install
-
pip install emot --upgrade
Imports
- emot
from emot.emo_unicode import UNICODE_EMO, EMOTICONS
import emot
Quickstart
import emot
# Initialize the emot object (required since v3.0)
emot_obj = emot.core.emot()
text_with_emojis = "I love python 👨 🙂 ❤️"
text_with_emoticons = "Hello there :-) :D"
text_without_emotions = "No emotions here."
# Detect emojis
result_emoji = emot_obj.emoji(text_with_emojis)
print("Emoji detection:", result_emoji)
# Expected output for v3.1: {'value': ['👨', '🙂', '❤'], 'location': [[14, 15], [16, 17], [18, 19]], 'mean': [':man:', ':slightly_smiling_face:', ':red_heart:'], 'flag': True}
# Detect emoticons
result_emoticon = emot_obj.emoticons(text_with_emoticons)
print("Emoticon detection:", result_emoticon)
# Expected output for v3.1: {'value': [':-)', ':D'], 'location': [[12, 15], [16, 18]], 'mean': ['Happy face smiley', 'Grinning face'], 'flag': True}
# Handle text without emotions
result_none = emot_obj.emoji(text_without_emotions)
print("No emotions detection:", result_none)
# Expected output for v3.1: {'value': [], 'location': [], 'mean': [], 'flag': False}