예제 #1
0
        // This function takes in the speakers transcript and generates Nico's response
        // Output is:
        //              String - Transcript - path of the response file (what Nico said)
        //              Int - Movement - movement code (overwritten later by python movement code)
        //              Int - AnswerStep - did Nico answer this step
        private static Tuple <string, int, string> dialogueManager(string userid, string path, List <int> problemStep, int speakerSpoke, string transcript, DateTime time, bool checkIfAnswered, string condition)
        {
            // Return variables
            string answerStep       = "no answer";
            int    nicoMovementCode = 1;

            string pathTranscriptFile = "";
            string pathResponseFile   = "";
            string BOT          = "";
            string problemset   = (SQLConditionGenderInfo.GetProblemSet(userid)).ToLower();
            string responseText = "";

            /*  CREATE BOT NAME
             *
             * Pandorabots available:
             *      asocialemma        Corresponds to Emma Single Session Problem Set and includes social dialogue
             *      anonsocialemma     Corresponds to Emma Single Session Problem Set
             *      emmab          Corresponds to Emma Multi Session 1
             *      emmac               Corresponds to Emma Multi Session 1
             *      emmad               Corresponds to Emma Multi Session 1
             *      emmae               Corresponds to Emma Multi Session 1
             *      emmaf               Corresponds to Emma Multi Session 1
             *      gsocialnico        Corresponds to Nico Single Session Problem Set and includes social dialogue
             *      gnonsocialnico     Corresponds to Nico Single Session Problem Set, no social dialogue
             * */

            if (problemset == "a")
            {
                if (condition.Contains("nonsocial"))
                {
                    BOT = problemset + "nonsocialemma";
                }
                else
                {
                    BOT = problemset + "socialemma";
                }
            }
            else if (problemset == "g")
            {
                if (condition.Contains("nonsocial"))
                {
                    BOT = problemset + "nonsocialnico";
                }
                else
                {
                    BOT = problemset + "socialnico";
                }
            }
            else
            {
                BOT = "emma" + problemset;
            }

            try
            {
                // Save transcript to a file so pandora python api program can read it in; save response in a file as well
                pathResponseFile   = string.Format("{0}-{1:yyyy-MM-dd_hh-mm-ss-tt}", path + "data\\transcripts\\" + userid + "_nicoresponse", time) + ".txt";
                pathTranscriptFile = string.Format("{0}-{1:yyyy-MM-dd_hh-mm-ss-tt}", path + "data\\transcripts\\" + userid + "_transcript", time) + ".txt";
                StreamWriter transcriptFile = new StreamWriter(pathTranscriptFile);
                transcriptFile.Write(transcript);
                transcriptFile.Close();

                string pythonexe  = Globals.pythonDirectory() + "python.exe";
                string pythonargs = Globals.pythonDirectory() + "NaoNRIPrograms\\VerbalManager\\chatPandoraBot.py " + pathTranscriptFile + " " + pathResponseFile + " " + BOT + " " + userid;
                Debug.WriteLine("di: the pythonargs is: " + pythonargs);

                ExternalMethodsCaller.PythonProcess(pythonexe, pythonargs);

                responseText = readResponse(pathResponseFile);
                string lastAnswer = SQLNicoState.ReadNicoState_Answer(userid);
                if (checkIfAnswered && (responseText.Contains("put the answer")))
                {
                    answerStep = "answering";
                }
            }
            catch (Exception error)
            {
                // ** WRITE OUT TO DB
                Debug.WriteLine("di: exception found here");
                SQLLog.InsertLog(DateTime.Now, error.Message, error.StackTrace, "ResponseGeneration.generateNicoResponse", 1);
            }

            Tuple <string, int, string> result = new Tuple <string, int, string>(responseText, nicoMovementCode, answerStep);

            return(result);
        }