Esempio n. 1
0
    // Start is called before the first frame update
    void Start()
    {
        try
        {
            MainBot = new OscovaBot();
            OscovaBot.Logger.LogReceived += (s, o) =>
            {
                Debug.Log($"OscovaBot: {o.Log}");
            };

            //Import bot's knowledge-base from an Oryzer Workspace project file.
            //To read the content of this file ensure you've got Oryzer installed. Visit Oryzer.com

            //First read the knowledge.json file and create a workspace.

            /*Note: Oryzer usually saves file in .West file extensions so the file was intentionally
             * renamed to knowledge.json so Unity stores it as a resource. */
            var txtAsset = (TextAsset)Resources.Load("tobor_phase_1_v_0.1", typeof(TextAsset));
            var tileFile = txtAsset.text;
            Debug.Log(txtAsset);
            Debug.Log(tileFile);

            var workspace = new WorkspaceGraph();
            workspace.LoadFromString(tileFile);

            //Import the workspace.
            MainBot.ImportWorkspace(workspace);
            MainBot.Trainer.StartTraining();

            //When the bot generates a response simply display it.
            MainBot.MainUser.ResponseReceived += (sender, evt) =>
            {
                //StartCoroutine(Response(evt.Response.Text));
                Debug.Log(evt.Response.Messages);
                AddMessage($"Bot: {evt.Response.Messages}", MessageType.Bot);
            };

            /*Note: Originally from Ma Xin
             * MainBot.Recognizers.EntityRecognized += Recognizers_EntityRecognized;
             * MainBot.Recognizers.EntitiesExtracted += Recognizers_EntitiesExtracted;
             *
             * MainBot.Dialogs.Add(new BotDialog());
             * //MainBot.ImportWorkspace("Assets/bot.json");//original Assets/SimpleText.west
             * MainBot.Trainer.StartTraining();
             *
             * MainBot.MainUser.ResponseReceived += (sender, evt) =>
             * {
             *  StartCoroutine(Response(evt.Response.Text));
             *  StartCoroutine(ShowText());
             *  Debug.Log(evt.Response.Text);
             *  //AddMessage($"Bot: {evt.Response.Text}", MessageType.Bot);
             * };
             */
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
    }
Esempio n. 2
0
        // Start is called before the first frame update
        void Start()
        {
            try
            {
                //Create new instance of bot.
                MainBot = new OscovaBot();
                OscovaBot.Logger.LogReceived += (s, o) =>
                {
                    Debug.Log($"OscovaBot: {o.Log}");
                };

                //Import bot's knowledge-base from an Oryzer Workspace project file.
                //To read the content of this file ensure you've got Oryzer installed. Visit Oryzer.com

                //First read the knowledge.json file and create a workspace.

                /*Note: Oryzer usually saves file in .West file extensions so the file was intentionally
                 * renamed to knowledge.json so Unity stores it as a resource. */
                var txtAsset = (TextAsset)Resources.Load("knowledge", typeof(TextAsset));
                var tileFile = txtAsset.text;

                var workspace = new WorkspaceGraph();
                workspace.LoadFromString(tileFile);

                //Import the workspace.
                MainBot.ImportWorkspace(workspace);
                MainBot.Trainer.StartTraining();

                //When the bot generates a response simply display it.
                MainBot.MainUser.ResponseReceived += (sender, evt) =>
                {
                    AddMessage($"Bot: {evt.Response.Text}", MessageType.Bot);
                };
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
        }
Esempio n. 3
0
 public HelloNode(WorkspaceGraph workspace) : base(workspace)
 {
 }
Esempio n. 4
0
 public HelloNodePlugin(WorkspaceGraph workspace) : base(workspace)
 {
     //Register Node.
     workspace.Nodes.RegisterType <HelloNode>();
 }
Esempio n. 5
0
    IEnumerator Start()
    {
        phaseInitiated     = PlayerPrefs.GetInt("Phase Initiated");
        ARTapToPlaceObject = FindObjectOfType <ARTapToPlaceObject>();

        Debug.Log("phase initiated: " + phaseInitiated);


        //Download JSON from URL according to phraseInitiated number
        WWW www = new WWW(chatbotURL[phaseInitiated - 1]);

        yield return(www);

        if (www.error == null)
        {
            Debug.Log("chatbot initiated: " + chatbotURL[phaseInitiated - 1]);
            Debug.Log("Get JSON: " + www.text);
        }
        else
        {
            Debug.Log("ERROR: " + www.error);
        }

        try
        {
            //Create new instance of bot.
            MainBot = new OscovaBot();

            OscovaBot.Logger.LogReceived += (s, o) =>
            {
                Debug.Log($"OscovaBot: {o.Log}");
            };

            //Import bot's knowledge-base from an Oryzer Workspace project file.
            //To read the content of this file ensure you've got Oryzer installed. Visit Oryzer.com

            //First read the knowledge.json file and create a workspace.

            /*Note: Oryzer usually saves file in .West file extensions so the file was intentionally
             * renamed to knowledge.json so Unity stores it as a resource. */

            //Get downloaded JSON text
            var tileFile  = www.text;
            var workspace = new WorkspaceGraph();
            workspace.LoadFromString(tileFile);

            //Import the workspace.
            MainBot.ImportWorkspace(workspace);
            MainBot.Dialogs.Add(new BotDialog());
            MainBot.Trainer.StartTraining();

            Debug.Log("Load rescource JSON: " + tileFile);

            //When the bot generates a response simply display it.
            MainBot.MainUser.ResponseReceived += (sender, evt) =>
            {
                if (evt.Response.Messages.Count == 0)
                {
                    Debug.Log(evt.Response.Text);
                    AddMessage($"Bot: {evt.Response.Text}", MessageType.Bot);
                }
                else
                {
                    foreach (var message in evt.Response.Messages)
                    {
                        if (message is TextMessage textMessage)
                        {
                            var textValue = textMessage.GetRandomText();
                            AddMessage($"Bot: {textValue}", MessageType.Bot);
                        }
                    }
                }
            };
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
    }