public override void Append(Unifiable p)
 {
     if (p != null)
     {
         Append(p.AsString());
     }
 }
        public override bool SameMeaningCS(Unifiable s, bool caseSensitive)
        {
            if (s is BestUnifiable)
            {
                return(s.SameMeaningCS(this, caseSensitive));
            }
            if (ReferenceEquals(this, s))
            {
                return(true);
            }
            bool null2 = ReferenceEquals(s, null);

            if (null2)
            {
                return(false);
            }
            if (caseSensitive)
            {
                if (str == s.AsString())
                {
                    return(true);
                }
                return(false);
            }
            if (ToUpper(str) == s.ToUpper())
            {
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        public override int CompareTo(Unifiable other)
        {
            double strictness      = Strictness;
            double otherStrictness = other.Strictness;

            if (strictness == otherStrictness)
            {
                return(AsString().CompareTo(other.AsString()));
            }
            return(strictness.CompareTo(otherStrictness));
        }
Esempio n. 4
0
        public static bool IsPredMatch(Unifiable required, Unifiable actualValue, SubQuery subquery)
        {
            if (IsNull(required))
            {
                return(IsNullOrEmpty(actualValue));
            }
            required = required.Trim();
            if (required.IsAnyText)
            {
                return(!IsNullOrEmpty(actualValue));
            }

            string requiredToUpper = required.ToUpper();

            if (requiredToUpper == "*")
            {
                return(!IsUnknown(actualValue));
            }

            if (requiredToUpper == "OM" || IsNullOrEmpty(required) || requiredToUpper == "$MISSING")
            {
                return(IsNullOrEmpty(actualValue) || actualValue == "OM");
            }
            if (IsIncomplete(required))
            {
                return(IsIncomplete(actualValue));
            }
            if (IsNull(actualValue))
            {
                return(IsNullOrEmpty(required));
            }
            actualValue = actualValue.Trim();
            if (actualValue.WillUnify(required, subquery))
            {
                return(true);
            }
            string requiredAsStringReplaceReplace = required.AsString().Replace(" ", "\\s")
                                                    .Replace("*", "[\\sA-Z0-9]+").Replace("_", "[A-Z0-9]+");
            Regex matcher = new Regex("^" + requiredAsStringReplaceReplace + "$",
                                      RegexOptions.IgnoreCase);

            if (matcher.IsMatch(actualValue))
            {
                return(true);
            }
            if (requiredToUpper == "UNKNOWN" && (IsUnknown(actualValue)))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
 public bool Lookup1(Unifiable textIn, Unifiable filter, out Unifiable term, SubQuery subquery)
 {
     if (Unifiable.IsNullOrEmpty(textIn))
     {
         term = null;
         return(false);
     }
     if (textIn.AsString().Contains("#$"))
     {
         term = textIn;
         if (!Unifiable.IsNullOrEmpty(term))
         {
             if (!IsaFilter(term, filter))
             {
                 return(false);
             }
         }
         return(true);
     }
     lock (stringTOResult)
     {
         string key = "" + textIn + "=" + filter;
         if (stringTOResult.TryGetValue(key, out term))
         {
             if (term == NILTerm)
             {
                 return(false);
             }
             return(true);
         }
         bool t          = lookup0(textIn, filter, out term, subquery);
         bool meansFalse = Unifiable.IsFalse(term);
         if (t != meansFalse)
         {
             if (meansFalse)
             {
                 writeToLog("NILTerm true=" + t + " term=" + term + " textIn" + textIn);
                 term = NILTerm;
             }
             else
             {
                 string paraphrase = Paraphrase(term);
                 writeToLog("true={0} term={1} textIn{2}  paraPhrase={3}", t, term, textIn, paraphrase);
             }
         }
         stringTOResult[key] = term;
         return(t);
     }
 }
        internal Unifiable SystemExecute(Unifiable cmd, Unifiable langu, Request user)
        {
            if (IsNullOrEmpty(langu))
            {
                langu = GlobalSettings.grabSetting("systemlang") ?? "bot";
            }
            else
            {
                langu = ToLower(Trim(langu));
            }
            Unifiable s = "The system tag should be doing '" + cmd + "' lang=" + langu;

            writeToLog(s.AsString());
            SystemExecHandler handler;

            if (SettingsDictionaryReal.TryGetValue(ExecuteHandlers, langu, out handler))
            {
                try
                {
                    object o = handler(cmd, user);
                    return(Unifiable.Create(o));
                }
                catch (Exception e)
                {
                    writeToLog(e);
                    return(Unifiable.Empty);
                }
            }
            else
            {
                try
                {
                    object            self   = user;
                    ScriptInterpreter parent = null;
                    ScriptInterpreter si     = ScriptManager.LoadScriptInterpreter(langu, self, parent);
                    object            o      = ScriptManager.EvalScriptInterpreter(cmd.ToValue(user.CurrentQuery), langu, self, parent, writeToLog);
                    string            siStr  = si.Str(o);
                    return(Unifiable.Create(siStr));
                }
                catch (Exception e)
                {
                    writeToLog(e);
                }
            }
            writeToLog(s);
            return(Unifiable.Empty);
        }
 public static Unifiable MatchKeyClean(Unifiable unifiable)
 {
     throw new NotImplementedException();
     return(ToUpper(MatchKeyClean(unifiable.AsString())));
 }
 /// <summary>
 ///   ctor
 /// </summary>
 /// <param name="bot"> The bot this transformer is a part of </param>
 /// <param name="inu"> The input Unifiable to be transformed </param>
 public TextTransformer(AltBot bot, string instr, Unifiable inu)
 {
     this.bot     = bot;
     inputStringU = inu ?? instr;
     inputString  = initialString = instr ?? inputStringU.AsString();
 }
Esempio n. 9
0
        public static bool ContainsAiml(Unifiable unifiable)
        {
            String s = unifiable.AsString();

            return(StaticXMLUtils.ContainsXml(s));
        }