Text Classification

SkillfulAPI.TextClassification

Overview

The TextClassification function provides functionality to classify a given input text and determine its sentiment by analyzing positive and negative scores. This can be useful for various applications, including sentiment analysis and content moderation in games.

Class Definition

using SkillfulAI.API;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TextClassification : MonoBehaviour
{
    /// <summary>
    /// Unity's Start method, called when the script is initialized. Initiates the text classification process.
    /// </summary>
    public void Start()
    {
        ClassifyText();
    }

    /// <summary>
    /// Initiates text classification based on a specified input text.
    /// </summary>
    public void ClassifyText()
    {
        // Input text to be classified
        string inputText = "You did amazing in the race. However you were in last place. You did not make qualification.";

        // Perform text classification on the input text
        SkillfulAPI.TextClassification(inputText, response =>
        {
            // Log positive and negative scores from the classification response
            Debug.Log("Positive Score: " + response.PositiveScore);
            Debug.Log("Negative Score: " + response.NegativeScore);
        });
    }
}

Detailed Explanation

Start Method

Description: Unity's Start method is called when the script is first initialized. This method begins the text classification process.

Code:

public void Start()
{
    ClassifyText();
}

Functionality:

  • Automatically calls the ClassifyText method when the script starts.

  • This method is ideal for initializing processes or setting up necessary configurations when the script is first executed.

ClassifyText Method

Description: The ClassifyText method sends a predefined input text to the SkillfulAI API for text classification and logs the classification results.

Code:

public void ClassifyText()
{
    // Input text to be classified
    string inputText = "You did amazing in the race. However you were in last place. You did not make qualification.";

    // Perform text classification on the input text
    SkillfulAPI.TextClassification(inputText, response =>
    {
        // Log positive and negative scores from the classification response
        Debug.Log("Positive Score: " + response.PositiveScore);
        Debug.Log("Negative Score: " + response.NegativeScore);
    });
}

Functionality:

  • Sends the input text to the SkillfulAI API for classification.

  • Logs the positive and negative scores received from the API response.

  • Provides insights into the sentiment or tone of the input text.

Usage Example

  1. Add the Script to a GameObject:

    • Attach the TextClassification script to any GameObject in your Unity scene.

  2. Run the Scene:

    • Upon starting the scene, the ClassifyText method will be invoked automatically.

    • The predefined input text will be sent to the SkillfulAI API, and the classification results will be logged to the console.

Conclusion

The TextClassification function showcases a simple implementation of text classification using the SkillfulAI Gaming SDK. By analyzing the sentiment of text input, this class can be utilized to enhance user interaction, feedback, and content management in your Unity project.

Last updated