<commit_before>﻿/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author <NAME> (<EMAIL>)
* @author <NAME> (<EMAIL>)
*/


using IBM.Watson.Logging;
using IBM.Watson.Utilities;
using IBM.Watson.Data;
using IBM.Watson.Data.XRAY;
using IBM.Watson.Services.v1;
using UnityEngine;
using System;
using IBM.Watson.Debug;
using IBM.Watson.Widgets.Question;

#pragma warning disable 414

namespace IBM.Watson.Widgets.Avatar
{
    /// <summary>
    /// Avatar of Watson 
    /// </summary>
    public class AvatarWidget : Widget
    {
        #region Public Types
        /// <summary>
        /// State of the Avatar in terms of its behavior.
        /// </summary>
        public enum AvatarState
        {
            /// <summary>
            /// Connecting - initial state
            /// </summary>
            CONNECTING,
            /// <summary>
            /// Connected - Listening continuously to understand the input
            /// </summary>
            LISTENING,
            /// <summary>
            /// Connected - After some input it is the time for thinking the understand the input
            /// </summary>
            THINKING,
            /// <summary>
            /// Connected - After semantically understanding, Watson is responding. 
            /// If Watson didn't understand the input, then it goes to listening mode while giving some response about not understood input.
            /// </summary>
            ANSWERING,
            /// <summary>
            /// Some type of error occured that is keeping the avatar from working.
            /// </summary>
            ERROR
        };

        /// <summary>
        /// Avatar Mood which effects various things in the application like Animation speed, coloring etc.
        /// </summary>
        public enum MoodType
        {
            /// <summary>
			/// Connecting / Disconnected - Waiting to be waken-up ( initial state )
			/// </summary>
            SLEEPING = 0,
            /// <summary>
            /// Connected - After wake up - waits a mood change
            /// </summary>
            IDLE,
            /// <summary>
            /// Connected - After wake up - set interested mood
            /// </summary>
            INTERESTED,
            /// <summary>
            /// Connected - After wake up - set urgent mood
            /// </summary>
            URGENT,
            /// <summary>
            /// Connected - After wake up - set upset mood
            /// </summary>
            UPSET,
            /// <summary>
            /// Connected - After wake up - set shy mood
            /// </summary>
            SHY
        }

        #endregion

        #region Private Data
        private XRAY m_XRAY = new XRAY();                      // XRAY service
        private Dialog m_Dialog = new Dialog();             // Dialog service

        private AvatarState m_State = AvatarState.CONNECTING;
        private ClassifyResult m_ClassifyResult = null;

        private SpeechResultList m_SpeechResult = null;
        private Questions m_QuestionResult = null;
        private Answers m_AnswerResult = null;
        private ParseData m_ParseData = null;
        private QuestionWidget m_FocusQuestion = null;
        private bool m_GettingAnswers = false;
        private bool m_GettingParse = false;

        [SerializeField]
        private float m_SoundVisualizerModifier = 20.0f;
        [SerializeField]
        private string m_Hello = "Hello";
        [SerializeField]
        private string m_Goodbye = "Goodbye";
        [SerializeField]
        private string m_RecognizeFailure = "I'm sorry, but I didn't understand your question.";
        [SerializeField]
        private string m_Pipeline = "thunderstone";
        [SerializeField]
        private Input m_levelInput = new Input("Level", typeof(FloatData), "OnLevelInput");
        [SerializeField]
        private Output m_TextOutput = new Output(typeof(TextData));
        [SerializeField]
        private GameObject m_QuestionPrefab = null;
        [SerializeField]
        private string m_DialogName = "xray";
        private string m_DialogId = null;
        private int m_DialogClientId = 0;
        private int m_DialogConversationId = 0;
        [SerializeField, Tooltip("If disconnected, how many seconds until we try to restart the avatar.")]
        private float m_RestartInterval = 30.0f;
        #endregion

        #region Public Properties
        /// <summary>
        /// Access the contained XRAY service object.
        /// </summary>
        public XRAY XRAY { get { return m_XRAY; } }
        /// <summary>
        /// What is the current state of this avatar.
        /// </summary>
        public AvatarState State
        {
            get { return m_State; }
            private set
            {
                if (m_State != value)
                {
                    m_State = value;
                    EventManager.Instance.SendEvent(Constants.Event.ON_CHANGE_AVATAR_STATE_FINISH, this, value);
					// if we went into an error state, automatically try to reconnect after a timeout..
                    if (m_State == AvatarState.ERROR)
                        Invoke("StartAvatar", m_RestartInterval);
                }

				if(m_State == AvatarState.CONNECTING || m_State == AvatarState.ERROR)
					Mood = MoodType.SLEEPING;
            }
        }


        #endregion

        #region Widget Interface
        protected override string GetName()
        {
            return "Avatar";
        }
        #endregion<commit_msg>* Added error message when something breaks.<commit_after>﻿/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author <NAME> (<EMAIL>)
* @author <NAME> (<EMAIL>)
*/


using IBM.Watson.Logging;
using IBM.Watson.Utilities;
using IBM.Watson.Data;
using IBM.Watson.Data.XRAY;
using IBM.Watson.Services.v1;
using UnityEngine;
using System;
using IBM.Watson.Debug;
using IBM.Watson.Widgets.Question;

#pragma warning disable 414

namespace IBM.Watson.Widgets.Avatar
{
    /// <summary>
    /// Avatar of Watson 
    /// </summary>
    public class AvatarWidget : Widget
    {
        #region Public Types
        /// <summary>
        /// State of the Avatar in terms of its behavior.
        /// </summary>
        public enum AvatarState
        {
            /// <summary>
            /// Connecting - initial state
            /// </summary>
            CONNECTING,
            /// <summary>
            /// Connected - Listening continuously to understand the input
            /// </summary>
            LISTENING,
            /// <summary>
            /// Connected - After some input it is the time for thinking the understand the input
            /// </summary>
            THINKING,
            /// <summary>
            /// Connected - After semantically understanding, Watson is responding. 
            /// If Watson didn't understand the input, then it goes to listening mode while giving some response about not understood input.
            /// </summary>
            ANSWERING,
            /// <summary>
            /// Some type of error occured that is keeping the avatar from working.
            /// </summary>
            ERROR
        };

        /// <summary>
        /// Avatar Mood which effects various things in the application like Animation speed, coloring etc.
        /// </summary>
        public enum MoodType
        {
            /// <summary>
			/// Connecting / Disconnected - Waiting to be waken-up ( initial state )
			/// </summary>
            SLEEPING = 0,
            /// <summary>
            /// Connected - After wake up - waits a mood change
            /// </summary>
            IDLE,
            /// <summary>
            /// Connected - After wake up - set interested mood
            /// </summary>
            INTERESTED,
            /// <summary>
            /// Connected - After wake up - set urgent mood
            /// </summary>
            URGENT,
            /// <summary>
            /// Connected - After wake up - set upset mood
            /// </summary>
            UPSET,
            /// <summary>
            /// Connected - After wake up - set shy mood
            /// </summary>
            SHY
        }

        #endregion

        #region Private Data
        private XRAY m_XRAY = new XRAY();                      // XRAY service
        private Dialog m_Dialog = new Dialog();             // Dialog service

        private AvatarState m_State = AvatarState.CONNECTING;
        private ClassifyResult m_ClassifyResult = null;

        private SpeechResultList m_SpeechResult = null;
        private Questions m_QuestionResult = null;
        private Answers m_AnswerResult = null;
        private ParseData m_ParseData = null;
        private QuestionWidget m_FocusQuestion = null;
        private bool m_GettingAnswers = false;
        private bool m_GettingParse = false;

        [SerializeField]
        private float m_SoundVisualizerModifier = 20.0f;
        [SerializeField]
        private string m_Hello = "Hello";
        [SerializeField]
        private string m_Goodbye = "Goodbye";
        [SerializeField]
        private string m_RecognizeFailure = "I'm sorry, but I didn't understand your question.";
        [SerializeField]
        private string m_Error = "Oh bugger, something has gone wrong.";
        [SerializeField]
        private string m_Pipeline = "thunderstone";
        [SerializeField]
        private Input m_levelInput = new Input("Level", typeof(FloatData), "OnLevelInput");
        [SerializeField]
        private Output m_TextOutput = new Output(typeof(TextData));
        [SerializeField]
        private GameObject m_QuestionPrefab = null;
        [SerializeField]
        private string m_DialogName = "xray";
        private string m_DialogId = null;
        private int m_DialogClientId = 0;
        private int m_DialogConversationId = 0;
        [SerializeField, Tooltip("If disconnected, how many seconds until we try to restart the avatar.")]
        private float m_RestartInterval = 30.0f;
        #endregion

        #region Public Properties
        /// <summary>
        /// Access the contained XRAY service object.
        /// </summary>
        public XRAY XRAY { get { return m_XRAY; } }
        /// <summary>
        /// What is the current state of this avatar.
        /// </summary>
        public AvatarState State
        {
            get { return m_State; }
            private set
            {
                if (m_State != value)
                {
                    m_State = value;
                    EventManager.Instance.SendEvent(Constants.Event.ON_CHANGE_AVATAR_STATE_FINISH, this, value);
					// if we went into an error state, automatically try to reconnect after a timeout..
                    if (m_State == AvatarState.ERROR)
                    {
                        if ( m_FocusQuestion != null )
                            m_FocusQuestion.OnLeaveTheSceneAndDestroy();

                        Invoke("StartAvatar", m_RestartInterval);
                        m_TextOutput.SendData( new TextData( m_Error ) );
                    }
                }

				if(m_State == AvatarState.CONNECTING || m_State == AvatarState.ERROR)
					Mood = MoodType.SLEEPING;
            }
        }


        #endregion

        #region Widget Interface
        protected override string GetName()
        {
            return "Avatar";
        }
        #endregion
{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.0033492822966507177, 'mean_word_length': 1.6935137457044673, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6071527', 'n_tokens_mistral': 3260, 'n_tokens_neox': 3120, 'n_words': 1065}