Translate unicode emojis to ascii emojis in Python

感情迁移 提交于 2019-12-24 03:45:05

问题


Is there a way to translate unicode emojis to an appropriate ascii emoticon in Python? I know the emoji library which can be used to convert unicode emojis to something like :crying_face:. But what I would need is to convert it to :'(

Is there an elegant way to do this without having to translate every possible emoji manually? Another option would be to convert the ascii emojis also to their textual representation, i.e. :'( should become :crying_face:.

My intermediate goal is to find a way to transform ascii and unicode emojis to a common representation. My final goal would be to replace emoticons (no matter if unicode or ascii) by the emotion they represent (if they do not represent an emotion, remove them)


回答1:


I found these repos that have a huge database of emoji's along with a text attribute(what you need):

https://github.com/alexmick/emoji-data-python

https://github.com/iamcal/emoji-data (This is the original. The python one seems to be a wrapper on this)

You can find out more by exploring the examples in the repos. From the For the python version you can use the official unicode name/hex code to get the EmojiChar object:

In [31]: grin = emoji_data_python.find_by_name("GRINNING FACE")

In [32]: grin
Out[32]:
[EmojiChar("GRINNING FACE"),
 EmojiChar("GRINNING FACE WITH SMILING EYES"),
 EmojiChar("GRINNING FACE WITH STAR EYES"),
 EmojiChar("GRINNING FACE WITH ONE LARGE AND ONE SMALL EYE")]

In [33]: grin[0].text
Out[33]: ':D'


来源:https://stackoverflow.com/questions/52154875/translate-unicode-emojis-to-ascii-emojis-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!