예제 #1
0
        private void OnGetToneAnalyze(ToneAnalyzerResponse resp, string data)
        {
            Log.Status("TestToneAnalyzer", "Response: {0} - {1}", resp, data);

            Test(resp != null);
            m_GetToneAnalyzerTested = true;
        }
예제 #2
0
    // TESTING
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
    {
        Log.Debug("ExampleToneAnalyzer.OnGetToneAnalyze()", "{0}", customData["json"].ToString());

        //ResultsField.text = (customData["json"].ToString());  // works but long and cannot read

        //string XYZ = string.Format("XYZ"); // works 1/2
        //ResultsField.text = XYZ;  // works 2/2

        //string XYZ = string.Concat("hello ", "world \n", "ABCDE"); // works 1/2
        //ResultsField.text = XYZ;   // works 2/2

        string RAW = (customData["json"].ToString());          // works but long and cannot read

        //RAW = string.Concat("Tone Response \n", RAW);
        RAW = Regex.Replace(RAW, "tone_categories", " \\\n");
        RAW = Regex.Replace(RAW, "}", "} \\\n");
        RAW = Regex.Replace(RAW, "tone_id", " ");
        RAW = Regex.Replace(RAW, "tone_name", " ");
        RAW = Regex.Replace(RAW, "score", " ");
        RAW = Regex.Replace(RAW, @"[{\\},:]", "");
        RAW = Regex.Replace(RAW, "\"", "");
        ResultsField.text = RAW;

        _analyzeToneTested = true;
    }
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
    {
        Tone[] emotionTone = null;
        foreach (var toneCategory in resp.document_tone.tone_categories)
        {
            if (toneCategory.category_name == "Emotion Tone")
            {
                emotionTone = toneCategory.tones.OrderByDescending(e => e.score).ToArray();
                break;
            }
        }

        var topScoreTone = "";

        if (emotionTone != null)
        {
            topScoreTone = emotionTone[0].tone_name;

            string resultText = "";
            foreach (var tone in emotionTone)
            {
                resultText += string.Format("[Tone: score={0}, tone_name={1}]", tone.score, tone.tone_name);
                resultText += "\n";
            }

            ResultText.text = resultText;
        }

        UnitychanController.ChangeEmotion(topScoreTone);

        Debug.Log(resp.sentences_tone[0]);
        Log.Debug("ExampleToneAnalyzer.OnGetToneAnalyze()", "{0}", customData["json"].ToString());
        _analyzeToneTested = true;
    }
예제 #4
0
    // Handle response from Tone Analysis
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
    {
        Debug.Log("***********");
        // watson Log.Debug; systemName, format, args
        Log.Debug("WatsonServiceConnection.OnGetToneAnalyze()", "{0}", customData["json"].ToString());

        //ResultsField.text = (customData["json"].ToString());  // works but long and cannot read
        //AnalyticsText.text = (customData["json"].ToString());  // works but long and cannot read

        // Log Analysis Repsonse
        Log.Debug("$$$$$ TONE LOG 0 ANGER", "{0}", resp.document_tone.tone_categories[0].tones[0].score);   // ANGER resp.document_tone.tone_categories [0].tones [0].score);
        Log.Debug("$$$$$ TONE LOG 1 DISGUST", "{0}", resp.document_tone.tone_categories[0].tones[1].score); // DISGUST
        Log.Debug("$$$$$ TONE LOG 2 FEAR", "{0}", resp.document_tone.tone_categories[0].tones[2].score);    // FEAR
        Log.Debug("$$$$$ TONE LOG 3 JOY", "{0}", resp.document_tone.tone_categories[0].tones[3].score);     // JOY
        Log.Debug("$$$$$ TONE LOG 4 SAD", "{0}", resp.document_tone.tone_categories[0].tones[4].score);     // SADNESS

        Log.Debug("$$$$$ TONE ANALYTICAL", "{0}", resp.document_tone.tone_categories[1].tones[0].score);    // ANALYTICAL
        Log.Debug("$$$$$ TONE CONFIDENT", "{0}", resp.document_tone.tone_categories[1].tones[1].score);     //  CONFIDENT
        Log.Debug("$$$$$ TONE TENTATIVE", "{0}", resp.document_tone.tone_categories[1].tones[2].score);     //  TENTATIVE

        // EMOTION
        // using indexes to arrays is poor technique for linking to specific Emotion values
        // but we dont have better examples.  Perhaps a string compare, but thats more time
        // here we encapsulate the magic numbers and use the EmotionHandler enum

        // category 0 = emotional tones
        EmotionH.HandleEmotion(WatsonToneID.Anger, resp.document_tone.tone_categories[0].tones[0].score);
        EmotionH.HandleEmotion(WatsonToneID.Disgust, resp.document_tone.tone_categories[0].tones[1].score);
        EmotionH.HandleEmotion(WatsonToneID.Fear, resp.document_tone.tone_categories[0].tones[2].score);
        EmotionH.HandleEmotion(WatsonToneID.Joy, resp.document_tone.tone_categories[0].tones[3].score);
        EmotionH.HandleEmotion(WatsonToneID.Sadness, resp.document_tone.tone_categories[0].tones[4].score);
        // category 1 = language tones
        EmotionH.HandleEmotion(WatsonToneID.Analytical, resp.document_tone.tone_categories[1].tones[0].score);
        EmotionH.HandleEmotion(WatsonToneID.Confident, resp.document_tone.tone_categories[1].tones[1].score);
        EmotionH.HandleEmotion(WatsonToneID.Tenatative, resp.document_tone.tone_categories[1].tones[2].score);
        // category 2 = social tones

        EmotionH.HandleEmotion(WatsonToneID.Consientious, resp.document_tone.tone_categories[2].tones[0].score);
        EmotionH.HandleEmotion(WatsonToneID.Extraversion, resp.document_tone.tone_categories[2].tones[1].score);
        EmotionH.HandleEmotion(WatsonToneID.Agreeable, resp.document_tone.tone_categories[2].tones[2].score);
        EmotionH.HandleEmotion(WatsonToneID.EmotionalRange, resp.document_tone.tone_categories[2].tones[3].score);


        // OTHER TEXT - Formatting for On Screen dump - LATER - pretty this up to use standard DESERIALIZE methods and table
        string RAW = (customData["json"].ToString());  // works but long and cannot read

        //RAW = string.Concat("Tone Response \n", RAW);
        RAW = Regex.Replace(RAW, "tone_categories", "tones: \\\n");
        RAW = Regex.Replace(RAW, "category_id", "\\\ncategory: ");
        RAW = Regex.Replace(RAW, "category_name", "  ");
        RAW = Regex.Replace(RAW, "}", "} \\\n");
        RAW = Regex.Replace(RAW, "tone_id", " ");
        RAW = Regex.Replace(RAW, "tone_name", " ");
        RAW = Regex.Replace(RAW, "score", " ");
        RAW = Regex.Replace(RAW, @"[{\\},:]", "");
        RAW = Regex.Replace(RAW, "\"", "");
        //ResultsField.text = RAW;
        AnalyticsText.text = RAW;
    }
    // TESTING
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
    {
        Log.Debug("ExampleToneAnalyzer.OnGetToneAnalyze()", "{0}", customData["json"].ToString());

        ResultsAnalysis.text = (customData["json"].ToString());          // works but long and cannot read

        /// Logging
        Log.Debug("$$$$$ TONE LOG 0 ANGER", "{0}", resp.document_tone.tone_categories[0].tones[0].score);       // ANGER resp.document_tone.tone_categories [0].tones [0].score);
        Log.Debug("$$$$$ TONE LOG 1 DISGUST", "{0}", resp.document_tone.tone_categories[0].tones[1].score);     // DISGUST
        Log.Debug("$$$$$ TONE LOG 2 FEAR", "{0}", resp.document_tone.tone_categories[0].tones[2].score);        // FEAR
        Log.Debug("$$$$$ TONE LOG 3 JOY", "{0}", resp.document_tone.tone_categories[0].tones[3].score);         // JOY
        Log.Debug("$$$$$ TONE LOG 4 SAD", "{0}", resp.document_tone.tone_categories[0].tones[4].score);         // SADNESS

        Log.Debug("$$$$$ TONE ANALYTICAL", "{0}", resp.document_tone.tone_categories[1].tones[0].score);        // ANALYTICAL
        Log.Debug("$$$$$ TONE CONFIDENT", "{0}", resp.document_tone.tone_categories[1].tones[1].score);         //  CONFIDENT
        Log.Debug("$$$$$ TONE TENTATIVE", "{0}", resp.document_tone.tone_categories[1].tones[2].score);         //  TENTATIVE


        // EMOTION
        if (resp.document_tone.tone_categories [0].tones [0].score > emotion_threshold)
        {
            sphere_emo_angerRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }
        else if (resp.document_tone.tone_categories [0].tones [1].score > emotion_threshold)
        {
            sphere_emo_disgustRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }
        else if (resp.document_tone.tone_categories [0].tones [2].score > emotion_threshold)
        {
            sphere_emo_fearRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }
        else if (resp.document_tone.tone_categories [0].tones [3].score > emotion_threshold)
        {
            sphere_emo_joyRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }
        else if (resp.document_tone.tone_categories [0].tones [4].score > emotion_threshold)
        {
            sphere_emo_sadnessRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }



        // OTHER TEXT - Formatting for On Screen dump - LATER - pretty this up to use standard DESERIALIZE methods and table
        string RAW = (customData["json"].ToString());          // works but long and cannot read

        //RAW = string.Concat("Tone Response \n", RAW);
        RAW = Regex.Replace(RAW, "tone_categories", " \\\n");
        RAW = Regex.Replace(RAW, "}", "} \\\n");
        RAW = Regex.Replace(RAW, "tone_id", " ");
        RAW = Regex.Replace(RAW, "tone_name", " ");
        RAW = Regex.Replace(RAW, "score", " ");
        RAW = Regex.Replace(RAW, @"[{\\},:]", "");
        RAW = Regex.Replace(RAW, "\"", "");
        ResultsAnalysis.text = RAW;

        _analyzeToneTested = true;
    }
예제 #6
0
 private void updateSOValue(ToneAnalyzerResponse resp, FloatVariable fv, int categoryId, int toneId)
 {
     if (fv == null)
     {
         return;             // no variable to update
     }
     if (TA_EmotionThreshold == null || resp.document_tone.tone_categories[categoryId].tones[toneId].score > TA_EmotionThreshold.Value)
     {
         fv.Value = (float)resp.document_tone.tone_categories[categoryId].tones[toneId].score;
     }
 }
예제 #7
0
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, string data)
    {
        /*
         * Response: [ToneAnalyzerResponse: document_tone=[DocumentTone: tone_categories=[ToneCategory: category_id=
         * emotion_tone, category_name=Emotion Tone, tones=[Tone: score=0, tone_id=anger, tone_name=Anger][Tone: score=
         * 0, tone_id=disgust, tone_name=Disgust][Tone: score=0, tone_id=fear, tone_name=Fear][Tone: score=0, tone_id=
         * joy, tone_name=Joy][Tone: score=0, tone_id=sadness, tone_name=Sadness]][ToneCategory: category_id=
         * writing_tone, category_name=Writing Tone, tones=[Tone: score=0, tone_id=analytical, tone_name=Analytical][Tone: score=
         * 0, tone_id=confident, tone_name=Confident][Tone: score=0, tone_id=tentative, tone_name=Tentative]][ToneCategory: category_id=
         * social_tone, category_name=Social Tone, tones=[Tone: score=0.288567, tone_id=openness_big5, tone_name=Openness][Tone: score=
         * 0.274434, tone_id=conscientiousness_big5, tone_name=Conscientiousness][Tone: score=0.543322, tone_id=extraversion_big5, tone_name=
         * Extraversion][Tone: score=0.599483, tone_id=agreeableness_big5, tone_name=Agreeableness][Tone: score=0.292921, tone_id=
         * neuroticism_big5, tone_name=Emotional Range]]], sentenceTone=No Sentence Tone] - okay
         *
         */
        Debug.Log("Response: " + resp + " - " + data);

        // regex score=([0-1]\.*[0-9]*), tone_id=(\S+),
        string          expr = "score=([0-1]\\.*[0-9]*), tone_id=(\\S+),";
        MatchCollection mc   = Regex.Matches(resp.ToString(), expr);

        foreach (Match m in mc)
        {
            //Debug.Log(m.ToString());
            // 1 is score, 2 is tone id name
            //Debug.Log("In match " + m + ", score is " + m.Groups[1].Value);
            //Debug.Log("In match " + m + ", tone_id is " + m.Groups[2].Value);
            double x;
            double.TryParse(m.Groups [1].Value, out x);
            tone_dict [m.Groups [2].Value] = x;
        }
        tone_dict ["Surprise"]           = faceNormalizeVector [0];
        tone_dict ["Joy"]                = faceNormalizeVector [1];
        tone_dict ["Sadness"]            = faceNormalizeVector [2];
        tone_dict ["Anger"]              = faceNormalizeVector [3];
        tone_dict ["Contempt"]           = faceNormalizeVector [4];
        tone_dict ["Disgust"]            = faceNormalizeVector [5];
        tone_dict ["Fear"]               = faceNormalizeVector [6];
        tone_dict ["Valence"]            = faceNormalizeVector [7];
        tone_dict ["Engagement"]         = faceNormalizeVector [8];
        tone_dict ["Smile"]              = faceNormalizeVector [9];
        tone_dict ["LipSuck"]            = faceNormalizeVector [10];
        tone_dict ["Attention"]          = faceNormalizeVector [11];
        tone_dict ["BrowFurrow"]         = faceNormalizeVector [12];
        tone_dict ["BrowRaise"]          = faceNormalizeVector [13];
        tone_dict ["ChinRaise"]          = faceNormalizeVector [14];
        tone_dict ["EyeClosure"]         = faceNormalizeVector [15];
        tone_dict ["InnerEyeBrowRaise"]  = faceNormalizeVector [16];
        tone_dict ["LipCornerDepressor"] = faceNormalizeVector [17];
        tone_dict ["LipPress"]           = faceNormalizeVector [18];
        tone_dict ["LipPucker"]          = faceNormalizeVector [19];
        tone_dict ["MouthOpen"]          = faceNormalizeVector [20];
        tone_dict ["NoseWrinkler"]       = faceNormalizeVector [21];
        tone_dict ["Smirk"]              = faceNormalizeVector [22];
        tone_dict ["UpperLipRaise"]      = faceNormalizeVector [23];

        mapper.emotDict = tone_dict;
        mapper.map();

        int    y             = 0;
        double currentMax    = 0;
        string maxEmotWatson = "Happy";
        string maxBig5       = null;
        string maxBigThree   = null;
        string maxEmotFace   = null;

        foreach (KeyValuePair <string, double> entry in tone_dict)
        {
            Debug.Log(entry.Key + " : " + entry.Value);
            if ((y == 0 && y == 5) && ((y == 8 && y == 13) && y == 20))
            {
                currentMax = 0;
            }
            if (y < 5)
            {
                if (entry.Value > currentMax)
                {
                    currentMax    = entry.Value;
                    maxEmotWatson = entry.Key;
                }
            }
            else if (y < 8)
            {
                if (entry.Value > currentMax)
                {
                    currentMax = entry.Value;
                    maxBig5    = entry.Key;
                }
            }
            else if (y < 13)
            {
                if (entry.Value > currentMax)
                {
                    currentMax  = entry.Value;
                    maxBigThree = entry.Key;
                }
            }
            else if (y < 20)
            {
                if (entry.Value > currentMax)
                {
                    currentMax  = entry.Value;
                    maxEmotFace = entry.Key;
                }
            }
            y++;
        }
        emotionText.text = "Primary Emotion: " + "\n" + maxEmotWatson + "\n" + maxBig5 + "\n" + maxBigThree + "\n" + maxEmotFace;
    }
예제 #8
0
 private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
 {
     Log.Debug("ExampleToneAnalyzer.OnGetToneAnalyze()", "{0}", customData["json"].ToString());
     _analyzeToneTested = true;
 }
예제 #9
0
    /// <summary>
    /// Invoked by Watson Tone Analysis to handle response to submission
    /// </summary>
    /// <param name="resp">Resp.</param>
    /// <param name="customData">Custom data.</param>
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
    {
        // extract response values from JSON response
        // watson Log.Debug; systemName, format, args
        Log.Debug("WatsonServiceConnection.OnGetToneAnalyze()", "{0}", customData["json"].ToString());

        //ResultsField.text = (customData["json"].ToString());  // works but long and cannot read
        //AnalyticsText.text = (customData["json"].ToString());  // works but long and cannot read

        // I dont particularly like the direct use of arrays and indicies
        // these Magic Numbers might change if IBM shuffles the responses
        // would be better to use lookup, but that may add a fair bit of overhead?
        // direct indexing is from R.Andersons's example git
        // the ToneAnalyzerResponse is an object with collection sof Document_tone
        // and Sentence_tone
        // Document_tone is collection of ToneCategory Arrays,
        // Sentence_tone is a bit more involved and not used in the examples, so unused here.
        // Tone Categories are Id+Name + array of Tone
        // Tone's are score, tone_id and tone_name.
        // These look like classics for refactoring into SO Variables
        //
        // Log Analysis Repsonse, read consol to be sure our index# match up to name
        // Emotional Tones
        Log.Debug("$$$$$ TONE Emotional ANGER", " {0} = {1}",
                  resp.document_tone.tone_categories[0].tones[0].tone_name,
                  resp.document_tone.tone_categories[0].tones[0].score
                  ); // ANGER resp.document_tone.tone_categories [0].tones [0].score);
        Log.Debug("$$$$$ TONE Emotional DISGUST", " {0} = {1}",
                  resp.document_tone.tone_categories[0].tones[1].tone_name,
                  resp.document_tone.tone_categories[0].tones[1].score); // DISGUST
        Log.Debug("$$$$$ TONE Emotional FEAR", " {0} = {1}",
                  resp.document_tone.tone_categories[0].tones[2].tone_name,
                  resp.document_tone.tone_categories[0].tones[2].score); // FEAR
        Log.Debug("$$$$$ TONE Emotional JOY", " {0} = {1}",
                  resp.document_tone.tone_categories[0].tones[3].tone_name,
                  resp.document_tone.tone_categories[0].tones[3].score); // JOY
        Log.Debug("$$$$$ TONE Emotional SAD", " {0} = {1}",
                  resp.document_tone.tone_categories[0].tones[4].tone_name,
                  resp.document_tone.tone_categories[0].tones[4].score); // SADNESS
                                                                         // language tones
        Log.Debug("$$$$$ TONE ANALYTICAL", " {0} = {1}",
                  resp.document_tone.tone_categories[1].tones[0].tone_name,
                  resp.document_tone.tone_categories[1].tones[0].score); // ANALYTICAL
        Log.Debug("$$$$$ TONE CONFIDENT", " {0} = {1}",
                  resp.document_tone.tone_categories[1].tones[1].tone_name,
                  resp.document_tone.tone_categories[1].tones[1].score); //  CONFIDENT
        Log.Debug("$$$$$ TONE TENTATIVE", " {0} = {1}",
                  resp.document_tone.tone_categories[1].tones[2].tone_name,
                  resp.document_tone.tone_categories[1].tones[2].score); //  TENTATIVE
                                                                         // category 2 = social tones
                                                                         // Consientious,  Extraversion Agreeable, EmotionalRange
                                                                         // not sure what other categories are implemented or planned or deprecated

        // Note that the original ExampleStreaming4RobotEmotion uses if/else
        // so only one value would be updated per pass.
        // here we are checking all values and setting the SO
        // if no EmotionThreshold assigned, then report all value updates
        // should either [Require ] or test for TA_ variables

        updateSOValue(resp, TA_Anger, 0, 0);
        updateSOValue(resp, TA_Disgust, 0, 1);
        updateSOValue(resp, TA_Fear, 0, 2);
        updateSOValue(resp, TA_Joy, 0, 3);
        updateSOValue(resp, TA_Sadness, 0, 4);

        // skip social tone for now
    }
예제 #10
0
 private void OnGetToneAnalyze(ToneAnalyzerResponse resp, string data)
 {
     Log.Debug("ExampleToneAnalyzer", "Tone Analyzer - Analyze Response: {0}", data);
     _analyzeToneTested = true;
 }
예제 #11
0
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, string data)
    {
        Debug.Log(resp);
        string response = resp.ToString();

        response.ToCharArray();
        double[] arr = new double[5];
        int      i   = 0;
        string   sub;

        for (int j = 0; j < 5; j++)
        {
            while (response[i] != '0')
            {
                i++;
            }
            sub = response.Substring(i, 5);
            i   = i + 11;
            Debug.Log(sub);
            arr[j] = Convert.ToDouble(sub);
        }
        int max = 0;

        for (int k = 1; k < 5; k++)
        {
            if (arr[k] > arr[max])
            {
                max = k;
            }
        }


        string result = "";

        if (max == 0)
        {
            result = "anger";
            funct  = result;
        }
        else if (max == 1)
        {
            result = "disgust";
            funct  = result;
        }
        else if (max == 2)
        {
            result = "fear";
            funct  = result;
        }
        else if (max == 3)
        {
            result = "joy";
            funct  = result;
        }
        else if (max == 4)
        {
            result = "sadness";
            funct  = result;
        }
        Debug.Log(result);
    }
    // TESTING
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
    {
        double anger   = resp.document_tone.tone_categories[0].tones[0].score;
        double disgust = resp.document_tone.tone_categories[0].tones[1].score;
        double fear    = resp.document_tone.tone_categories[0].tones[2].score;
        double joy     = resp.document_tone.tone_categories[0].tones[3].score;
        double sadness = resp.document_tone.tone_categories[0].tones[4].score;


        var tones = new SortedDictionary <string, double> {
            { "anger", anger },
            { "disgust", disgust },
            { "fear", fear },
            { "joy", joy },
            { "sadness", sadness },
        };


        string max_tone = tones.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;


        //Grow that emotion
        if (tones[max_tone] > emotion_threshold && emotional_states[max_tone] < max_emotion_value)
        {
            Log.Debug("Tone Levels ", "1) Growing Max Tone = {0}", max_tone);
            //text_scroll.addline("test", max_tone);
            emotional_states[max_tone] += emotional_growth;
        }
        else
        {
            Log.Debug("Tone Levels ", "1) Max tone below Threshold {0}", emotion_threshold);
        }

        //decay all others
        Log.Debug("Tone Levels ", "2) Dacaying other tones", max_tone);
        List <string> keys = new List <string>(emotional_states.Keys);

        foreach (string e_state in keys)
        {
            if (emotional_states[e_state] > 0)
            {
                emotional_states[e_state] -= emotional_decay;
            }
        }
        Log.Debug("Emotional State Levels", "J:{0} S:{1} F:{2} D:{3} A:{4}", emotional_states["joy"], emotional_states["sadness"], emotional_states["fear"], emotional_states["disgust"], emotional_states["anger"]);

        string max_emotion = emotional_states.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;

        Log.Debug("Tone Levels ", "3) Looking for Prodominant Emotion = {0}", max_emotion);

        Log.Debug("Tone Levels ", "4) checking emotion above idle threshold : {0}", (emotional_states[max_emotion] > idle_threshold));

        string state = (emotional_states[max_emotion] > idle_threshold) ? max_emotion : "idle";

        Log.Debug("Tone Levels ", "5) Updating state to {0} ", state);
        CactusField.text = state;

        // set to default
        Log.Debug("Tone Levels", "6)Updating bars - No Emotion");
        bar1JoyRenderer.transform.localScale    = new Vector3(1F, 1F + (bar_scale * emotional_states["joy"]), 1F);
        bar1JoyRenderer.transform.localPosition = joy_base + new Vector3(0F, (bar_scale * emotional_states["joy"]) / 2, 0F);

        bar2SadnessRenderer.transform.localScale    = new Vector3(1F, 1F + (bar_scale * emotional_states["sadness"]), 1F);
        bar2SadnessRenderer.transform.localPosition = sad_base + new Vector3(0F, (bar_scale * emotional_states["sadness"]) / 2, 0F);


        bar3FearRenderer.transform.localScale    = new Vector3(1F, 1F + (bar_scale * emotional_states["fear"]), 1F);
        bar3FearRenderer.transform.localPosition = fear_base + new Vector3(0F, (bar_scale * emotional_states["fear"]) / 2, 0F);


        bar4DisgustRenderer.transform.localScale    = new Vector3(1F, 1F + (bar_scale * emotional_states["disgust"]), 1F);
        bar4DisgustRenderer.transform.localPosition = disgust_base + new Vector3(0F, (bar_scale * emotional_states["disgust"]) / 2, 0F);


        bar5AngerRenderer.transform.localScale    = new Vector3(1F, 1F + (bar_scale * emotional_states["anger"]), 1F);
        bar5AngerRenderer.transform.localPosition = anger_base + new Vector3(0F, (bar_scale * emotional_states["anger"]) / 2, 0F);



        int state_id = 0;

        switch (state)
        {
        case "idle":
            state_id = 0;
            break;

        case "joy":
            state_id = 1;
            break;

        case "sadness":
            state_id = 2;
            break;

        case "fear":
            state_id = 3;
            break;

        case "disgust":
            state_id = 4;
            break;

        case "anger":
            state_id = 5;
            break;
        }

        //stops trigger loop
        if (state_id != last_state_id)
        {
            Log.Debug("Tone Levels", "7)Trigger Animation via State_ID - {0}", state_id);
            droid_animator.SetInteger("State_ID", state_id);
            last_state_id = state_id;
        }
        else
        {
            Log.Debug("Tone Levels", "7)Leaving Animation, state stable", state_id);
        }


        if (resp.document_tone.tone_categories[1].tones[0].score > emotion_threshold)
        {
        }
        else if (resp.document_tone.tone_categories[1].tones[1].score > emotion_threshold)
        {
        }
        else if (resp.document_tone.tone_categories [1].tones[2].score > emotion_threshold)
        {
        }


        // OTHER TEXT - Formatting for On Screen dump - LATER - pretty this up to use standard DESERIALIZE methods and table
        string RAW = (customData["json"].ToString());          // works but long and cannot read

        //RAW = string.Concat("Tone Response \n", RAW);
        RAW = Regex.Replace(RAW, "tone_categories", " \\\n");
        RAW = Regex.Replace(RAW, "}", "} \\\n");
        RAW = Regex.Replace(RAW, "tone_id", " ");
        RAW = Regex.Replace(RAW, "tone_name", " ");
        RAW = Regex.Replace(RAW, "score", " ");
        RAW = Regex.Replace(RAW, @"[{\\},:]", "");
        RAW = Regex.Replace(RAW, "\"", "");
        //ResultsField.text = RAW;

        _analyzeToneTested = true;
    }
예제 #13
0
    // TESTING
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
    {
        Log.Debug("ExampleToneAnalyzer.OnGetToneAnalyze()", "{0}", customData["json"].ToString());

        ResultsField.text = (customData["json"].ToString());          // works but long and cannot read


        // CACTUS EMOTION DETECTION FOR DROID EMOTION RESPONSE
        //var bar1Object = GameObject.Find("bar1");
        //var renderer = gameObject.GetComponent<Renderer>();

        //CactusField.text = ResultsField.text; // works

        Log.Debug("$$$$$ TONE LOG 0 ANGER", "{0}", resp.document_tone.tone_categories[0].tones[0].score);       // ANGER resp.document_tone.tone_categories [0].tones [0].score);
        Log.Debug("$$$$$ TONE LOG 1 DISGUST", "{0}", resp.document_tone.tone_categories[0].tones[1].score);     // DISGUST
        Log.Debug("$$$$$ TONE LOG 2 FEAR", "{0}", resp.document_tone.tone_categories[0].tones[2].score);        // FEAR
        Log.Debug("$$$$$ TONE LOG 3 JOY", "{0}", resp.document_tone.tone_categories[0].tones[3].score);         // JOY
        Log.Debug("$$$$$ TONE LOG 4 SAD", "{0}", resp.document_tone.tone_categories[0].tones[4].score);         // SADNESS

        Log.Debug("$$$$$ TONE ANALYTICAL", "{0}", resp.document_tone.tone_categories[1].tones[0].score);        // ANALYTICAL
        Log.Debug("$$$$$ TONE CONFIDENT", "{0}", resp.document_tone.tone_categories[1].tones[1].score);         //  CONFIDENT
        Log.Debug("$$$$$ TONE TENTATIVE", "{0}", resp.document_tone.tone_categories[1].tones[2].score);         //  TENTATIVE

        // EMOTION
        if (resp.document_tone.tone_categories [0].tones [0].score > emotion_threshold)
        {
            DroidRenderer.material = red_material;
            CactusField.text       = "Anger";
            bar5AngerRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories [0].tones [1].score > emotion_threshold)
        {
            DroidRenderer.material = green_material;
            CactusField.text       = "Disgust";
            bar4DisgustRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories [0].tones [2].score > emotion_threshold)
        {
            DroidRenderer.material = purple_material;
            CactusField.text       = "Fear";
            bar3FearRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories [0].tones [3].score > emotion_threshold)
        {
            DroidRenderer.material = yellow_material;
            CactusField.text       = "Joy";
            bar1JoyRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories [0].tones [4].score > emotion_threshold)
        {
            DroidRenderer.material = blue_material;
            CactusField.text       = "Sadness";
            bar2SadnessRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }

        // Language tone - https://www.ibm.com/watson/developercloud/tone-analyzer/api/v3/
        else if (resp.document_tone.tone_categories[1].tones[0].score > emotion_threshold)
        {
            DroidRenderer.material = white_material;
            CactusField.text       = "Analytical";
            cyl1AnalyticalRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories[1].tones[1].score > emotion_threshold)
        {
            DroidRenderer.material = white_material;
            CactusField.text       = "Confident";
            cyl2ConfidentRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories [1].tones[2].score > emotion_threshold)
        {
            DroidRenderer.material = white_material;
            CactusField.text       = "Tentative";
            cyl3TentativeRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }


        // OTHER TEXT - Formatting for On Screen dump - LATER - pretty this up to use standard DESERIALIZE methods and table
        string RAW = (customData["json"].ToString());          // works but long and cannot read

        //RAW = string.Concat("Tone Response \n", RAW);
        RAW = Regex.Replace(RAW, "tone_categories", " \\\n");
        RAW = Regex.Replace(RAW, "}", "} \\\n");
        RAW = Regex.Replace(RAW, "tone_id", " ");
        RAW = Regex.Replace(RAW, "tone_name", " ");
        RAW = Regex.Replace(RAW, "score", " ");
        RAW = Regex.Replace(RAW, @"[{\\},:]", "");
        RAW = Regex.Replace(RAW, "\"", "");
        ResultsField.text = RAW;

        _analyzeToneTested = true;
    }
예제 #14
0
 private void OnGetToneAnalyze(ToneAnalyzerResponse resp, string data)
 {
     Debug.Log("Response: " + resp + " - " + data);
 }
예제 #15
0
    // Handle response from Tone Analysis
    private void OnGetToneAnalyze(ToneAnalyzerResponse resp, Dictionary <string, object> customData)
    {
        Log.Debug("ExampleToneAnalyzer.OnGetToneAnalyze()", "{0}", customData["json"].ToString());

        ResultsField.text = (customData["json"].ToString());  // works but long and cannot read

        // Log Analysis Repsonse
        Log.Debug("$$$$$ TONE LOG 0 ANGER", "{0}", resp.document_tone.tone_categories[0].tones[0].score);   // ANGER resp.document_tone.tone_categories [0].tones [0].score);
        Log.Debug("$$$$$ TONE LOG 1 DISGUST", "{0}", resp.document_tone.tone_categories[0].tones[1].score); // DISGUST
        Log.Debug("$$$$$ TONE LOG 2 FEAR", "{0}", resp.document_tone.tone_categories[0].tones[2].score);    // FEAR
        Log.Debug("$$$$$ TONE LOG 3 JOY", "{0}", resp.document_tone.tone_categories[0].tones[3].score);     // JOY
        Log.Debug("$$$$$ TONE LOG 4 SAD", "{0}", resp.document_tone.tone_categories[0].tones[4].score);     // SADNESS

        Log.Debug("$$$$$ TONE ANALYTICAL", "{0}", resp.document_tone.tone_categories[1].tones[0].score);    // ANALYTICAL
        Log.Debug("$$$$$ TONE CONFIDENT", "{0}", resp.document_tone.tone_categories[1].tones[1].score);     //  CONFIDENT
        Log.Debug("$$$$$ TONE TENTATIVE", "{0}", resp.document_tone.tone_categories[1].tones[2].score);     //  TENTATIVE

        // EMOTION
        if (resp.document_tone.tone_categories[0].tones[0].score > emotion_threshold)
        {
            EmotionText.text                     = "Anger";
            AvatarRenderer.material              = red_material;
            AvatarRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);

            anger_BarRender.transform.localScale      += new Vector3(0.1F, 0.1F, 0.1F);
            anger_SphereRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }
        else if (resp.document_tone.tone_categories[0].tones[1].score > emotion_threshold)
        {
            EmotionText.text        = "Disgust";
            AvatarRenderer.material = green_material;

            AvatarRenderer.transform.localScale -= new Vector3(0.1F, 0.1F, 0.1F);

            disgust_BarRender.transform.localScale      += new Vector3(0.1F, 0.1F, 0.1F);
            disgust_SphereRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }
        else if (resp.document_tone.tone_categories[0].tones[2].score > emotion_threshold)
        {
            EmotionText.text                     = "Fear";
            AvatarRenderer.material              = purple_material;
            AvatarRenderer.transform.localScale -= new Vector3(0.1F, 0.1F, 0.1F);

            fear_BarRender.transform.localScale      += new Vector3(0.1F, 0.1F, 0.1F);
            fear_SphereRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }
        else if (resp.document_tone.tone_categories[0].tones[3].score > emotion_threshold)
        {
            EmotionText.text                     = "Joy";
            AvatarRenderer.material              = yellow_material;
            AvatarRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);

            joy_SphereRender.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
            joy_BarRender.transform.localScale    += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories[0].tones[4].score > emotion_threshold)
        {
            EmotionText.text                     = "Sadness";
            AvatarRenderer.material              = blue_material;
            AvatarRenderer.transform.localScale -= new Vector3(0.1F, 0.1F, 0.1F);

            sadness_BarRender.transform.localScale      += new Vector3(0.1F, 0.1F, 0.1F);
            sadness_SphereRenderer.transform.localScale += new Vector3(0.025F, 0.025F, 0.025F);
        }

        // Language tone - https://www.ibm.com/watson/developercloud/tone-analyzer/api/v3/
        else if (resp.document_tone.tone_categories[1].tones[0].score > emotion_threshold)
        {
            EmotionText.text        = "Analytical";
            AvatarRenderer.material = white_material;
            analyticalRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories[1].tones[1].score > emotion_threshold)
        {
            EmotionText.text        = "Confident";
            AvatarRenderer.material = white_material;
            confidentRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }
        else if (resp.document_tone.tone_categories[1].tones[2].score > emotion_threshold)
        {
            EmotionText.text        = "Tentative";
            AvatarRenderer.material = white_material;
            tentativeRenderer.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
        }


        // OTHER TEXT - Formatting for On Screen dump - LATER - pretty this up to use standard DESERIALIZE methods and table
        string RAW = (customData["json"].ToString());  // works but long and cannot read

        //RAW = string.Concat("Tone Response \n", RAW);
        RAW = Regex.Replace(RAW, "tone_categories", " \\\n");
        RAW = Regex.Replace(RAW, "}", "} \\\n");
        RAW = Regex.Replace(RAW, "tone_id", " ");
        RAW = Regex.Replace(RAW, "tone_name", " ");
        RAW = Regex.Replace(RAW, "score", " ");
        RAW = Regex.Replace(RAW, @"[{\\},:]", "");
        RAW = Regex.Replace(RAW, "\"", "");
        ResultsField.text = RAW;

        _analyzeToneTested = true;
    }