在Python中将unicode表情符号转换为ASCII表情符号 [英] Translate unicode emojis to ascii emojis in Python

查看:456
本文介绍了在Python中将unicode表情符号转换为ASCII表情符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以将unicode表情符号转换为Python中合适的ascii表情符号?我知道 emoji库,该库可用于将unicode表情符号转换为:crying_face:之类的东西.但是我需要将其转换为:'(

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 :'(

是否有一种优雅的方法无需手动翻译所有可能的表情符号?另一种选择是将ascii表情符号也转换为它们的文本表示形式,即:'(应该变成:crying_face:.

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:.

我的中间目标是找到一种将ASCII和Unicode表情符号转换为通用表示形式的方法.我的最终目标是将表情符号(无论是unicode还是ascii)替换为它们所代表的情感(如果它们不代表情感,则将其删除)

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)

推荐答案

我发现这些存储库具有巨大的表情符号数据库以及text属性(您需要什么):

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 (这是原始的.似乎是python的包装)

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

您可以通过阅读回购中的示例来了解更多信息.来自 对于python版本,您可以使用正式的Unicode名称/十六进制代码来获取EmojiChar对象:

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'

这篇关于在Python中将unicode表情符号转换为ASCII表情符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆