public T grabSetting(string name)
 {
     if (containsLocalCalled(name))
     {
         return((T)(object)Unifiable.Create(propGet()));
     }
     return((T)(object)Unifiable.Empty);
 }
        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);
        }
Beispiel #3
0
 internal string FixPronouns(string englishIn, Func <string, string> whoAmI)
 {
     var pns = new[]
     {
         "him", "he", "she", "her", "them", "they", "it", "this",
         "i", "you", "me", "my", "your", "our", "their",
     };
     string english        = " " + englishIn.Trim() + " ";
     string englishToLower = english.ToLower();
     {
         foreach (var pronoun in pns)
         {
             if (englishToLower.Contains(" " + pronoun + " "))
             {
                 if (whoAmI == null)
                 {
                     writeToLog("FixPronouns: DONT KNOW THE USER TO RESOLVE '" + pronoun + "'");
                     return(english);
                 }
                 Unifiable v = Unifiable.Create(whoAmI(pronoun));
                 bool      goodReplacement = !Unifiable.IsIncomplete(v) && !Unifiable.IsNullOrEmpty(v) &&
                                             !Unifiable.IsMissing(v);
                 if (!goodReplacement)
                 {
                     writeToLog("FixPronouns: BAD REPLACEMENT '" + pronoun + "' => '" + v + "'");
                     continue;
                 }
                 english = ReplaceWord(english, pronoun, v);
                 if (pronoun != pronoun.Trim())
                 {
                     english = ReplaceWord(english, pronoun + "s", v + "s");
                 }
             }
         }
         englishToLower = english.ToLower();
         foreach (var pronoun in pns)
         {
             if (englishToLower.Contains(" " + pronoun + " "))
             {
                 Unifiable v = Unifiable.Create(whoAmI(pronoun));
                 writeToLog("FixPronouns: BAD REPLACEMENT '" + pronoun + "' => '" + v + "'");
             }
             continue;
         }
         return(english);
     }
 }
        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;
        }
Beispiel #6
0
 public void SetValue(object oldValue, object newValue, object unused)
 {
     setter.Invoke((T)(object)Unifiable.Create(newValue));
 }