How to find a textual description of emoticons, unicode characters and emoji in a string (python, perl)? [closed]

夙愿已清 提交于 2019-12-10 10:34:44

问题


The detection and counting of emoticon icons has been addressed previously.

As a follow-up on this question and the solution provided, I'd like extend it with ability to link the detected emoticons, unicode characters and emoji to their corresponding (textual) descriptions:

  • emoticons (Western and Eastern, e.g. List_of_emoticons from Wikipedia),
  • unicode characters (e.g. U1F600.pdf available from the unicode website (direct link is included in the previous stackoverflow question mentioned above),
  • other emoji types, e.g. from the list of emoji frequently used in Twitter (twitter-emoji-list from the emojipedia website).

Is there any comprehensive solution already available for conducting such a translation, in python or perl, similar to the method implemented in Swift? If not, can you make a script that provides a textual description for an emoticon/emoji found in a string?


回答1:


perl example using charnames:

use 5.014;
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);
use charnames ':full';

my @faces = split //, '😄😀😈';
for (@faces) {
    say sprintf "U+%05X %s %s",
        ord($_), $_, charnames::viacode(ord($_));
}

prints

U+1F604 😄 SMILING FACE WITH OPEN MOUTH AND SMILING EYES
U+1F600 😀 GRINNING FACE
U+1F608 😈 SMILING FACE WITH HORNS



回答2:


Python has the unicodedata import module with data on all the Unicode characters:

import unicodedata as ud
s = '\U0001F604\U0001F600\U0001F608'
for c in s:
    print('{} U+{:5X} {}'.format(c,ord(c),ud.name(c)))

Output:

😄 U+1F604 SMILING FACE WITH OPEN MOUTH AND SMILING EYES
😀 U+1F600 GRINNING FACE
😈 U+1F608 SMILING FACE WITH HORNS


来源:https://stackoverflow.com/questions/26086108/how-to-find-a-textual-description-of-emoticons-unicode-characters-and-emoji-in

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