示例#1
0
        protected override Unifiable ProcessChangeU()
        {
            if (CheckNode("evidencepattern"))
            {
                try
                {
                    var varMSM = botActionMSM;

                    string payload = templateNodeInnerText.ToValue(query);

                    string evidence = GetAttribValue("evidence", varMSM.lastDefEvidence);
                    string prob_str = GetAttribValue("prob", "1.0");
                    double prob     = double.Parse(prob_str);
                    //string quote = "" + '\u0022' + "";
                    string quote        = "'";
                    string evidenceCode =
                        //@"<aiml graph=" + quote + "msm" + quote + ">" +
                        @"<topic name=" + quote + "CEP" + quote + " > <category><pattern>" + payload + "</pattern>" +
                        @"<template><think><setevidence evidence=" + quote + evidence + quote +
                        @" prob=" + quote + prob_str + quote +
                        @" /></think>ep " + evidence + "</template></category></topic>";
                    //@"</aiml>";
                    //Proc.AddAiml(evidenceCode);
                    GraphMaster myGraph = request.GetGraph("msm");
                    AddSideEffect("ADD AIML " + evidenceCode, () => Proc.AddAiml(myGraph, evidenceCode));

                    AltBot.writeDebugLine("MSM: evidence_pattern evidenceCode = {0}", evidenceCode);
                }
                catch (Exception e)
                {
                    writeToLogWarn("MSMWARN: " + e);
                }
            }
            return(Unifiable.Empty);
        }
示例#2
0
        private GraphMaster SetupUserWithGraph(string newname, string newkey, User newuser)
        {
            GraphMaster graph = GetUserGraph(newkey);

            SetupUserWithGraph0(graph, newname, newkey, newuser);
            return(graph);
        }
        protected override Unifiable ProcessChangeU()
        {
            if (loadTemplate == null)
            {
                writeToLogWarn("Should already contain a loadTemplate! ");
                loadTemplate = PrepairTemplateNodeToBecomeSource();
            }
            var         saveOpts = request.LoadOptions;
            Unifiable   vv       = null;
            GraphMaster GM       = request.Graph;
            int         size     = GM.Size;

            try
            {
                request.CurrentlyLoadingFrom = DocumentInfo();
                request.Loader.loadAIMLNode(loadTemplate);
            }
            finally
            {
                request.LoadOptions = saveOpts;
            }
            int    newSize = GM.Size;
            int    change  = newSize - size;
            string ch      = "Loaded " + change + " into " + GM + " was " + size;

            if (FinalResult == (string)null)
            {
                return(Succeed(ch));
            }
            return(Succeed(ch + " " + FinalResult));
        }
示例#4
0
        //public override Unifiable FullPath { get; set; }

        public static TemplateInfo GetTemplateInfo(XmlNode template, Unifiable guard, Unifiable thatInfo, Node node,
                                                   CategoryInfo category, GraphMaster graphMaster)
        {
            bool prev = NoInfo;

            try
            {
                NoInfo = false;
                //return new TemplateInfo(template, guard, node, category);
                Unifiable responseInfo = graphMaster.FindResponse(template, template.OuterXml);
                category.GraphmasterNode = node;
                //category.Graph = node;
                if (thatInfo != null)
                {
                    category.That = thatInfo;
                }
                TemplateInfo info = category as TemplateInfo;
                info.Guard    = guard;
                info.Response = responseInfo;
                return(info);
            }
            finally
            {
                NoInfo = prev;
            }
        }
示例#5
0
 public bool IsAllowedGraph(GraphMaster graph)
 {
     if (!TheRequest.IsAllowedGraph(graph))
     {
         return(false);
     }
     return(true);
 }
示例#6
0
 public GraphQuery(Unifiable inputPath, Request request, GraphMaster gMaster, MatchState mstate)
     : base(request)
 {
     InputPath   = inputPath;
     TheRequest  = (MasterRequest)request;
     graphMaster = gMaster;
     matchState  = mstate;
 }
示例#7
0
        public static string GetTemplateSource(IEnumerable CI, PrintOptions printOptions)
        {
            if (CI == null)
            {
                return("");
            }
            StringWriter fs = new StringWriter();

            GraphMaster.PrintToWriter(CI, printOptions, fs, null, TimeSpan.Zero);
            return(fs.ToString());
        }
示例#8
0
 // Start is called before the first frame update
 void Start()
 {
     Instance = this;
     Covid19Viz[] covidViz = Globe.GetComponents <Covid19Viz>();;
     StartCoroutine(EnableScript(1, covidViz[1]));
     StartCoroutine(EnableScript(2, covidViz[2]));
     canvas.worldCamera = Camera.main;
     //CovidData3DInstance.ClickedOnDataEvent += EnableGraphs;
     ConfirmedGraph.gameObject.SetActive(false);
     DeathGraph.gameObject.SetActive(false);
     RecoveredGraph.gameObject.SetActive(false);
     ShowInfoPanel(false);
     BigGraphContainer.gameObject.SetActive(false);
     smallGraph_initPos   = smallGraphContainer.position;
     smallGraph_initScale = smallGraphContainer.localScale;
 }
示例#9
0
        public void SetCategoryTag(Unifiable generatedPath, Unifiable patternInfo, CategoryInfo category,
                                   XmlNode outerNode, XmlNode templateNode, Unifiable guard, Unifiable thatInfo)
        {
#if false
            var node = this.RootNode;
            if (SilentTagsInPutParent && AIMLLoader.IsSilentTag(templateNode))
            {
                GraphMaster parent1 = makeParent();
                this.Parents.Add(parent1);
                parent1.Size++;
                node = parent1.RootNode;
                writeToLog("Adding to Parent " + category);
            }
            Node created = Node.addCategoryTag(node, generatedPath, patternInfo,
                                               category, outerNode, templateNode, guard, thatInfo, this);

            this.Size++;
#endif
            // keep count of the number of categories that have been processed
        }
示例#10
0
 private void SetupUserWithGraph0(GraphMaster graph, string newname, string newkey, User newuser)
 {
     //graph.AddParallelMT(AltBot.TheUserListenerGraph, newuser.WriteToUserTrace);
     newuser.StartGraph = graph;
     newuser.UserID     = newkey;
     newuser.UserName   = newname;
     OnBotCreated(() => graph.AddGenlMT(DefaultStartGraph, newuser.WriteToUserTrace));
     //newuser.Predicates.IsIdentityReadOnly = false;
     newuser.Predicates.addSetting("name", newname);
     newuser.Predicates.addSetting("id", newkey);
     newuser.Predicates.InsertFallback(() => AllUserPreds);
     newuser.AddTodoItem(() =>
     {
         newuser.SyncDirectory(GetUserDir(newkey));
         if (graph.Size == 0)
         {
             graph.UnTraced = true;
         }
     });
     //newuser.Predicates.IsIdentityReadOnly = true;
 }
示例#11
0
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return(false);
            }
            GraphMaster useRef = InGraph ?? Graph;

            if (useRef == null)
            {
                TemplateInfo ci = obj as TemplateInfo;
                if (ci != null)
                {
                    useRef = ci.InGraph ?? ci.Graph;
                }
            }
            if (useRef == null || useRef.CompareTemplatesForReferenceIdentity)
            {
                return(ReferenceEquals(this, obj));
            }
            return(Equals(obj as CategoryInfo, true, false));
        }
示例#12
0
        public static R FromLoaderOper <R>(Func <R> action, GraphMaster gm, LoaderOptions loadOpts)
        {
            OutputDelegate prev = userTraceRedir;

            try
            {
                userTraceRedir = gm.writeToLog;
                try
                {
                    if (!loadOpts.NeedsLoaderLock)
                    {
                        return(action());
                    }
                    lock (ErrorList)
                    {
                        lock (gm.LockerObject)
                        {
                            return(action());
                        }
                    }
                }
                catch (Exception e)
                {
                    AltBot.writeDebugLine("ERROR: LoaderOper {0}", e);
                    if (!ChatOptions.AllowRuntimeErrors)
                    {
                        return(default(R));
                    }
                    throw;
                    //return default(R);
                }
            }
            finally
            {
                userTraceRedir = prev;
            }
        }
示例#13
0
        /// <summary>
        /// Adds a category to the graphmaster structure using the given topic
        /// </summary>
        /// <param name="node">the XML node containing the category</param>
        /// <param name="topicName">the topic to be used</param>
        /// <param name="filename">the file from which this category was taken</param>
        private void ProcessCategory(XmlNode node, string topicName, string filename)
        {
            // reference and check the required nodes
            XmlNode pattern  = FindNode("pattern", node);
            XmlNode template = FindNode("template", node);

            if (object.Equals(null, pattern))
            {
                throw new XmlException("Missing pattern tag in a node found in " + filename);
            }
            if (object.Equals(null, template))
            {
                throw new XmlException("Missing template tag in the node with pattern: " + pattern.InnerText + " found in " + filename);
            }

            string categoryPath = GeneratePath(node, topicName, false);

            // o.k., add the processed AIML to the GraphMaster structure
            if (categoryPath.Length > 0)
            {
                try
                {
                    GraphMaster.AddCategory(categoryPath, template.OuterXml, filename);
                    // keep count of the number of categories that have been processed
                    GraphSize++;
                }
                catch
                {
                    _logger.LogError("Failed to load a new category into the graphmaster where the path = " + categoryPath + " and template = " + template.OuterXml + " produced by a category in the file: " + filename);
                }
            }
            else
            {
                _logger.LogWarning("Attempted to load a new category with an empty pattern where the path = " + categoryPath + " and template = " + template.OuterXml + " produced by a category in the file: " + filename);
            }
        }
示例#14
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;
                }
            }
        }
示例#15
0
 internal void AddAiml(GraphMaster myGraph, string evidenceCode)
 {
     mbot.AddAiml(myGraph, evidenceCode);
 }
示例#16
0
 public GraphMaster GetGraph(string graphName, GraphMaster current)
 {
     return(mbot.GetGraph(graphName, current));
 }
示例#17
0
 public static void PrintTemplates(IEnumerable CI, OutputDelegate console, PrintOptions printOptions, TimeSpan sleepBetween)
 {
     GraphMaster.PrintToWriter(CI, printOptions, new OutputDelegateWriter(console), null, sleepBetween);
 }
示例#18
0
/*
 *      public Request(String rawInput, AltAIMLbot.User user, AltBot bot)
 *          : this(rawInput, user, bot, null)
 *      {
 *      }
 *
 *            public MasterRequest(String rawInput, AltAIMLbot.User user, AltBot bot, AltAIMLParser.Request r)
 *          : base(rawInput, user, bot, r, null)
 *      {
 *      }
 */
        public MasterRequest(string rawInput, User user, string thatSaid, User targetUser, AltBot bot, Request parent, GraphMaster graphMaster)
            : base(rawInput, user, thatSaid, targetUser, bot, parent, graphMaster)
        {
        }
示例#19
0
        /// <summary>
        /// The method that does the actual Processing of the text.
        /// </summary>
        /// <returns>The resulting Processed text</returns>
        protected override Unifiable ProcessChangeU()
        {
            if (templateNode.NodeType == XmlNodeType.Comment)
            {
                return(Succeed(templateNode.Value));
            }
            if (templateNode.NodeType == XmlNodeType.Text)
            {
                string s = Trim(templateNode.InnerText);
                if (String.IsNullOrEmpty(s))
                {
                    return(Unifiable.Empty);
                }
                return(s);
            }
            string currentNodeName = templateNode.Name.ToLower();

            if (currentNodeName == "substitutions")
            {
                var prevDict = request.TargetSettings;
                // Process each of these child "settings"? nodes
                try
                {
                    request.TargetSettings = request.TargetBot.InputSubstitutions;
                    SettingsDictionaryReal.loadSettingNode(request.TargetSettings, templateNode, SettingsPolicy.Default, request);
                }
                finally
                {
                    request.TargetSettings = prevDict;
                }
                return(ProcessSucceed());
            }
            if (currentNodeName == "genlmt")
            {
                string name       = GetAttribValue(templateNode, "name,mt,to,super,into", null);
                string removeTo   = GetAttribValue(templateNode, "remove", null);
                string from       = GetAttribValue(templateNode, "graph,from", null);
                bool   deleteLink = false;
                if (name == null)
                {
                    name = Trim(templateNode.InnerText);
                }
                if (removeTo != null)
                {
                    deleteLink = true;
                    name       = removeTo;
                }
                GraphMaster FROM = request.GetGraph(from);
                GraphMaster TO   = request.GetGraph(name);
                if (FROM != null && TO != null)
                {
                    if (deleteLink)
                    {
                        FROM.RemoveGenlMT(TO, writeToLog);
                    }
                    else
                    {
                        FROM.AddGenlMT(TO, writeToLog);
                    }
                    return(Succeed("GENLMT: " + FROM + " => " + name + " => " + TO));
                }
            }
            if (currentNodeName == "sraigraph")
            {
                string name = GetAttribValue(templateNode, "name,mt,to,super,into", null);
                string from = GetAttribValue(templateNode, "graph,from", null);
                if (name == null)
                {
                    name = Trim(templateNode.InnerText);
                }
                GraphMaster FROM = request.GetGraph(from);
                GraphMaster TO   = request.GetGraph(name);
                if (FROM != null && TO != null)
                {
                    FROM.Srai = name;
                    return(Succeed("SRAI: " + FROM + " => " + name + " => right now " + TO));
                }
                return(Failure("FROM '" + from + "'='" + FROM + "'" + " TO '" + name + "'='" + TO + "'"));
            }
            if (currentNodeName == "meta")
            {
                return(Succeed("UNUSED: " + templateNode.OuterXml));
            }
            if (currentNodeName == "#comment")
            {
                return(Succeed("UNUSED: " + templateNode.OuterXml));
            }
            if (currentNodeName == "item")
            {
                SettingsDictionaryReal.loadSettingNode(request.TargetSettings, templateNode, SettingsPolicy.Default, request);
                return(ProcessSucceed());
            }
            if (currentNodeName == "bot")
            {
                SettingsDictionaryReal.loadSettingNode(request.TargetBot.Settings, templateNode, SettingsPolicy.Default, request);
                return(ProcessSucceed());
            }
            string currentNodeOuterXml = templateNode.OuterXml;

            if (currentNodeOuterXml.Length > 280)
            {
                currentNodeOuterXml = TextFilter.ClipString(currentNodeOuterXml, 280);
            }
            writeToLog("ImmediateAiml: " + currentNodeOuterXml);

            /*
             * <TestCase name="connect">
             *      <Input>CONNECT</Input>
             *      <ExpectedAnswer>Connected to test case AIML set.</ExpectedAnswer>
             * </TestCase>
             */

            if (templateNode.NodeType == XmlNodeType.Comment)
            {
                return(ProcessSucceed());
            }

            // pull from late bound sustituion dictionaries
            var sd = request.GetSubstitutions(currentNodeName, false);

            if (sd != null)
            {
                if (FinalResultValid)
                {
                    return(FinalResult);
                }
                if (!Unifiable.IsIncomplete(FinalResult))
                {
                    return(FinalResult);
                }
                Func <Unifiable, Unifiable> Format = (v) => ApplySubstitutions.Substitute(sd, templateNodeInnerText);
                if (base.isRecursive && !ReadOnly)
                {
                    FinalResult = Format(TransformAtomically(null, true));
                    return(finalResult.Value);
                }
                return(FinalResult = TransformAtomically(Format, false));
            }

            if (AltBot.UnknownTagsAreBotVars)
            {
                var dict = Proc.GlobalSettings;
                if (dict.containsSettingCalled(currentNodeName))
                {
                    var v = dict.grabSetting(currentNodeName);
                    if (!Unifiable.IsMissing(v))
                    {
                        return(v);
                    }
                }
            }
            var            vs         = Proc.EvalAiml(templateNode, request, request.writeToLog);
            StringBuilder  sb         = new StringBuilder();
            int            writeThrus = 0;
            int            total      = 0;
            OutputDelegate WriteLine  = DLRConsole.SystemWriteLine;

            foreach (var node in vs)
            {
                total++;
                string nodeOuterXml = ToXmlValue(node);
                WriteLine(nodeOuterXml);
                string p = GetAttribValue(node, "PASSED", "FALSE");
                if (p == "False")
                {
                    writeThrus++;
                    sb.Append("\n" + nodeOuterXml.Replace("\" ", "\"\n ") + "\n");
                }
                WriteLine("");
            }

            WriteLine("");
            WriteLine("");
            WriteLine("" + writeThrus);
            WriteLine("");
            string ss = sb.ToString();

            WriteLine(ss);
            WriteLine("");
            WriteLine("");
            WriteLine("");
            return(Succeed("total is " + total));
        }
示例#20
0
 // Use this for initialization
 void Start()
 {
     selector   = GetComponent <SelectionDisplay> ();
     underGraph = GameObject.FindObjectOfType <GraphMaster> ();
 }