How to use the emoji.demojize function in emoji

To help you get started, we’ve selected a few emoji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github magicalraccoon / tootstream / src / tootstream / toot_parser.py View on Github external
def emoji_unicode_to_shortcodes(text):
    """Convert unicode emoji to standard emoji short codes."""
    return emoji.demojize(text)
github sagesharp / foss-heartbeat / ghsentiment.py View on Github external
# Strip out any blockquotes or inline code
    text = re.sub('```.+?```', 'block-code.', text, flags=re.DOTALL)
    text = re.sub('`[^`]+`', 'inline-code', text, flags=re.MULTILINE)
    text = re.sub('^    .+?$', 'block-code.', text, flags=re.MULTILINE)
    # Remove any quoted text, since we want the sentiment of the person posting
    text = re.sub('^>.+?$', '', text, flags=re.MULTILINE)
    # Replace any URLs with their text
    text = re.sub('\[(.*?)\]\(.*?\)', '\g<1>', text)
    text = re.sub('https?:.+? ', 'URL ', text)
    text = re.sub('https?:.+?$', 'URL.', text, flags=re.MULTILINE)
    # convert emojis into their short hand code.
    # This makes it easier for me to correct sentiment in the training text.
    # It also allows the Standford CoreNLP to parse each emoji as a separate word,
    # which will allow us to train it for sentiment of groups of emoji.
    # E.g. :tea: is neutral, but :tea: :fire: references the "This is fine" meme
    text = emoji.demojize(text)
    # We often have blocks of code follow a colon, e.g.
    #
    # This is not correct syntax for python 3:
    # ```print foo```
    # This is the correct syntax:
    # ```print(foo)```
    #
    # This code will translate that into
    #
    # This is not correct syntax for python 3:
    # block-quote
    # This is the correct syntax:
    # block-quote
    #
    # The Standford CoreNLP assumes that the sentence continues
    # after the colon, because it's assuming sentences like
github gahjelle / pythonji / pythonji / __main__.py View on Github external
def demojize(py_path):
    """Replace emojis by strings in the given file"""
    py_text = py_path.read_text()
    python_text = emoji.demojize(py_text, delimiters=DELIMITERS)
    return emojize_literals(python_text)
github chenghuige / wenzheng / utils / gezi / segment.py View on Github external
def bseg_(text):
      bseg.Cut(to_gbk(emoji.demojize(text.decode('utf8'))))
      bseg.NerTag()
      if not gezi.env_has('BSEG_SUBNER'):
        nodes = bseg.GetNerNodes()
      else:
        nodes = bseg.GetSubNerNodes()
      l = [(to_utf8(x.word), x.name) for x in nodes]
      return l
    # have tested as 718 cause error 
github vlajnaya-mol / message-analyser / message_analyser / plotter.py View on Github external
def barplot_emojis(msgs, your_name, target_name, topn, path_to_save):
    sns.set(style="whitegrid")

    mc_emojis = stools.get_emoji_countered(msgs).most_common(topn)
    if not mc_emojis:
        return
    your_msgs = [msg for msg in msgs if msg.author == your_name]
    target_msgs = [msg for msg in msgs if msg.author == target_name]

    your_emojis_cnt = stools.get_emoji_countered(your_msgs)
    target_emojis_cnt = stools.get_emoji_countered(target_msgs)

    df_dict = {"name": [], "emoji": [], "num": []}
    for e, _ in mc_emojis:
        df_dict["emoji"].extend([emoji.demojize(e), emoji.demojize(e)])
        df_dict["name"].append(your_name)
        df_dict["num"].append(your_emojis_cnt[e])
        df_dict["name"].append(target_name)
        df_dict["num"].append(target_emojis_cnt[e])

    ax = sns.barplot(x="num", y="emoji", hue="name", data=pd.DataFrame(df_dict), palette="PuBu")
    ax.set(ylabel="emoji name", xlabel="emojis")
    ax.legend(ncol=1, loc="lower right", frameon=True)

    fig = plt.gcf()
    fig.set_size_inches(11, 8)
    plt.tight_layout()

    fig.savefig(os.path.join(path_to_save, barplot_emojis.__name__ + ".png"), dpi=500)
    # plt.show()
    log_line(f"{barplot_emojis.__name__} was created.")
github carpedm20 / emoji / example / example.py View on Github external
# -*- coding: UTF-8 -*-
import emoji

print(emoji.emojize('Water! :water_wave:'))
print(emoji.demojize(u'🌊')) # for Python 2.x
# print(emoji.demojize('🌊')) # for Python 3.x
github IEEEComputerSocietyUNB / ProjetoChatbot / bot / application.py View on Github external
def emotional_state_collect_emotion(self, update, msg_text):
        """
        When the user chooses an option based on how he or she is feeling
        a certain moment. This method is called to evaluate which option
        has been choosen and then call the method responsible for storing
        the information.

        @update = the user info.
        @msg_text = the option the user has choosen
        """
        with open("bot/dialogs/emotions.json", "r") as rf:
            data = json.load(rf)
        response = random.choice(data[emoji.demojize(msg_text)]["statements"])
        response = str(response)
        emotion_type = int(data[emoji.demojize(msg_text)]["emotion_type"])

        update.effective_message.reply_text(response)
        update.effective_message.reply_text(
            "Em breve, eu te apresentarei um diÑrio com maiores informaçáes.",
            reply_markup=ReplyKeyboardRemove(),
        )
        self.emotion_handler = False
        self.emotional_state_store_emotion(update, emotion_type)
        return 0
github monologg / hashtag-prediction-pytorch / server / app.py View on Github external
def predict():
    img_id = request.args.get('image_id')
    text = request.args.get('text')
    max_seq_len = int(request.args.get('max_seq_len'))
    n_label = int(request.args.get('n_label'))

    # Prediction
    img_link = "https://drive.google.com/uc?id={}".format(img_id)
    download(img_link, "{}.jpg".format(img_id), cachedir=app.config['UPLOAD_FOLDER'])
    img_tensor = img_to_tensor(os.path.join(app.config['UPLOAD_FOLDER'], "{}.jpg".format(img_id)), args.no_cuda)

    texts = [emoji.demojize(text.lower())]

    input_ids, attention_mask, token_type_ids = convert_texts_to_tensors(texts, max_seq_len, args.no_cuda)
    with torch.no_grad():
        outputs = model(input_ids, attention_mask, token_type_ids, None, img_tensor)
    logits = outputs[0]

    _, top_idx = logits.topk(n_label)

    preds = []
    print(top_idx)
    for idx in top_idx[0]:
        preds.append("#{}".format(label_lst[idx]))

    return render_template("result.html", user_image="./{}/{}".format(app.config['UPLOAD_FOLDER'], "{}.jpg".format(img_id)), text=text, tag=" ".join(preds))