Skip to content

Replaces words with emojis if matches in the EMOJI_DATA of the "emoji" python library can be found. No colons for emoji shorthand codes are needed, just normal text.

License

Notifications You must be signed in to change notification settings

EstebanQ2024/emoji_sentence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

To use, only one function needs to be imported:

from replace_emojis import replace_with_emoji

"""
Replaces words in a sentence with corresponding emojis if available.

Args:
    sentence (str): The input sentence to process.
    debug (bool): Flag to toggle debug print statements. Default is False.

Returns:
    str: The sentence with words replaced by emojis where applicable.
"""

Emoji data is taken from the EMOJI_DATA dictionary of the emoji library.

Three match cases are used:

  • Exact match of a word to emoji 'EN' language description
  • Emoji 'EN' description matches the beggining of a word
  • Exact match of a word with emoji 'alias'

Example:

I love omnipotent a Pizza pizza, cats, bobcats, ants, pigs, croissants, and bread thumbs_up thumbsup PIzzaaaa re-Pizzaaaaa!

I love 🕉️nipotent 🅰️ 🍕 🍕, 🐱s, bobcats, 🐜s, 🐷s, 🥐s, and 🍞 👍 👍 🍕aaa re-Pizzaaaaa!

--

For additional debugging print statements:

Setting keyword arg debug=True will output information about the words (tokens) extracted from the text, and the emoji matches and substitutions.

Example:

Tokens: {'re-pizzaaaaa', 'bobcats', 'a', 'i', 'love', 'thumbs_up', 'croissants', 'omnipotent', 'cats', 'ants', 'pigs', 'bread', 'pizzaaaa', 'pizza', 'thumbsup', 'and'}

Emoji Found: 🅰️, Token: a, Match: 🅰️, Sub: 🅰️

Emoji Found: 👍, Token: thumbs_up, Match: :thumbs_up:, Sub: :thumbs_up:

Emoji Found: 🥐, Token: croissants, Match: 🥐, Sub: 🥐s

Emoji Found: 🕉️, Token: omnipotent, Match: 🕉️, Sub: 🕉️nipotent

Emoji Found: 🐈, Token: cats, Match: 🐱, Sub: 🐱s

Emoji Found: 🐜, Token: ants, Match: 🐜, Sub: 🐜s

Emoji Found: 🐖, Token: pigs, Match: 🐷, Sub: 🐷s

Emoji Found: 🍞, Token: bread, Match: 🍞, Sub: 🍞

Emoji Found: 🍕, Token: pizzaaaa, Match: 🍕, Sub: 🍕aaa

Emoji Found: 🍕, Token: pizza, Match: 🍕, Sub: 🍕

Emoji Found: 👍, Token: thumbsup, Match: 👍, Sub: 👍

I love omnipotent a Pizza pizza, cats, bobcats, ants, pigs, croissants, and bread thumbs_up thumbsup PIzzaaaa re-Pizzaaaaa!

I love 🕉️nipotent 🅰️ 🍕 🍕, 🐱s, bobcats, 🐜s, 🐷s, 🥐s, and 🍞 👍 👍 🍕aaa re-Pizzaaaaa!

About

Replaces words with emojis if matches in the EMOJI_DATA of the "emoji" python library can be found. No colons for emoji shorthand codes are needed, just normal text.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages