Exemplo n.º 1
0
        public int callDbPush(string myText, XmlNode expandWordnet)
        {
            // the defualt is true

            if (MayPush(myText, expandWordnet) == null)
            {
                return(-1);
            }
            WordExpander expandWithWordNet = WordNetExpand;

            bool tf;

            if (StaticXMLUtils.TryParseBool(expandWordnet, "wordnet,synonyms", out tf))
            {
                expandWithWordNet = tf ? (WordExpander)WordNetExpand : NoWordNetExpander;
            }

            ulong myDocID = IncDocId();
            Dictionary <ulong, string> contentIdPairs = new Dictionary <ulong, string>();

            contentIdPairs.Add(myDocID, myText);

            // Indexing:
            int numIndexed = Index(contentIdPairs, expandWithWordNet);

            writeToLog("Indexed {0} docs.", numIndexed);
            return(numIndexed);
        }
Exemplo n.º 2
0
        public string callDbQuery0(string searchTerm1, OutputDelegate dbgLog, Func <Unifiable> OnFalure, XmlNode templateNode, float threshold, bool expandWithWordNet, bool expandOnNoHits, out float reliablity)
        {
            checkDbLock();
            bool tf;

            if (StaticXMLUtils.TryParseBool(templateNode, "wordnet,synonyms", out tf))
            {
                expandWithWordNet = tf;
            }
            WordExpander wordNetExpander = expandWithWordNet ? (WordExpander)WordNetExpand : NoWordNetExpander;
            string       userFilter      = "";
            // Do we only want responses with the current user name in it ?
            // As in "what is my favorite color?"
            string onlyUserStr = StaticXMLUtils.GetAttribValue(templateNode, "onlyUser", "false").ToLower();

            if (onlyUserStr.Equals("true"))
            {
                userFilter = TripleStoreProxy.Entify(TheBot.BotUserID);
            }
            string res = callDbQueryStatic(SearchSources, searchTerm1, dbgLog, templateNode, threshold, out reliablity,
                                           userFilter, wordNetExpander);

            if (OnFalure != null && string.IsNullOrEmpty(res))
            {
                return(OnFalure());
            }
            return(res);
        }
        static public Unifiable SetSettingForType(string subject, SubQuery query, ISettingsDictionary dict, string name, string gName, object value, string setReturn, XmlNode templateNode)
        {
            string _sreturn = setReturn;

            setReturn = StaticXMLUtils.GetAttribValue <string>(templateNode, "set-return", () => _sreturn, query.ReduceStarAttribute <string>);

            Request request   = query.Request;
            AltBot  TargetBot = request.TargetBot;
            // try to use a global blackboard predicate
            User gUser = TargetBot.ExemplarUser;

            string    realName;
            Unifiable resultGet = SettingsDictionaryReal.grabSettingDefaultDict(dict, name, out realName);
            bool      shouldSet = ShouldSet(templateNode, dict, realName, value, resultGet, query);

            User         user = query.CurrentUser;
            ITripleStore userbotLuceneIndexer = (ITripleStore)user.mbot.TripleStore;
            string       userName             = user.UserID;

            if (!shouldSet)
            {
                writeToLog("!shouldSet ERROR {0} name={1} value={2} old={3}", dict, realName, value, resultGet);
                bool shouldSet2 = ShouldSet(templateNode, dict, realName, value, resultGet, query);
                return(ReturnSetSetting(dict, name, setReturn));
            }
            if (IsIncomplete(value))
            {
                if (UseLuceneForSet && userbotLuceneIndexer != null)
                {
                    userbotLuceneIndexer.retractAllTriple(userName, name);
                }
                SettingsDictionaryReal.removeSettingWithUndoCommit(query, dict, name);
                if (!IsNullOrEmpty(gName))
                {
                    SettingsDictionaryReal.removeSettingWithUndoCommit(query, gUser, gName);
                }
            }
            else
            {
                if (UseLuceneForSet && userbotLuceneIndexer != null)
                {
                    userbotLuceneIndexer.updateTriple(userName, name, value);
                }
                if (!String.IsNullOrEmpty(gName))
                {
                    SettingsDictionaryReal.addSettingWithUndoCommit(query, gUser.Predicates, gUser.addSetting, gName, value);
                }
                query.SetDictValue++;
                SettingsDictionaryReal.addSettingWithUndoCommit(query, dict, dict.addSetting, name, value);
            }
            var retVal = ReturnSetSetting(dict, name, setReturn);

            if (!IsIncomplete(retVal) || !IsNullOrEmpty(retVal))
            {
                string comment = null;
                //if (query.LastTagHandler!=null) comment = query.LastTagHandler.Succeed(" setting " + name);
                return(retVal);// +comment;
            }
            return(retVal);
        }
 public override string ToString()
 {
     if (docLineInfo == null)
     {
         return(StaticXMLUtils.TextAndSourceInfo(this));
     }
     return(docLineInfo.TextAndSourceInfo(this));
 }
Exemplo n.º 5
0
 public static string NoSpaceLowerCaseName(string path)
 {
     path = ToLower(Trim(StaticXMLUtils.ConsolidSpaces(path)));
     return(StaticXMLUtils.OlderReference(
                path,
                path
                .Replace(" ", "_").Replace(".", "_")
                .Replace("-", "_").Replace("__", "_")));
 }
Exemplo n.º 6
0
        /// <summary>
        /// This method searches for the search query, then deletes those with a score equal to the top ranked.
        /// </summary>
        /// <param name="query">The search term as a string that the caller wants to search for within the
        /// index as referenced by this object.</param>
        public int DeleteTopScoring(string searchQuery, XmlNode templateNode, bool mustContainExact)
        {
            // If must contain the exact words (the defualt is false)
            // bool mustContainExact = false;
            bool tf;

            if (StaticXMLUtils.TryParseBool(templateNode, "exact", out tf))
            {
                mustContainExact = tf;
            }
            return(DeleteTopScoring(searchQuery, mustContainExact));
        }
Exemplo n.º 7
0
        public virtual string ParseXmlResult(string res, string resFind)
        {
            int idxOf = res.IndexOf("?>");

            if (idxOf > 5)
            {
                if (idxOf < 50)
                {
                    string prefix = ""; // res.Substring(0, idxOf + 2);
                    res = res.Substring(idxOf + 2);
                    res = prefix + "<node>" + res + "</node>";
                }
            }
            var nodes = StaticXMLUtils.getNode(res);
            var body  = StaticXMLUtils.FindNode("body", nodes, null, 10);

            if (body != null)
            {
                nodes = body;
            }
            var text_result = StaticXMLUtils.FindNode(resFind, nodes, null, 10);

            if (text_result == null)
            {
                text_result = body;
            }
            if (text_result != null)
            {
                var    res2 = StaticXMLUtils.VisibleRendering(text_result.ChildNodes, PASS1);
                string s    = res2.Split(new string[] { "<div id=\"ga_mainDebug" }, StringSplitOptions.RemoveEmptyEntries)[0];
                // StaticXMLUtils.InnerXmlText(text_result);
                //if (s.Contains("<"))
                {
                    try
                    {
                        var s2 =
                            StaticXMLUtils.VisibleRendering(
                                StaticXMLUtils.getNode("<node>" + HttpUtil.GetWellFormedHTML("<node>" + s + "</node>", null) + "</node>").ChildNodes, PASS2);
                        if (!IsNullOrEmpty(s2))
                        {
                            s = s2;
                        }
                    }
                    catch
                    {
                    }
                }
                return(s);
            }
            TheBot.writeToLog(GetServiceName() + ": unused " + res);
            return(null);
        }
Exemplo n.º 8
0
        public static string MainSentence(string sentence)
        {
            string prev = "";

            while (sentence != prev)
            {
                prev     = sentence;
                sentence = StaticXMLUtils.Trim(sentence);
                int sl = sentence.Length - 1;

                if (sl < 0)
                {
                    return(sentence);
                }

                char c = sentence[sl];
                if (Char.IsPunctuation(c))
                {
                    sentence = sentence.Substring(0, sl);
                }
                sentence = sentence.TrimEnd();
            }
            int sf = sentence.LastIndexOfAny(new[] { '?' });

            if (sf > 0)
            {
                String newClip = sentence.Substring(0, sf - 1);
                // AltBot.writeDebugLine("AIMLTRACE !REWRITE THAT QUESTION " + sentence + " => " + newClip);
                if (newClip.Length > 4)
                {
                    sentence = newClip;
                }
            }
            sentence = TextPatternUtils.SymTrim(sentence, '?');
            sf       = sentence.LastIndexOfAny(new[] { '.', '!' });
            if (sf > 0)
            {
                String newClip = StaticXMLUtils.Trim(sentence.Substring(sf));
                while (Char.IsPunctuation(newClip[0]))
                {
                    newClip = newClip.Substring(1).TrimStart();
                }
                //   AltBot.writeDebugLine("AIMLTRACE !REWRITE THAT SENT " + sentence + " => " + newClip);
                if (newClip.Length > 4)
                {
                    sentence = newClip;
                }
            }
            return(sentence);
        }
        private bool SetNewValue(string value)
        {
            var  ir        = value;
            bool wasSetter = false;

            if (StaticXMLUtils.IsValueSetter(value))
            {
                ir        = StaticXMLUtils.ValueText(value);
                wasSetter = true;
            }
            if (!wasSetter)
            {
                writeToLog("ERROR not a setter");
            }
            if (ir.Length == 0)
            {
                if (LocalName != "think")
                {
                    writeToLog("ERROR: SetNewValue Not using " + value);
                    return(false);
                }
                outValueReplaced = "";
                return(true);
            }
            else
            {
                if (protect)
                {
                    if (value.Contains("<") || value.Contains("+-"))
                    {
                        writeToLog("ERROR: InnerXml Should not be changed to \"" + value + "\"");
                    }
                    else
                    {
                        writeToLog("WARNING: InnerXml Should not be changed to \"" + value + "\"");
                    }
                }
                if (wasSetter)
                {
                    outValueReplaced = ir;
                    //base.InnerXml = ir;
                }
                else
                {
                    writeToLog("WARNING: ERROR InnerXml Is not being changed to \"" + value + "\"");
                }
                return(true);
            }
        }
Exemplo n.º 10
0
 static public string MakeRuleStrings(IEnumerable <ConversationCondition> addRules)
 {
     {
         string s = "";
         if (addRules != null)
         {
             int c = 1;
             foreach (ConversationCondition rule in addRules)
             {
                 s += string.Format("<!-- Rule {0}: {1} -->\n", c, StaticXMLUtils.MakeXmlCommentSafe(rule.ToString()));
                 c++;
             }
         }
         return(s);
     }
 }
Exemplo n.º 11
0
 public TemplateInfoImpl(Unifiable pattern, XmlNode cateNode, XmlNode templateNode,
                         LoaderOptions options, Unifiable responseInfo,
                         Unifiable guard, Unifiable topicInfo, Node patternNode, Unifiable thatInfo)
     : base(pattern, cateNode, options)
 {
     if (templateNode == null || responseInfo.FullPath == Unifiable.Empty)
     {
         throw new NotImplementedException();
     }
     TemplateRating = 1.0;
     Guard          = guard;
     if ((thatInfo != null && !thatInfo.IsCatchAll) || (guard != null && !guard.IsCatchAll) ||
         (topicInfo != null && !topicInfo.IsCatchAll))
     {
         IsHighlyUsefull = true;
     }
     //CategoryXml = cateNode;
     That            = thatInfo;
     Response        = responseInfo;
     Topic           = topicInfo;
     Pattern         = pattern;
     GraphmasterNode = patternNode;
     srcNode         = templateNode;
     //ParentCategoryInfo = categoryInfo;
     try
     {
         {
             bool doCut;
             if (StaticXMLUtils.TryParseBool(templateNode, "cut", out doCut) || StaticXMLUtils.TryParseBool(cateNode, "cut", out doCut))
             {
                 NeckCut = doCut;
             }
         }
         string scoreString = StaticXMLUtils.GetAttribValue(templateNode, "score", null);
         scoreString    = scoreString ?? StaticXMLUtils.GetAttribValue(cateNode, "score", null);
         TemplateRating = scoreString != null?double.Parse(scoreString) : 1.0;
     }
     catch
     {
     }
     if (TemplateRating != 1.0)
     {
         AltBot.writeDebugLine("!! SCORE =" + TemplateRating + " for " + this);
     }
 }
Exemplo n.º 12
0
        public String queryTriple(string subject, string relation, XmlNode templateNode)
        {
            templateNode = templateNode ?? this.templateNodeInit;
            string factoidSR = GenFormatFactoid(subject, relation, "", templateNode);

            if (IsExcludedSRV(subject, relation, "", factoidSR, writeToLog, "queryTriple"))
            {
                return(String.Empty);
            }

            float threshold         = 0.5f;
            float minTerms          = 0.3f;
            bool  expandWithWordNet = true;
            bool  expandOnNoHits    = false;

            bool tf;

            if (StaticXMLUtils.TryParseBool(templateNode, "expand", out tf))
            {
                expandOnNoHits = tf;
            }
            if (StaticXMLUtils.TryParseBool(templateNode, "wordnet,synonyms", out tf))
            {
                expandWithWordNet = tf;
            }
            float  reliability;
            string result = EnglishFactiodStore.AskQuery(factoidSR, writeToLog, () => null, templateNode, threshold,
                                                         expandWithWordNet, expandOnNoHits, out reliability);

            if (!string.IsNullOrEmpty(result) && result.ToLower().StartsWith(factoidSR.ToLower()) &&
                reliability > threshold)
            {
                writeToLog("Success! queryTriple {0}, {1} => {2}", subject, relation, result);
                return(result.Substring(factoidSR.Length).Trim());
            }
            writeToLog("queryTriple {0}, {1} => '{2}' (returning String.Empty)", subject, relation, result);
            return(String.Empty);
        }
Exemplo n.º 13
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (IsPrecond)
            {
                sb.Append("precond");
            }
            else
            {
                sb.Append("condition");
            }
            if (TagName != null)
            {
                sb.Append("=\"" + TagName.ToUpper() + "\"");
            }
            if (IndexVal != null)
            {
                sb.Append(" pos=" + IndexVal);
            }
            if (IndexPosition)
            {
                sb.Append(" idx=" + IndexPosition);
            }
            if (Pattern != null)
            {
                sb.Append(" match=\"" + Pattern + "\" ");
            }
            var sSourceNode = SourceNode as XmlNode;

            if (sSourceNode != null)
            {
                sb.AppendLine(StaticXMLUtils.LocationInfo(sSourceNode) + sSourceNode.OuterXml);
            }
            return(sb.ToString());
        }
        private static bool ShouldSet(XmlNode templateNode, ISettingsDictionary dictionary, string name, object newValue, Unifiable oldValue, SubQuery query)
        {
            if (templateNode == null)
            {
                return(true);
            }
            bool canSet = query.UseDictionaryForSet(dictionary);

            ;
            bool onlyIfUnknown;

            if (StaticXMLUtils.TryParseBool(templateNode, "ifUnknown", out onlyIfUnknown))
            {
                if (onlyIfUnknown)
                {
                    return((Unifiable.IsMissing(oldValue) || IsIncomplete(oldValue)) && canSet);
                }
            }

            bool overwriteExisting;

            if (StaticXMLUtils.TryParseBool(templateNode, "overwriteExisting", out overwriteExisting))
            {
                if (!overwriteExisting)
                {
                    return((Unifiable.IsNullOrEmpty(oldValue) || IsIncomplete(oldValue)) && canSet);
                }
                //if (overwriteExisting)
                return(true);
            }

            string oldMatch  = StaticXMLUtils.GetAttribValue(templateNode, "existing", null);
            bool   shouldSet = true;

            if (oldMatch != null)
            {
                if (!StaticAIMLUtils.IsPredMatch(oldMatch, oldValue, null))
                {
                    shouldSet = false;
                }
            }
            var    newValueU = Unifiable.Create(newValue);
            string newMatch  = StaticXMLUtils.GetAttribValue(templateNode, "matches", null);

            if (newMatch != null)
            {
                if (!StaticAIMLUtils.IsPredMatch(newMatch, newValueU, null))
                {
                    shouldSet = false;
                }
            }
            string wontvalue = StaticXMLUtils.GetAttribValue(templateNode, "wontvalue", null);

            if (wontvalue != null)
            {
                if (StaticAIMLUtils.IsPredMatch(wontvalue, newValueU, null))
                {
                    shouldSet = false;
                }
            }
            return(shouldSet && canSet);
        }
        static public Unifiable GetSettingForType(string subject, SubQuery query, ISettingsDictionary dict, string name, out string realName, string gName, Unifiable defaultVal, out bool succeed, XmlNode node)
        {
            Request             request    = query.Request;
            OutputDelegate      writeToLog = request.writeToLog ?? TextPatternUtils.DEVNULL;
            AltBot              TargetBot  = request.TargetBot;
            ISettingsDictionary udict;
            string              dictName = AIMLTagHandler.GetNameOfDict(query, subject ?? dict.NameSpace, node, out udict);
            // try to use a global blackboard predicate
            User gUser = TargetBot.ExemplarUser;

            defaultVal = StaticXMLUtils.GetAttribValue(node, "default,defaultValue", defaultVal);
            gName      = StaticXMLUtils.GetAttribValue(node, "global_name", gName);

            string realName0;


            var vv = ScriptManager.GetGroup(query.TargetBot.ObjectRequester, dictName, name);
            {
                if (vv != null)
                {
                    if (vv.Count == 0)
                    {
                        succeed  = true;
                        realName = name;
                        return("");
                    }
                    succeed  = true;
                    realName = name;
                    foreach (var e in vv)
                    {
                        return(Unifiable.Create(e));
                    }
                }
            }
            Unifiable resultGet = SettingsDictionaryReal.grabSettingDefaultDict(udict, name, out realName0);

            if (ReferenceEquals(resultGet, null))
            {
                realName  = null;
                resultGet = Unifiable.NULL;
            }
            // if ((!String.IsNullOrEmpty(result)) && (!result.IsWildCard())) return result; // we have a local one

            String realNameG;
            // try to use a global blackboard predicate
            Unifiable gResult = SettingsDictionaryReal.grabSettingDefaultDict(gUser.Predicates, gName, out realNameG);

            if ((Unifiable.IsMissing(resultGet)) && (!Unifiable.IsMissing(gResult)))
            {
                // result=nothing, gResult=something => return gResult
                writeToLog("SETTINGS OVERRIDE " + gResult);
                succeed  = true;
                realName = realNameG;
                // return gResult;
            }
            string sresultGet = resultGet.ToValue(query);

            // if Unknown or empty
            if (UseLuceneForGet && Unifiable.IsMissing(sresultGet))
            {
                Unifiable userName = udict.grabSetting("id");
                if (Unifiable.IsNullOrEmpty(userName))
                {
                    writeToLog("ERROR IsNullOrEmpty id in " + udict.NameSpace);
                }
                ITripleStore userbotLuceneIndexer = (ITripleStore)query.Request.TargetBot.TripleStore;
                string       resultLucene         = userbotLuceneIndexer.queryTriple(userName, name, node);
                if (!string.IsNullOrEmpty(resultLucene))
                {
                    succeed  = true;
                    realName = name;
                    return(resultLucene);
                }
            }


            if (sresultGet != null)
            {
                if (sresultGet.ToUpper() == "UNKNOWN")
                {
                    succeed  = false;
                    realName = null;
                    return(sresultGet + " " + name);
                }
                else if (Unifiable.IsEMPTY(resultGet))
                {
                    succeed  = true;
                    realName = name;
                    return(resultGet);
                }
                else if (Unifiable.IsUnknown(resultGet))
                {
                    succeed  = false;
                    realName = name;
                    return(resultGet);
                }
            }
            if (!String.IsNullOrEmpty(sresultGet))
            {
                succeed  = true;
                realName = realName0;
                query.GetDictValue++;
                if (!IsNullOrEmpty(gResult))
                {
                    if (resultGet.IsWildCard)
                    {
                        realName = realNameG;
                        // result=*, gResult=something => return gResult
                        return(gResult);
                    }
                    // result=something, gResult=something => return result
                    return(resultGet);
                }
                else
                {
                    // result=something, gResult=nothing => return result
                    return(resultGet);
                }
            }
            if (defaultVal == null)
            {
                succeed  = false;
                realName = null;
                return(defaultVal);
            }
            // default => return defaultVal
            succeed  = true;
            realName = realName0;
            return(ReturnSetSetting(udict, name, defaultVal));
            //return defaultVal;
        }
Exemplo n.º 16
0
 public static T GetAttribValue_S <T>(XmlNode templateNode, string attribName, T defaultIfEmpty) where T : IConvertible
 {
     return(StaticXMLUtils.GetAttribValue(templateNode, attribName, () => (defaultIfEmpty), null));
 }
Exemplo n.º 17
0
        internal AIMLTagHandler GetTagHandlerU(User user, SubQuery query, Request request, Result result, XmlNode node, bool liText)
        {
            AIMLTagHandler tagHandlerU   = getBespokeTags(user, query, request, result, node);
            string         nodeNameLower = StaticAIMLUtils.ToLower(node.LocalName);
            AltBot         targetBot     = query.TargetBot;

            if (Equals(null, tagHandlerU))
            {
                switch (nodeNameLower)
                {
                case "template":
                case "answer":     //CML
                    tagHandlerU = new template(targetBot, user, query, request, result, node);
                    break;

                case "aiml":
                case "cml":     //CML
                    tagHandlerU = new aiml(targetBot, user, query, request, result, node);
                    break;

                case "aimlexec":
                case "eval":
                    tagHandlerU = new aimlexec(targetBot, user, query, request, result, node);
                    break;

                case "vars":
                case "root":
                case "predicates":     //CML
                    tagHandlerU = new root(targetBot, user, query, request, result, node, (() => query.TargetSettings));
                    break;

                case "properties":
                case "bots":
                    tagHandlerU = new root(targetBot, user, query, request, result, node,
                                           (() => request.TargetBot.GlobalSettings));
                    break;

                case "substitutions":
                    tagHandlerU = new root(targetBot, user, query, request, result, node,
                                           (() => request.TargetBot.InputSubstitutions));
                    break;

                case "topic":
                case "conversation":     //CML
                    tagHandlerU = new topic(targetBot, user, query, request, result, node);
                    break;

                case "category":
                case "conv":     //CML
                    tagHandlerU = new category(targetBot, user, query, request, result, node);
                    break;

                case "and":
                    tagHandlerU = new and(targetBot, user, query, request, result, node);
                    break;

                case "or":
                    tagHandlerU = new or(targetBot, user, query, request, result, node);
                    break;

                case "optional":
                    tagHandlerU = new optional(targetBot, user, query, request, result, node);
                    break;

                case "isa":
                    tagHandlerU = new isa(targetBot, user, query, request, result, node);
                    break;

                case "bot":
                    tagHandlerU = new bot(targetBot, user, query, request, result, node);
                    break;

                case "condition":
                case "options":     //cml
                    tagHandlerU = new condition_aima(targetBot, user, query, request, result, node);
                    break;

                case "li":
                    if (liText)
                    {
                        tagHandlerU = new liif(targetBot, user, query, request, result, node);
                    }
                    break;

                case "if":
                    tagHandlerU = new liif(targetBot, user, query, request, result, node);
                    break;

                case "personf":
                    tagHandlerU = new format(targetBot, user, query, request, result, node,
                                             new Func <string, string>(HttpUtility.UrlEncode),
                                             null);
                    break;

                case "date":
                    tagHandlerU = new date(targetBot, user, query, request, result, node);
                    break;

                case "formal":
                    tagHandlerU = new formal(targetBot, user, query, request, result, node);
                    break;

                case "gender":
                    tagHandlerU = new gender(targetBot, user, query, request, result, node);
                    break;

                case "get":
                    tagHandlerU = new get(targetBot, user, query, request, result, node);
                    break;

                case "gossip":
                    tagHandlerU = new gossip(targetBot, user, query, request, result, node);
                    break;

                case "get_ip":
                case "id":
                    tagHandlerU = new id(targetBot, user, query, request, result, node);
                    break;

                case "inputreq":
                    tagHandlerU = new inputreq(targetBot, user, query, request, result, node);
                    break;

                case "request":
                    tagHandlerU = new input(targetBot, user, query, request, result, node, 1);
                    break;

                case "input":
                    tagHandlerU = new input(targetBot, user, query, request, result, node, 1);
                    break;

                case "justthat":     // <input index="2"/>
                    tagHandlerU = new input(targetBot, user, query, request, result, node, 2);
                    break;

                case "beforethat":     // <input index="3"/>
                    tagHandlerU = new input(targetBot, user, query, request, result, node, 3);
                    break;

#if !(__MonoCS__)
                case "javascript":
                    tagHandlerU = new javascript(targetBot, user, query, request, result, node);
                    break;
#endif
                case "learn":
                case "load":
                case "noload":     // the commented version of <load>
                    tagHandlerU = new learn(targetBot, user, query, request, result, node);
                    break;

                case "lowercase":
                    tagHandlerU = new lowercase(targetBot, user, query, request, result, node);
                    break;

                case "person":
                    tagHandlerU = new substitute(targetBot, user, query, request, result, node);
                    break;

                case "person2":
                    tagHandlerU = new substitute(targetBot, user, query, request, result, node);
                    break;

                case "random":
                    tagHandlerU = new random(targetBot, user, query, request, result, node);
                    break;

                case "sentence":
                    tagHandlerU = new sentence(targetBot, user, query, request, result, node);
                    break;

                case "set":
                    tagHandlerU = new set(targetBot, user, query, request, result, node);
                    break;

                case "size":
                case "getsize":
                    tagHandlerU = new size(targetBot, user, query, request, result, node);
                    break;

                case "sr":
                    tagHandlerU = new sr(targetBot, user, query, request, result, node);
                    break;

                case "srai_odd":
                    tagHandlerU = new srai_odd(targetBot, user, query, request, result, node);
                    break;

                case "star":
                    tagHandlerU = new star(targetBot, user, query, request, result, node);
                    break;

                case "system":
                    tagHandlerU = new system(targetBot, user, query, request, result, node);
                    break;

                case "that":     //default <that index="1,1"/>
                    tagHandlerU = new that(targetBot, user, query, request, result, node, 1);
                    break;

                case "justbeforethat":     //treated as <that index="2,1"/>
                    tagHandlerU = new that(targetBot, user, query, request, result, node, 2);
                    break;

                case "response":     //treated as <that index="1,1"/>
                    tagHandlerU = new that(targetBot, user, query, request, result, node, 2);
                    break;

                case "thatstar":
                    tagHandlerU = new thatstar(targetBot, user, query, request, result, node);
                    break;

                case "think":
                    tagHandlerU = new think(targetBot, user, query, request, result, node);
                    break;

                case "topicstar":
                    tagHandlerU = new topicstar(targetBot, user, query, request, result, node);
                    break;

                case "uppercase":
                    tagHandlerU = new uppercase(targetBot, user, query, request, result, node);
                    break;

                case "version":
                case "getversion":
                    tagHandlerU = new version(targetBot, user, query, request, result, node);
                    break;

                case "cycsystem":
                    tagHandlerU = new cycsystem(targetBot, user, query, request, result, node);
                    break;

                case "cycretract":
                    tagHandlerU = new cycretract(targetBot, user, query, request, result, node);
                    break;

                case "cycassert":
                    tagHandlerU = new cycassert(targetBot, user, query, request, result, node);
                    break;

                case "cycterm":
                    tagHandlerU = new cycterm(targetBot, user, query, request, result, node);
                    break;

                case "cycquery":
                    tagHandlerU = new cycquery(targetBot, user, query, request, result, node);
                    break;

                case "cyccondition":
                    tagHandlerU = new cyccondition(targetBot, user, query, request, result, node);
                    break;

                case "cycphrase":
                    tagHandlerU = new cycphrase(targetBot, user, query, request, result, node);
                    break;

                case "cycparaphrase":
                    tagHandlerU = new cycphrase(targetBot, user, query, request, result, node);
                    break;

                case "guard":
                    tagHandlerU = new guard(targetBot, user, query, request, result, node);
                    break;

                case "guardstar":
                    tagHandlerU = new guardstar(targetBot, user, query, request, result, node);
                    break;

                case "cycrandom":
                    tagHandlerU = new cycrandom(targetBot, user, query, request, result, node);
                    break;

                case "tscore":
                    tagHandlerU = new tscore(targetBot, user, query, request, result, node);
                    break;

                case "space":
                    tagHandlerU = new space(targetBot, user, query, request, result, node);
                    break;

                case "markov":
                    tagHandlerU = new markov(targetBot, user, query, request, result, node);
                    break;

                case "soundcode":
                    tagHandlerU = new soundcode(targetBot, user, query, request, result, node);
                    break;

                // MSM
                case "msm":
                    tagHandlerU = new msm(targetBot, user, query, request, result, node);
                    break;

                case "processmsm":
                    tagHandlerU = new process_msm(targetBot, user, query, request, result, node);
                    break;

                case "setstate":
                    tagHandlerU = new setstate(targetBot, user, query, request, result, node);
                    break;

                case "state":
                    tagHandlerU = new state(targetBot, user, query, request, result, node);
                    break;

                case "transition":
                    tagHandlerU = new transition(targetBot, user, query, request, result, node);
                    break;

                case "setevidence":
                    tagHandlerU = new setevidence(targetBot, user, query, request, result, node);
                    break;

                case "evidenceassoc":
                    tagHandlerU = new evidence_assoc(targetBot, user, query, request, result, node);
                    break;

                case "evidencepattern":
                    tagHandlerU = new evidence_pattern(targetBot, user, query, request, result, node);
                    break;

                case "evidencestate":
                    tagHandlerU = new evidencestate(targetBot, user, query, request, result, node);
                    break;

                case "dependentmachine":
                    tagHandlerU = new dependentmachine(targetBot, user, query, request, result, node);
                    break;

                case "responsetopic":
                    tagHandlerU = new response_topic(targetBot, user, query, request, result, node);
                    break;

                case "push":
                    tagHandlerU = new push(targetBot, user, query, request, result, node);
                    break;

                case "pop":
                    tagHandlerU = new pop(targetBot, user, query, request, result, node);
                    break;

                case "peekstack":
                    tagHandlerU = new peekstack(targetBot, user, query, request, result, node);
                    break;

                case "lex":
                    tagHandlerU = new lex(targetBot, user, query, request, result, node);
                    break;

                case "lexset":
                    tagHandlerU = new lexset(targetBot, user, query, request, result, node);
                    break;

                case "lexis":
                    tagHandlerU = new lexis(targetBot, user, query, request, result, node);
                    break;

                case "dbpush":
                    tagHandlerU = new dbpush(targetBot, user, query, request, result, node);
                    break;

                case "dbquery":
                    tagHandlerU = new dbquery(targetBot, user, query, request, result, node);
                    break;

                case "dbupdate":
                    tagHandlerU = new dbupdate(targetBot, user, query, request, result, node);
                    break;

                case "dbdelete":
                    tagHandlerU = new dbdelete(targetBot, user, query, request, result, node);
                    break;

                case "dbload":
                    tagHandlerU = new dbload(targetBot, user, query, request, result, node);
                    break;


                case "regex":
                    tagHandlerU = new regex(targetBot, user, query, request, result, node);
                    break;

                case "bind":     // <bind>#$isa</bind>
                    tagHandlerU = new bind(targetBot, user, query, request, result, node);
                    break;

                case "#text":
                    if (!liText)
                    {
                        return(null);
                    }
                    return(new verbatum(node.Value, targetBot, user, query, request, result, node));

                case "#comment":
                    return(new verbatum(node.OuterXml, targetBot, user, query, request, result, node));

                case "br":
                    return(new verbatum("\n", targetBot, user, query, request, result, node));

                case "pre":
                    return(new verbatum(StaticXMLUtils.InnerXmlText(node), targetBot, user, query, request, result, node));

                case "p":
                    return(new verbatum("\n\n", targetBot, user, query, request, result, node));

                case "meta":
                    return(new verbatum(node.OuterXml, targetBot, user, query, request, result, node));

                default:
                    break;
                }
            }
            if (tagHandlerU != null)
            {
                return(tagHandlerU);
            }
            if (StaticAIMLUtils.IsHtmlTag(node.Name))
            {
                return(new recursiveVerbatum(node, targetBot, user, query, request, result, node, true));
            }
            if (tagHandlerU == null)
            {
                // "bot", "favorite", "fav"
                foreach (KeyValuePair <string, string> prefix in new[]
                {
                    new KeyValuePair <string, string>("get_", "get"),
                    new KeyValuePair <string, string>("set_", "set"),
                    new KeyValuePair <string, string>("bot_", "bot"),
                    new KeyValuePair <string, string>("favorite_", "bot"),
                    new KeyValuePair <string, string>("favorite", "bot"),
                    new KeyValuePair <string, string>("fav_", "bot"),
                    new KeyValuePair <string, string>("fav", "bot"),

                    new KeyValuePair <string, string>("get", "get"),
                    new KeyValuePair <string, string>("set", "set"),
                    new KeyValuePair <string, string>("bot", "bot"),
                })
                {
                    if (nodeNameLower.StartsWith(prefix.Key) && node.Name.Length > prefix.Key.Length)
                    {
                        string               name    = node.Name.Substring(prefix.Key.Length);
                        XmlNode              pn      = node.ParentNode;
                        LineInfoElementImpl  newnode = StaticXMLUtils.CopyNode(prefix.Value, node, false);
                        XmlAttributeLineInfo atr     = (XmlAttributeLineInfo)newnode.OwnerDocument.CreateAttribute("name");
                        atr.ReadOnly = false;
                        atr.Value    = name;
                        newnode.Attributes.Append(atr);
                        if (node.Name.ToLower() != newnode.Name.ToLower())
                        {
                            writeToLog("AIMLLOADER: converted " + node.OuterXml + " -> " + newnode.OuterXml);
                            return(targetBot.GetTagHandler(newnode, query, request, result, user, liText));
                        }
                        writeToLog("AIMLLOADER: ! convert " + node.OuterXml + " -> " + newnode.OuterXml);
                    }
                }
            }
            if (tagHandlerU != null)
            {
                return(tagHandlerU);
            }
            if (nodeNameLower == "name")
            {
                return(new bot(targetBot, user, query, request, result, node));
            }

            tagHandlerU = new lazyClosure(targetBot, user, query, request, result, node);
            writeToLog("AIMLLOADER:  lazyClosure: " + node.OuterXml);
            return(tagHandlerU);
        }
Exemplo n.º 18
0
        public AIMLTagHandler proccessResponse000(SubQuery query, Request request, Result result,
                                                  XmlNode sOutput, Unifiable sGuard,
                                                  out bool createdOutput, out bool templateSucceeded,
                                                  AIMLTagHandler parentHandlerU, TemplateInfo templateInfo,
                                                  bool copyChild, bool copyParent)
        {
            AltBot Proc = query.TargetBot;

            //query.LastTagHandler = handler;
            bool isTraced = request.IsTraced || request.IsTraced || !request.GraphsAcceptingUserInput ||
                            (templateInfo != null && templateInfo.IsTraced);
            //XmlNode guardNode = AIMLTagHandler.getNode(s.Guard.InnerXml);
            bool usedGuard = sGuard != null && sGuard.PatternNode != null;

            sOutput = sOutput ?? templateInfo.ClonedOutput;
            string  output        = sOutput.OuterXml;
            XmlNode templateNode  = sOutput;
            bool    childOriginal = true;

            result.Started = true;
            if (usedGuard)
            {
                output = "<template>" + sGuard.PatternNode.OuterXml + " GUARDBOM " + output +
                         "</template>";
                templateNode = StaticAIMLUtils.getNodeAndSetSibling(false, output, false, false, sOutput);

                childOriginal = false;
            }

            bool           protectChild     = copyChild || childOriginal;
            bool           suspendingLimits = request.IsToplevelRequest || request.SuspendSearchLimits;
            AIMLTagHandler tagHandlerU      = GetTagHandler(request.Requester, query, request, result,
                                                            templateNode, parentHandlerU);
            string outputSentenceOut = processNode(templateNode, query,
                                                   request, result, request.Requester, parentHandlerU,
                                                   protectChild, copyParent, tagHandlerU, suspendingLimits, out templateSucceeded);

            templateSucceeded = !StaticAIMLUtils.IsFalse(outputSentenceOut);

            if (outputSentenceOut == null)
            {
                if (tagHandlerU == null)
                {
                    writeToLog("tagHandler = null " + output);
                }
                else
                {
                    bool success = false;
                    if (tagHandlerU.QueryHasSuceeded)
                    {
                        success = true;
                    }
                    if (tagHandlerU.QueryHasFailed)
                    {
                        success = false;
                    }
                    if (success)
                    {
                        writeToLog("Very BaD " + output);
                    }
                    else
                    {
                    }
                    templateSucceeded = false;
                    createdOutput     = false;
                    return(tagHandlerU);
                }
            }
            outputSentenceOut = outputSentenceOut ?? "";
            string left, outputSentence;

            if (!StaticAIMLUtils.SplitOff(outputSentenceOut, "GUARDBOM", out left, out outputSentence))
            {
                left           = null;
                outputSentence = outputSentenceOut;
            }
            if (sGuard == null || sGuard.PatternNode != null)
            {
                string o = Proc.ToEnglish(outputSentence);
                if (outputSentence.Trim().Length > 0)
                {
                    templateSucceeded = true;
                }
                if (Proc.IsOutputSentence(o, outputSentence))
                {
                    if (isTraced)
                    {
                        string aIMLLoaderParentTextAndSourceInfo = ParentTextAndSourceInfo(templateNode);
                        if (aIMLLoaderParentTextAndSourceInfo.Length > 300)
                        {
                            aIMLLoaderParentTextAndSourceInfo = TextFilter.ClipString(
                                aIMLLoaderParentTextAndSourceInfo, 300);
                        }
                        writeToLog("AIMLTRACE '{0}' IsOutputSentence={1}", o, aIMLLoaderParentTextAndSourceInfo);
                    }
                    createdOutput = true;
                    request.AddOutputSentences(templateInfo, o, result, request.TopLevelScore);
                }
                else
                {
                    createdOutput = false;
                }
                // @TODO @HACK @BUG isTraced is a HORRID flag here!
                if (false && !createdOutput && isTraced && request.GraphsAcceptingUserInput)
                {
                    if (templateInfo != null)
                    {
                        string fromStr = " from " + templateInfo.Graph;
                        if (!StaticAIMLUtils.IsSilentTag(templateNode))
                        {
                            writeToLog("SILENT '{0}' TEMPLATE={1}", o, ParentTextAndSourceInfo(templateNode) + fromStr);
                        }
                        request.DisableTemplateUntilFinished(templateInfo);
                    }
                    else
                    {
                        writeToLog("UNUSED '{0}' TEMPLATE={1}", o, ParentTextAndSourceInfo(templateNode));
                    }
                }

                return(tagHandlerU);
            }
            try
            {
                templateSucceeded = !StaticAIMLUtils.IsFalse(left);
                if (!templateSucceeded)
                {
                    createdOutput = false;
                    return(tagHandlerU);
                }
                string lang = StaticXMLUtils.GetAttribValue(sGuard.PatternNode, "lang", "cycl").ToLower();

                try
                {
                    Unifiable ss = Proc.SystemExecute(left, lang, request);
                    if (StaticAIMLUtils.IsFalse(ss) || StaticAIMLUtils.IsNullOrEmpty(ss))
                    {
                        if (isTraced)
                        {
                            writeToLog("GUARD FALSE '{0}' TEMPLATE={1}", request,
                                       ParentTextAndSourceInfo(templateNode));
                        }
                        templateSucceeded = false;
                        createdOutput     = false;
                        return(tagHandlerU);
                    }
                    else
                    {
                        templateSucceeded = true;
                    }
                }
                catch (ChatSignal e)
                {
                    throw;
                }
                catch (Exception e)
                {
                    Proc.writeToLog(e);
                    templateSucceeded = false;
                    createdOutput     = false;
                    return(tagHandlerU);
                }

                //part the BOM
                string o = Proc.ToEnglish(outputSentence);
                if (Proc.IsOutputSentence(o, outputSentence))
                {
                    if (isTraced)
                    {
                        writeToLog(query.Graph + ": GUARD SUCCESS '{0}' TEMPLATE={1}", o,
                                   ParentTextAndSourceInfo(templateNode));
                    }
                    templateSucceeded = true;
                    createdOutput     = true;
                    request.AddOutputSentences(templateInfo, o, result, request.TopLevelScore);
                    return(tagHandlerU);
                }
                else
                {
                    writeToLog("GUARD SKIP '{0}' TEMPLATE={1}", outputSentence,
                               ParentTextAndSourceInfo(templateNode));
                }
                templateSucceeded = false;
                createdOutput     = false;
                return(tagHandlerU);
            }
            catch (ChatSignal e)
            {
                throw;
            }
            catch (Exception ex)
            {
                Proc.writeToLog(ex);
                templateSucceeded = false;
                createdOutput     = false;
                return(tagHandlerU);
            }
        }
Exemplo n.º 19
0
        virtual public string ToFileString(PrintOptions printOptions)
        {
            //if (XmlDocumentLineInfo.SkipXmlns && this.srcNode.Attributes != null) this.srcNode.Attributes.RemoveNamedItem("xmlns");
            string s = "";

            if (IsDisabled)
            {
                if (!printOptions.WriteDisabledItems)
                {
                    return(s);
                }
            }
            string graphName = ((IAIMLInfo)this).Graph.ScriptingName;

            if (printOptions.IncludeGraphName)
            {
                if (graphName != printOptions.CurrentGraphName)
                {
                    if (printOptions.InsideAiml)
                    {
                        s += "\n</aiml>\n";
                        s += string.Format("\n<aiml graph=\"{0}\">\n", graphName);
                        printOptions.CurrentGraphName = graphName;
                    }
                    else
                    {
                        printOptions.InsideAiml = true;
                        s += string.Format("\n<aiml graph=\"{0}\">\n", graphName);
                        printOptions.CurrentGraphName = graphName;
                    }
                }
            }

            s += GetSourceWithTopic(printOptions);

            string escapedStuff = "";

            //if (!printOptions.IncludeLineInfoExternal)
            {
                if (!printOptions.GroupFileElements)
                {
                    if (printOptions.IncludeFileNamePerNode)
                    {
                        string cfile = Filename ?? StaticXMLUtils.FileNameOfXmlNode(srcNode);
                        if (cfile != printOptions.InsideFilename)
                        {
                            escapedStuff += cfile;
                            printOptions.InsideFilename = cfile;
                        }
                    }
                }
                if (printOptions.IncludeLinenoPerNode)
                {
                    escapedStuff += ":" + LineNumberInfo;
                }
            }

            escapedStuff = StaticXMLUtils.MakeXmlCommentSafe(escapedStuff);
            if (IsDisabled)
            {
                s = DLRConsole.SafeFormat("<!-- {0} {1} {2} -->", StaticAIMLUtils.MakeXmlCommentSafe(WhyDisabled), StaticAIMLUtils.MakeXmlCommentSafe(s), escapedStuff);
            }
            else
            {
                s = DLRConsole.SafeFormat("{0} <!-- {1}  -->", s, escapedStuff);
            }
            return(s);
        }
Exemplo n.º 20
0
        public string callDbQueryStatic(ICollection <IDocSearch> searchables, string searchTerm1, OutputDelegate dbgLog,
                                        XmlNode templateNode, float threshold,
                                        out float reliablity, string userFilter, WordExpander wordNetExpander)
        {
            reliablity = 0.0f;
            try
            {
                // if dbgLog == null then use /dev/null logger
                dbgLog = dbgLog ?? TextFilter.DEVNULL;
                // Searching:

                int numHits;

                string maxReplyStr = StaticXMLUtils.GetAttribValue(templateNode, "max", "1").ToLower();
                int    maxReply    = Int16.Parse(maxReplyStr);

                string thresholdStr = StaticXMLUtils.GetAttribValue(templateNode, "threshold", null);
                if (!string.IsNullOrEmpty(thresholdStr))
                {
                    float parsed;
                    if (float.TryParse(thresholdStr, out parsed))
                    {
                        threshold = parsed;
                    }
                }

                // Do we only want responses with the current user name in it ?
                // As in "what is my favorite color?"
                var results = new List <ISearchResult>();
                dbgLog("Searching for the term \"{0}\"...", searchTerm1);
                foreach (var ss in searchables)
                {
                    results.AddRange(Search(searchTerm1, wordNetExpander));
                }

                numHits = results.Count;
                dbgLog("Number of hits == {0}.", numHits);

                float topScore = 0;
                int   goodHits = 0;
                for (int i = 0; i < numHits; ++i)
                {
                    dbgLog("{0}) Doc-id: {1}; Content: \"{2}\" with score {3}.", i + 1, results[i].ID, results[i].Text, results[i].Score);
                    if (results[i].Text.Contains(userFilter))
                    {
                        if (results[i].Score >= threshold)
                        {
                            goodHits++;
                        }
                        if (results[i].Score > topScore)
                        {
                            topScore = results[i].Score;
                        }
                    }
                }

                //if (numHits > 0) topScore = scores[0];
                // Console.WriteLine();



                if ((goodHits > 0) && (topScore >= threshold))
                {
                    // should be weighted but lets just use the highest scoring
                    string reply       = "";
                    int    numReturned = 0;
                    if (goodHits < maxReply)
                    {
                        maxReply = goodHits;
                    }
                    for (int i = 0; ((i < numHits) && (numReturned < maxReply)); i++)
                    {
                        if (results[i].Text.Contains(userFilter) && (results[i].Score >= topScore))
                        {
                            reply = reply + " " + results[i].Text;
                            numReturned++;
                            reliablity = topScore;
                        }
                    }
                    Unifiable converseMemo = reply.Trim();
                    dbgLog(" reply = {0}", reply);
                    return(converseMemo);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(Unifiable.Empty);
            }
        }
        /***
         *
         * This document already has a 'DocumentElement' node.
         * at System.Xml.XmlDocument.IsValidChildType(XmlNodeType type)
         * at System.Xml.XmlDocument.AppendChildForLoad(XmlNode newChild, XmlDocument doc)
         * at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
         * at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
         * at System.Xml.XmlDocument.Load(XmlReader reader)
         *
         */

        public string TextAndSourceInfo(XmlNode node)
        {
            string s = StaticXMLUtils.TextInfo(node);

            return(s + " " + StaticXMLUtils.LocationEscapedInfo(node));
        }
Exemplo n.º 22
0
        public static bool ContainsAiml(Unifiable unifiable)
        {
            String s = unifiable.AsString();

            return(StaticXMLUtils.ContainsXml(s));
        }
Exemplo n.º 23
0
 public T GetAttribValue <T>(string attribName, Func <T> defaultIfEmpty) where T : IConvertible
 {
     return(StaticXMLUtils.GetAttribValue(templateNode, attribName, defaultIfEmpty, null));
 }
Exemplo n.º 24
0
 public override string ToString()
 {
     return(CategoryXml.OuterXml + " " + StaticXMLUtils.LocationEscapedInfo(CategoryXml));
 }
Exemplo n.º 25
0
 public string SourceInfo()
 {
     return(Filename + ":" + StaticXMLUtils.GetLineNumberOfXmlNode(this));
 }
Exemplo n.º 26
0
 public static string ParentTextAndSourceInfo(XmlNode node)
 {
     return(StaticXMLUtils.ParentTextAndSourceInfo(node));
 }
Exemplo n.º 27
0
        private XmlNode RunTest(Request request, XmlNode src, OutputDelegate outputdelegate, out bool m)
        {
            // request = request ?? Loader.LoaderRequest00;
            User   user  = request.Requester;
            AltBot robot = request.TargetBot ?? Loader.TargetBot;

            string tcname = StaticXMLUtils.FindNodeOrAttrib(src, "name", null);
            string tcdesc = FindNodeOrAttrib(src, "Description", null);
            string input  = FindNodeOrAttrib(src, "Input", null);

            if (input == null)
            {
                outputdelegate("ERROR cannot find 'Input' in '" + src.OuterXml + "'");
                m = false;
                return(getNodeAndSetSibling(false,
                                            "<template type=\"error\">ERROR cannot find 'Input' in '" + src.OuterXml + "'</template>", true,
                                            false, src));
            }
            string userID = FindNodeOrAttrib(src, "UserId,UserName", () => user.UserID);

            const string MISSING_EXPECTED_ANSWER = "ExpectedKeywords";
            var          matchTheseToPass        = new List <string>();
            string       expectedAnswer          = FindNodeOrAttrib(src, "ExpectedAnswer", () => MISSING_EXPECTED_ANSWER);

            expectedAnswer = Fudge(expectedAnswer);
            if (expectedAnswer == MISSING_EXPECTED_ANSWER)
            {
                var nodes = FindNodes("ExpectedKeywords", src);
                if (nodes == null || nodes.Count == 0)
                {
                    outputdelegate("ERROR cannot find 'ExpectedAnswer' in '" + src.OuterXml + "'");
                }
                else
                {
                    foreach (XmlNode list in nodes)
                    {
                        string v = Unifiable.InnerXmlText(list);

                        matchTheseToPass.Add(".*" + Fudge(v) + ".*");
                    }
                }
            }
            else
            {
                matchTheseToPass.Add("^" + Fudge(expectedAnswer) + "$");
            }

            outputdelegate("{0}: {1} ", tcname, tcdesc);
            outputdelegate("{0}: {1} ", userID, input);
            string resp = "ERROR";

            try
            {
                var requestToBot = robot.MakeRequestToBot(input, userID, true, RequestKind.ChatRealTime);
                requestToBot.IsTraced = traceIt;
                if (traceIt)
                {
                    AltBot.Breakpoint("testing...");
                    requestToBot.DebugLevel = 9;
                }
                Result result = robot.Chat(requestToBot);
                resp = result.Output ?? result.ToString() ?? resp;
                if (resp == null)
                {
                    resp = "NULLED";
                }
                resp = Fudge(resp);
                outputdelegate("{0}: {1} ", robot, resp);
                m = true;
                int good = 0;
                foreach (string s in matchTheseToPass)
                {
                    if (!Matches(resp, s, FindNodeOrAttrib(src, "MatchType,Match", null)))
                    {
                        m = false;
                    }
                    else
                    {
                        good++;
                    }
                }
                outputdelegate("PASSED={0}", m);
                if (traceIt)
                {
                    AltBot.Breakpoint("tested...");
                }
                return(GetMessage(src, "PASSED='" + m +
                                  "'", "TESTCASE='" + tcname + "' GOOD='" + good +
                                  "' RESPNS='" + resp +
                                  "' EXPECT='" + expectedAnswer +
                                  "' INPUT='" + input +
                                  "' DESC='" + tcdesc + "'"));
            }
            catch (Exception err)
            {
                string ERRMSG = "" + err;
                m = false;
                errorCount++;
                return(GetMessage(src, "PASSED='" + m +
                                  "'", "TESTCASE='" + tcname + "' ERRMSG='" + ERRMSG + "' RESP='" + resp +
                                  "' EXPECT='" + expectedAnswer +
                                  "' INPUT='" + input +
                                  "' DESC='" + tcdesc + "'"));
            }
        }
Exemplo n.º 28
0
 string IAIMLInfo.SourceInfo()
 {
     return(StaticXMLUtils.GetLineNumberOfXmlNode(this));
 }