Beispiel #1
0
 protected override Unifiable ProcessChangeU()
 {
     if (CheckNode("state"))
     {
         try
         {
             var    varMSM             = botActionMSM;
             string payload            = templateNodeInnerText.ToValue(query);
             string payload3           = InnerXmlText(templateNode);
             string prevLastDefMachine = varMSM.lastDefMachine;
             string state         = GetAttribValue("name", null);
             string machine       = GetAttribValue("machine", prevLastDefMachine);
             string init_prob_str = GetAttribValue("init_prob", "0.1");
             string self_prob_str = GetAttribValue("self_prob", "0.1");
             double init_prob     = double.Parse(init_prob_str);
             double self_prob     = double.Parse(self_prob_str);
             varMSM.lastDefState = state;
             MachineSideEffect(() =>
             {
                 varMSM.lastDefState = prevLastDefMachine;
                 varMSM.defState(machine, state, init_prob, self_prob);
                 string responseCode = "<aiml graph=\"msm\"> " + payload3 + " </aiml>";
                 AddSideEffect("Add AIML " + responseCode, () => TargetBot.AddAiml(responseCode));
             });
         }
         catch (Exception e)
         {
             writeToLogWarn("MSMWARN: " + e);
         }
     }
     return(Unifiable.Empty);
 }
        protected override Unifiable ProcessChangeU()
        {

            if (CheckNode("responsetopic"))
            {
                try
                {
                    var varMSM = botActionMSM;
                    string payload = templateNodeInnerText.ToValue(query);
                    string payload2 = Recurse();
                    string payload3 = InnerXmlText(templateNode);
                    string machine = GetAttribValue("machine",  varMSM.lastDefMachine);
                    string myState = GetAttribValue("state", varMSM.lastDefState);
                    string myTopic = GetAttribValue("topic", null);
                    string prob_str = GetAttribValue("prob", "0.1");
                    double prob = double.Parse(prob_str);
                    payload= payload.Replace("rcategory", "category");
                    payload= payload.Replace("rpattern", "pattern");
                    string responseCode = "<aiml graph=\"msm\"> <topic name=\"" + myTopic + "\"> " + payload + " </topic> </aiml>";
                    AltBot.writeDebugLine("MSM: response_topic ResponseCode = {0}", responseCode);
                    MachineSideEffect(() => varMSM.addResponse(machine, myState, myTopic, prob));
                    // TODO: define machine-state -> topic
                    AddSideEffect("Add AIML " + responseCode, () => TargetBot.AddAiml(responseCode));

                }
                catch (Exception e)
                {
                    writeToLogWarn("MSMWARN: " + e);
                }

            }
            return Unifiable.Empty;

        }
Beispiel #3
0
        protected Unifiable ProcessAsIfFileLoading()
        {
            {
                GraphMaster g         = request.Graph;
                var         g0        = g;
                String      graphName = GetAttribValue("graph", null);
                if (graphName != null)
                {
                    g = Proc.GetGraph(graphName, g0);
                    if (g != null)
                    {
                        request.Graph = g;
                    }
                }
                Unifiable path    = GetAttribValue("filename,uri,file,url,dir,path,pathname,directory", null);
                string    command = GetAttribValue("command,cmd", null);
                try
                {
                    //templateNode.LocalName
                    string documentInfo = DocumentInfo();
                    request.CurrentlyLoadingFrom = documentInfo;
                    request.Graph = request.Graph;
                    string innerXML = InnerXmlText(templateNode);


                    if (!string.IsNullOrEmpty(command))
                    {
                        string more = "";
                        if (!string.IsNullOrEmpty(innerXML))
                        {
                            more = " - " + innerXML;
                        }
                        TargetBot.BotDirective(request.Requester, request,
                                               "@" + command + " " + request.Graph.ScriptingName + more,
                                               writeToLog);
                        //QueryHasSuceededN++;
                    }
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(innerXML) && innerXML.Contains("<"))
                            {
                                try
                                {
                                    long successes = request.Loader.loadAIMLNode(templateNode);
                                    return("" + successes);
                                }
                                finally
                                {
                                }
                            }
                            else if (path == "")
                            {
                                writeToLogWarn(
                                    "ERROR! Attempted (but failed) to <learn> some new AIML from the following URI: '{0}' - '{1}'",
                                    path, innerXML);
                            }
                            else
                            {
                                path = path ?? innerXML;
                                request.CurrentFilename = path;
                                long forms = request.Loader.loadAIMLURI(path);
                                QueryHasSuceededN++;
                                return("" + forms); // Succeed();
                            }
                        }
                        catch (ChatSignal e)
                        {
                            throw;
                        }
                        catch (Exception e2)
                        {
                            Proc.writeToLog(e2);
                            writeToLogWarn(
                                "ERROR! Attempted (but failed) to <learn> some new AIML from the following URI: {0} error {1}",
                                path, e2);
                        }
                    }
                    return(Succeed("learned something"));
                }
                finally
                {
                    request.Graph = g0;
                }
            }
        }