예제 #1
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="bot">The bot involved in this request</param>
 /// <param name="user">The user making the request</param>
 /// <param name="query">The query that originated this node</param>
 /// <param name="request">The request inputted into the system</param>
 /// <param name="result">The result to be passed to the user</param>
 /// <param name="templateNode">The node to be processed</param>
 public system(AIMLbot.Bot bot,
               AIMLbot.User user,
               AIMLbot.Utils.SubQuery query,
               AIMLbot.Request request,
               AIMLbot.Result result,
               XmlNode templateNode)
     : base(bot, user, query, request, result, templateNode)
 {
 }
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="bot">The bot involved in this request</param>
 /// <param name="user">The user making the request</param>
 /// <param name="query">The query that originated this node</param>
 /// <param name="request">The request inputted into the system</param>
 /// <param name="result">The result to be passed to the user</param>
 /// <param name="templateNode">The node to be processed</param>
 public condition(AIMLbot.Bot bot,
                  AIMLbot.User user,
                  AIMLbot.Utils.SubQuery query,
                  AIMLbot.Request request,
                  AIMLbot.Result result,
                  XmlNode templateNode)
     : base(bot, user, query, request, result, templateNode)
 {
     this.isRecursive = false;
 }
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="bot">The bot involved in this request</param>
 /// <param name="user">The user making the request</param>
 /// <param name="query">The query that originated this node</param>
 /// <param name="request">The request inputted into the system</param>
 /// <param name="result">The result to be passed to the user</param>
 /// <param name="templateNode">The node to be processed</param>
 public javascript(AIMLbot.Bot bot,
                   AIMLbot.User user,
                   AIMLbot.Utils.SubQuery query,
                   AIMLbot.Request request,
                   AIMLbot.Result result,
                   XmlNode templateNode)
     : base(bot, user, query, request, result, templateNode)
 {
     // Preprocess javascript, return result and then process result
     this.isRecursive = false;
 }
예제 #4
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text.Trim();

            if (textBox1.Text == string.Empty)
            {
                return;
            }

            AIMLbot.Request req = new AIMLbot.Request(textBox1.Text, _user, _bot);

            tbLog.AppendText("You> " + textBox1.Text);
            tbLog.AppendText(Environment.NewLine);

            AIMLbot.Result r = _bot.Chat(req);

            string unfilteredResp = r.Output;

            string resp = string.Empty;

            string[] cmds = Common.GetTextBetween(unfilteredResp, out resp, '[', ']');

            resp = resp.Replace("\r", string.Empty);
            resp = resp.Replace("\n", string.Empty);
            resp = EZ_Builder.Scripting.VariableManager.SubsituteWithValues(resp);
            resp = resp.Replace("\"", "");
            resp = Regex.Replace(resp, @"\s+", " ");

            tbLog.AppendText("Bot> " + resp);
            tbLog.AppendText(Environment.NewLine);

            EZ_Builder.Scripting.VariableManager.SetVariable(
                _cf.STORAGE[ConfigTitles.RESPONSE_VARIABLE].ToString(),
                resp);

            if (_cf.STORAGE[ConfigTitles.RESPONSE_SCRIPT].ToString() != string.Empty)
            {
                EZ_Builder.Scripting.EZScriptManager.GetExecutor(_EXECUTOR_NAME).StartScriptASync(_cf.STORAGE[ConfigTitles.RESPONSE_SCRIPT].ToString());
            }

            foreach (string cmd in cmds)
            {
                Invokers.SetAppendText(tbLog, true, 50, "Exec: {0}", cmd);

                string response = EZ_Builder.Scripting.EZScriptManager.GetExecutor(_EXECUTOR_NAME + "_embedded").ExecuteScriptSingleLine(cmd);

                if (response != string.Empty)
                {
                    Invokers.SetAppendText(tbLog, true, 50, response);
                }
            }

            textBox1.Clear();
        }
예제 #5
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="bot">The bot involved in this request</param>
 /// <param name="user">The user making the request</param>
 /// <param name="query">The query that originated this node</param>
 /// <param name="request">The request itself</param>
 /// <param name="result">The result to be passed back to the user</param>
 /// <param name="templateNode">The node to be processed</param>
 public AIMLTagHandler(AIMLbot.Bot bot,
                       AIMLbot.User user,
                       AIMLbot.Utils.SubQuery query,
                       AIMLbot.Request request,
                       AIMLbot.Result result,
                       XmlNode templateNode) : base(bot, templateNode.OuterXml)
 {
     this.user         = user;
     this.query        = query;
     this.request      = request;
     this.result       = result;
     this.templateNode = templateNode;
 }
예제 #6
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="bot">The bot involved in this request</param>
 /// <param name="user">The user making the request</param>
 /// <param name="query">The query that originated this node</param>
 /// <param name="request">The request itself</param>
 /// <param name="result">The result to be passed back to the user</param>
 /// <param name="templateNode">The node to be processed</param>
 public AIMLTagHandler(   AIMLbot.Bot bot, 
     AIMLbot.User user,
     AIMLbot.Utils.SubQuery query,
     AIMLbot.Request request,
     AIMLbot.Result result,
     XmlNode templateNode)
     : base(bot,templateNode.OuterXml)
 {
     this.user = user;
     this.query = query;
     this.request = request;
     this.result = result;
     this.templateNode = templateNode;
 }
예제 #7
0
        protected override Unifiable ProcessChangeU()
        {
            try
            {
                int    d      = request.GetCurrentDepth();
                object prefix = string.Format("{0}: SRAI({1}/{2})", request.Graph, depth, d);
                if (d > request.SraiDepth.Max)
                {
                    writeToLog(prefix + "WARNING Depth pretty deep " + templateNode + " returning empty");
                    return(Unifiable.Empty);
                }
                if (depth > 30)
                {
                    writeToLog(prefix + "WARNING Depth pretty deep " + templateNode + " returning empty");
                    return(Unifiable.Empty);
                }
                if (this.templateNode.Name.ToLower() == "srai")
                {
                    Unifiable templateNodeInnerValue = Recurse();
                    if (!templateNodeInnerValue.IsEmpty)
                    {
                        AIMLbot.Request subRequest = request.CreateSubRequest(templateNodeInnerValue, this.user,
                                                                              this.Proc, (AIMLbot.Request)request);


                        subRequest.Graph = request.Graph.Srai;

                        var ti = query.CurrentTemplate;
                        if (ti != null)
                        {
                            subRequest.UsedTemplates.Add(ti);
                        }

                        // make sure we don't keep adding time to the request
                        bool   showDebug          = true;
                        string subRequestrawInput = subRequest.rawInput;
                        if (subRequestrawInput.Contains("SYSTEMANIM") || subRequestrawInput.Contains("HANSANIM"))
                        {
                            showDebug = false;
                        }

                        if (showDebug)
                        {
                            writeToLog(prefix + " CALLING '" + subRequestrawInput + "'");
                        }


                        if (mybot.chatTrace)
                        {
                            //  mybot.bot.writeChatTrace("\"L{0}\" -> \"S{1}\" ;\n", depth - 1, depth-1);
                            // mybot.bot.writeChatTrace("\"L{0}\" -> \"S{1}\" ;\n", depth, depth);
                            //mybot.bot.writeChatTrace("\"S{0}\" -> \"SRC:{1}\" ;\n", depth, CatTextInfo());

                            //mybot.bot.writeChatTrace("\"S{0}\" -> \"S{1}\" ;\n", depth - 1, depth);
                            //mybot.bot.writeChatTrace("\"S{0}\" -> \"SIN:{1}\" ;\n", depth, subRequestrawInput);
                            //mybot.bot.writeChatTrace("\"SIN:{0}\" -> \"LN:{1}\" ;\n", subRequestrawInput, CatTextInfo());
                        }
                        if (depth > 200)
                        {
                            writeToLog(prefix + " FAILING TOOOO DEEEEP '" + subRequestrawInput + "'");
                            return(Unifiable.Empty);
                        }
                        AIMLbot.Result subResult;
                        var            prev   = subRequest.GraphsAcceptingUserInput;
                        var            prevSO = user.SuspendAdd;
                        try
                        {
                            subRequest.GraphsAcceptingUserInput = true;
                            //var newresult = new AIMLbot.Result(request.user, Proc, request);
                            //subRequest.result = newresult;
                            user.SuspendAdd = true;
                            if (request.IsTraced)
                            {
                                subRequest.IsTraced = !showDebug;
                            }
                            subResult = this.Proc.Chat0(subRequest, subRequest.Graph);
                        }
                        finally
                        {
                            user.SuspendAdd = prevSO;
                            subRequest.GraphsAcceptingUserInput = prev;
                        }
                        this.request.hasTimedOut = subRequest.hasTimedOut;
                        var subQueryRawOutput = subResult.RawOutput.Trim();
                        if (Unifiable.IsNullOrEmpty(subQueryRawOutput))
                        {
                            if (showDebug)
                            {
                                writeToLog(prefix + " MISSING RETURN ");
                            }
                            if (mybot.chatTrace)
                            {
                                mybot.writeChatTrace("\"L{0}\" -> \"S{1}\" ;\n", depth, depth);
                                mybot.writeChatTrace("\"S{0}\" -> \"SIN:{1}\" ;\n", depth, subRequestrawInput);
                                //mybot.writeChatTrace("\"SIN:{0}\" -> \"LN:{1}\" ;\n", subRequestrawInput, CatTextInfo());
                                mybot.writeChatTrace("\"SIN:{0}\" -> \"PATH:{1}\" [label=\"{2}\"] ;\n",
                                                     subRequestrawInput, depth, subResult.NormalizedPaths);
                                mybot.writeChatTrace("\"PATH:{0}\" -> \"LN:{1}\" [label=\"{2}\"] ;\n", depth, depth,
                                                     LineNumberTextInfo());

                                mybot.writeChatTrace("\"LN:{0}\" -> \"RPY:MISSING({1})\" ;\n", depth, depth);
                            }

                            return(Unifiable.Empty);
                        }
                        else
                        {
                            string sss = result.ToString();
                            if (showDebug)
                            {
                                writeToLog("{0} SUCCESS RETURN {1}  {2} '{3}'", prefix, subRequestrawInput,
                                           subResult.Score, subQueryRawOutput);
                                if (query != null)
                                {
                                    if (query.CurrentTemplate != null)
                                    {
                                        writeToLog("SCORE {0}*{1}->{2} ",
                                                   subResult.Score, query.CurrentTemplate.Rating,
                                                   query.CurrentTemplate.Rating *= subResult.Score);
                                    }
                                }
                            }
                            this.request.AddSubResult(result);
                            this.request.AddSubResult(subResult);
                        }

                        if (mybot.chatTrace)
                        {
                            mybot.writeChatTrace("\"L{0}\" -> \"S{1}\" ;\n", depth, depth);
                            mybot.writeChatTrace("\"S{0}\" -> \"SIN:{1}\" ;\n", depth, subRequestrawInput);
                            mybot.writeChatTrace("\"SIN:{0}\" -> \"PATH:{1}\" [label=\"{2}\"] ;\n", subRequestrawInput,
                                                 depth, subResult.NormalizedPaths);
                            mybot.writeChatTrace("\"PATH:{0}\" -> \"LN:{1}\" [label=\"{2}\"] ;\n", depth, depth,
                                                 LineNumberTextInfo());
                            mybot.writeChatTrace("\"LN:{0}\" -> \"RPY:{1}\" ;\n", depth, subQueryRawOutput);
                        }
                        return(subResult.Output);
                    }
                    else
                    {
                        if (templateNodeInnerValue.IsEmpty)
                        {
                            writeToLog("InnerValue.IsEmpty! " + initialString);
                            return(templateNodeInnerValue);
                        }
                    }
                }
                return(Unifiable.Empty);
            }
            finally
            {
                depth--;
            }
        }
예제 #8
0
 private static void Talk(String toWhom, String komunikat)
 {
     AIMLbot.User myUser = new AIMLbot.User(toWhom, myBot);
     if (najblizszeZrodlo != null)
         if ((myEnergy < cennikSwiata.initialEnergy - ZnanaMapa.znajdzPole(najblizszeZrodlo.x,
                     najblizszeZrodlo.y).getEnergia()) || (myEnergy < kosztDoZrodla
                     + 2 * cennikSwiata.speakCost))
             return;
     AIMLbot.Request r = new AIMLbot.Request(komunikat, myUser, myBot);
     AIMLbot.Result res = myBot.Chat(r);
     if ((res.Output == "")||(res.Output == "Nie rozumiem!"))
     {
         czyRozmawiam = false;
         return;
     }
     Console.WriteLine("Ja: " + res.Output);
     Speak(res.Output);
 }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Chatbot.Trigger"/> class.
        /// </summary>
        /// <param name="Chatbot">Chatbot.</param>
        public void Initialize(GameObject tmpchatbot)
        {
            // Save delivered GameObject
            chatbot = tmpchatbot;
            // Throw error if not Game Object delivered
            if (!chatbot)
            {
                Debug.LogWarning("To use chatbot you need to attatch ChatbotCore.cs script to a GameObject and pass GameObject to Chatbot. GameObject is empty.");
            }
            // Windows, Linux and Mac OSX
                        #if !(UNITY_WEBPLAYER || UNITY_WEBGL)
            else
            {
                // Initialize Program # variables
                bot     = new AIMLbot.Bot(this);
                user    = new AIMLbot.User("User", bot);
                request = new AIMLbot.Request("", user, bot);
                result  = new AIMLbot.Result(user, bot, request);
                // Global Settings
                Setting[] settings;
                // Gather all attatched settings from Scene
                settings = chatbot.GetComponentsInChildren <Setting>();
                // Loop through settings and
                foreach (Setting setting in settings)
                {
                    // Set global settings in Program# and Jurassic
                    SetGlobalSetting(setting.gameObject.name, setting.value);
                }
                // Load Settings from Scene Setting Components.
                bot.loadSettingsFromScene();
                // Load AIML files from AIML path defined in Settings.xml
                bot.loadAIMLFromFiles();

                // Define to or not to use JavaScript (Jurassic) in AIML
                bot.UseJavaScript = true;
                // Use Program # with Jurassic and Chatbot
                bot.ProgramSharpJSWithChatbot = true;
                // Create Triggers instance
                trigger = new Chatbot.Triggers();
                // Initializes triggers that are attatched
                // to the Chatbot. Needs to pass the
                // Chatbot Gameobject and Triggers instance
                trigger.Initialize(chatbot, this);
                // Create Motives instance
                motive = new Chatbot.Motives();
                // Initialize it
                motive.Initialize(chatbot);
                // Create Planner instance
                planner = new Chatbot.NestedPlanner();
                // Initialize planner
                planner.Initialize(chatbot, this, motive);
            }
                        #else
            // Webplayer plattform or WebGl
            ProgramSharpWebplayerCoroutine WebplayerCoroutine = chatbot.GetComponent <ProgramSharpWebplayerCoroutine>();
            if (WebplayerCoroutine != null && chatbot != null)
            {
                // Load settings from scene
                bot     = new AIMLbot.Bot(WebplayerCoroutine, Application.dataPath + "/Chatbot/Program #/advancedconfig/Settings.xml", true, this);
                user    = new AIMLbot.User("User", bot);
                request = new AIMLbot.Request("", user, bot);
                result  = new AIMLbot.Result(user, bot, request);

                // Define to or not to use JavaScript (Jurassic) in AIML
                bot.UseJavaScript = true;
                // Use Program # with Jurassic and Chatbot
                bot.ProgramSharpJSWithChatbot = true;
                // Create Triggers instance
                trigger = new Chatbot.Triggers();
                // Initializes triggers that are attatched
                // to the Chatbot. Needs to pass the
                // Chatbot Gameobject and Triggers instance
                trigger.Initialize(chatbot, this);
                // Create Motives instance
                motive = new Chatbot.Motives();
                // Initialize it
                motive.Initialize(chatbot);
                // Create Planner instance
                planner = new Chatbot.NestedPlanner();
                // Initialize planner
                planner.Initialize(chatbot, this, motive);
            }
            else
            {
                Debug.LogWarning("You need to attatch the Webplayer Component in Webplayer plattform mode.");
            }
                        #endif
        }