如何在每个表情符号之间放置空格

How to put spaces in between every emojis

我有一个推文数据集,其中至少包含一次表情符号。但有时还有更多。表情符号可以在句子的中间,也可以在开头或结尾。因此,对于每条推文,情况都不同。我在尝试仅拆分句子中的表情符号时遇到困难。如果我遍历每个单词,多个表情符号也被视为一个单词。

She is too hot for Congress.  Vote her out!  #sarcasm 

预期输出:She is too hot for Congress. Vote her out! #sarcasm

The Struggle is Real  #struggle #struggleisreal #struggles #funny #humor #saying #sarcasm #lifestruggles #sarcastic #funnysaying #sayings #thestruggleisreal 

预期输出:The Struggle is Real #struggle #struggleisreal #struggles #funny #humor #saying #sarcasm #lifestruggles #sarcastic #funnysaying #sayings #thestruggleisreal

  For More Funny Post Follow

预期输出: For More Funny Post Follow

上面的答案 post 给了我一个列表和数据集中每条推文的标记词,这是我不想要的,它也没有解决我的问题。我在表情符号之间看不到 space。

使用表情符号库'v1.5.0'这很容易。

import emoji

def extract_emojis(s):
    return ''.join((' '+c+' ') if c in emoji.UNICODE_EMOJI['en'] else c for c in s)

测试:

s = " me así, seds  hello ‍ emoji hello ‍‍ how are  you today"

extract_emojis(s)

输出:

'     me así, se        ds        hello     \u200d   emoji hello   \u200d  \u200d   how are    you today        '