Exemplo n.º 1
0
        public static string SubstituteRecurse(AltBot bot, SettingsDictionary dictionary, string target)
        {
            string result = Unifiable.ToVMString(target);
            String prev   = "";

            while (prev != result)
            {
                prev   = result;
                result = Substitute(dictionary, target);
            }
            return(Unifiable.MakeUnifiableFromString(result, false));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target Unifiable
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target Unifiable to which the substitutions are to be applied</param>
        /// <returns>The processed Unifiable</returns>
        public static string Substitute(ISettingsDictionary dictionary, string target)
        {
            if (dictionary == null)
            {
                return(target);
            }
            string marker   = ApplySubstitutions.getMarker(5);
            string markerSP = ApplySubstitutions.getMarker(3);
            string result   = " " + Unifiable.ToVMString(target) + " ";

            result = SubstituteResults(dictionary, marker, markerSP, result, false);
            return(result.Replace(marker, "").Replace(markerSP, " "));
        }
Exemplo n.º 3
0
 public ICollection <SubQuery> PreprocessSubQueries(Request request, ICollection <SubQuery> resultSubQueries, bool isTraced, ref bool printedSQs, OutputDelegate writeToLog)
 {
     // var usingResultSubQueries = new List<SubQuery>();
     //todo pick and chose the queries
     // if (result.SubQueries.Count != 1)
     if (isTraced)
     {
         string s = "AIMLTRACE: SubQueries.Count = " + resultSubQueries.Count;
         foreach (SubQuery path in resultSubQueries)
         {
             s += Environment.NewLine;
             s += "  " + Unifiable.ToVMString(path.FullPath);
         }
         printedSQs = true;
         writeToLog(s);
         DLRConsole.SystemFlush();
     }
     return(resultSubQueries);
 }
Exemplo n.º 4
0
 protected override Unifiable Format(Unifiable templateNodeInnerText)
 {
     if (CheckNode("formal"))
     {
         Unifiable result = Unifiable.CreateAppendable();
         Unifiable rest   = templateNodeInnerText;
         while (!IsNullOrEmpty(rest))
         {
             // Unifiable[] words = templateNodeInnerText.AsString().Split(new char[]{''});
             Unifiable word = rest.First;
             rest = rest.Rest;
             {
                 Unifiable newWord = word.ToPropper();
                 result.Append(newWord);
             }
         }
         return(Trim(Unifiable.ToVMString(result)));
     }
     return(Unifiable.Empty);
 }
Exemplo n.º 5
0
        //private static int depth = 0;
        public override Unifiable RecurseChildren()
        {
            try
            {
                ResetValues(true);
                isRecursive = true;
                Unifiable f = Recurse();
                //depth++;

                /* int d = request.GetCurrentDepth();
                 * if (d > 30)
                 * {
                 *   writeToLogWarn("WARNING Depth pretty deep " + f + " returning empty");
                 *   return Unifiable.Empty;
                 * }
                 * if (depth > 30)
                 * {
                 *   writeToLogWarn("WARNING Depth pretty deep " + f + " returning empty");
                 *   return Unifiable.Empty;
                 * }*/
                var tn = templateNode;
                foreach (var cn in tn.ChildNodes)
                {
                }
                string  s    = Unifiable.ToVMString(f);
                XmlNode node =
                    new XmlDocumentLineInfo(s, false).ReadNode(
                        XmlDocumentLineInfo.CreateXmlTextReader(new StringReader(s)));
                bool templateSucceeded;
                bool createdOutput;
                templateInfo        = GetTemplateInfo();
                request.LastHandler = Proc.TagHandling.proccessResponse(query, request, result, (XmlNode)node, templateInfo.Guard, out createdOutput,
                                                                        out templateSucceeded, this, templateInfo, ReadOnly, true);
                return(Unifiable.Empty);
            }
            finally
            {
                //   depth--;
            }
        }
Exemplo n.º 6
0
        protected override Unifiable ProcessChangeU()
        {
            return(templateNodeInnerText);

            if (false && templateNode.Name.ToLower() == "aimlexec")
            {
                Unifiable result = Unifiable.CreateAppendable();
                Unifiable rest   = templateNodeInnerText;
                while (!IsNullOrEmpty(rest))
                {
                    // Unifiable[] words = templateNodeInnerText.AsString().Split(new char[]{''});
                    Unifiable word = templateNodeInnerText.First;
                    rest = rest.Rest;
                    {
                        Unifiable newWord = word;
                        result.Append(newWord + " ");
                    }
                }
                return(Trim(Unifiable.ToVMString(result)));
            }
            return(templateNodeInnerText);
        }
Exemplo n.º 7
0
        //(mapcar #'(lambda (x) (pwhen (member col x) ))  (denotation-mapper "isa"))

        private bool lookupCycTerm(string template, string text, Unifiable filter, out Unifiable term)
        {
            string textStr = text.StartsWith("\"") ? text : ("\"" + text + "\"");

            if (!char.IsLetter(text[0]))
            {
            }
            template = template.Replace("\"%s\"", textStr);

            //template = template.Replace("#$%s-TheWord", textWord);
            template = template.Replace("%s", text);


            try
            {
                term = EvalSubL(TextPatternUtils.SafeFormat("(first (ask-template '?CYCOBJECT '(#$and {0} (#$isa ?CYCOBJECT {1})) #$EverythingPSC))", template, Unifiable.ToVMString(filter)), null);
            }
            catch (System.Exception ex)
            {
                term = null;
                return(false);
            }
            if (Unifiable.IsFalse(term))
            {
                return(false);
            }
            return(true);
        }