Learn R Programming

text2emotion (version 0.1.0)

predict_emotion_with_emoji: Predict Emotion with Emoji Representation

Description

This function takes input text, preprocesses it, extracts TF-IDF features using a pre-trained model, predicts the emotion using a trained classifier, and returns the result with optional emoji representation.

Usage

predict_emotion_with_emoji(text, output_type = "textemoji")

Value

Depending on output_type:

  • For "emotion": character string of predicted emotion

  • For "emoji": character string of corresponding emoji

  • For "textemoji": original text with appended emoji

The function also prints the result to console.

Arguments

text

Character string containing the text to analyze.

output_type

Type of output to return. Must be one of:

  • "emotion" - returns only the predicted emotion label

  • "emoji" - returns only the corresponding emoji

  • "textemoji" - returns original text appended with predicted emoji (default)

Examples

Run this code
if (FALSE) {
# This example is not run because it requires manually downloading
# a large external model (~30MB), which cannot be retrieved automatically
# and may fail in offline environments.
predict_emotion_with_emoji("I'm so happy today!")
predict_emotion_with_emoji("This makes me angry", "emoji")
predict_emotion_with_emoji("I feel scared", "emotion")
}

Run the code above in your browser using DataLab