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);
        }
Exemplo n.º 2
0
        public string GenFormatFactoid(string subject, string relation, object value, XmlNode templateNode)
        {
            string subj       = Entify(subject);
            var    dictionary = TheBot.GetDictionary(subj) as SettingsDictionary;

            bool      noValue = Unifiable.IsNullOrEmpty(value);
            Unifiable formatter;
            {
                if (noValue)
                {
                    // query mode
                    formatter = GetDictValue(dictionary, relation, "format-query");
                }
                else
                {
                    // assert mode
                    formatter = GetDictValue(dictionary, relation, "format-assert");
                }
            }

            var formatterUpper = Unifiable.ToUpper(formatter);

            if (Unifiable.IsNullOrEmpty(formatter) || Unifiable.IsTrueOrYes(formatterUpper) || formatter == "default")
            {
                formatter = " {0} {1} is {2} ";
            }

            if (Unifiable.IsFalseOrNo(formatterUpper))
            {
                return("false");
            }

            return(ExpandFormat(subj, relation, value, noValue, dictionary, formatter, templateNode));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public string ExpandFormat(string subj, string relation, object value, bool isQuery, SettingsDictionary dictionary, Unifiable formatter, XmlNode templateNode)
        {
            string pred = Entify(relation);

            string botName = !IsBotRobot(subj) ? Entify(TheBot.BotUserID) : Entify(TheBot.LastUser.UserID);
            {
                var whword = GetDictValue(dictionary, relation, "format-whword");

                if (!Unifiable.IsNullOrEmpty(whword) && isQuery)
                {
                    value = whword;
                }
                var formatterUpper = Unifiable.ToUpper(formatter);
                if (Unifiable.IsFalseOrNo(formatterUpper))
                {
                    return("false");
                }

                formatter = ReplaceWord(formatter, "$subject", "{0}");
                formatter = ReplaceWord(formatter, "$verb", "{1}");
                formatter = ReplaceWord(formatter, "$object", "{2}");

                formatter = ReplaceWord(formatter, "$user", "{0}");
                formatter = ReplaceWord(formatter, "$relation", "{1}");
                formatter = ReplaceWord(formatter, "$value", "{2}");

                formatter = ReplaceWord(formatter, "$predicate", pred);

                formatter = ReplaceWord(formatter, "$set-return",
                                        TheBot.RelationMetaProps.grabSetting(relation + "." + "set-return"));
                formatter = ReplaceWord(formatter, "$default", TheBot.DefaultPredicates.grabSetting(relation));

                formatter = ReplaceWord(formatter, "$botname", botName);
                formatter = ReplaceWord(formatter, "$bot", botName);
            }

            string english = " " + String.Format(formatter, subj, pred, Entify(value)).Trim() + " ";

            english = ReplaceWord(english, "I", subj);
            english = ReplaceWord(english, "you", botName);
            english = english.Trim();
            User user = TheBot.FindUser(subj);

            english = FixPronouns(english, user.grabSettingNoDebug);
            return(english);
        }
Exemplo n.º 5
0
        public static bool IsSomething(Unifiable s, out Unifiable something)
        {
            something = s;
            if (IsNullOrEmpty(s) || IsIncomplete(s) || IsMissing(s))
            {
                return(false);
            }
            string ss = s.ToUpper().Trim();

            if (ss.Contains("TAG-"))
            {
                return(false);
            }
            if (ss.Length < 2)
            {
                return(false);
            }
            if (ss == ".")
            {
                return(false);
            }
            return(ss != "NOTHING");
        }