コード例 #1
0
 private User CreateNewUser0(string fullname, string key)
 {
     //lock (BotUsers)
     {
         string username = fullname;
         fullname = CleanupFromname(fullname);
         int spaces = TextPatternUtils.CountOf(fullname, " ");
         if (spaces > 1)
         {
             throw new InvalidCastException("fullname=" + fullname);
         }
         key = key.ToLower();
         User myUser = new MasterUser(key, username, this, null);
         myUser.userTrace = writeToUserLog;
         myUser.UserName  = username;
         writeToUserLog("New User " + fullname + " -DEBUG9");
         if (key != null)
         {
             lock (microBotUsersLock) BotUsers[key] = myUser;
         }
         bool roleAcct = IsRoleAcctName(fullname);
         myUser.IsRoleAcct = roleAcct;
         myUser.AddTodoItem(() => SetupUserData(myUser, fullname, key));
         return(myUser);
     }
 }
コード例 #2
0
        /// <summary>
        /// @askall what is 1 plus 1?
        /// </summary>
        /// <param name="textstr"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public virtual object AskTextStringAll(string textstr, Request request)
        {
            string said;
            string tolang;

            if (!TextPatternUtils.SplitOff(textstr, "-", out tolang, out said))
            {
                tolang = "";
                said   = textstr;
            }
            string res        = tolang;
            var    allResults = new List <ISearchResult>();

            foreach (IDocSearch searchSource in SearchSources)
            {
                try
                {
                    foreach (ISearchResult re in searchSource.Search(said, null))
                    {
                        allResults.Add(re);
                        res += " " + re.ToString();
                    }
                }
                catch (Exception e)
                {
                    writeToLog("ERROR: " + e);
                }
            }
            if (allResults.Count == 0)
            {
                return(tolang);
            }
            return(res.Trim());
        }
コード例 #3
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);
        }
コード例 #4
0
        private Unifiable CleanupCyc0(string text)
        {
            text = TextPatternUtils.ReTrimAndspace(text);
            int l_1 = text.Length - 1;

            if (l_1 < 2)
            {
                return(text);
            }
            char c = text[l_1];

            if (!text.Contains("#$"))
            {
                return(text);
            }
            if (char.IsPunctuation(c))
            {
                return(CleanupCyc0(text.Substring(0, l_1)) + c);
            }
            int i = text.IndexOf(" ");

            if (i > 0)
            {
                String stext = CleanupCyc0(text.Substring(0, i)).AsString() + " " + CleanupCyc0(text.Substring(i + 1)).AsString();
                return(stext);
            }
            if (text.StartsWith("#$") || text.StartsWith("(#$"))
            {
                return(TextPatternUtils.ReTrimAndspace(Paraphrase0(text).AsString().Replace("#$", " ")));
            }
            return(TextPatternUtils.ReTrimAndspace(text.Replace("#$", " ")));
        }
コード例 #5
0
ファイル: Utterance.cs プロジェクト: hackerlank/trunk-chatbot
        public Unifiable GetSentence(int sentenceNum, bool mustBeSailent)
        {
            if (sentenceNum == 0)
            {
                return(RawText);
            }
            String sentenceIn = RawText;

            foreach (Unifiable output in EnglishSentences)
            {
                sentenceIn = output;
                String sentence = OutputSentencesToEnglish(output);
                sentence = MainSentence(sentence);
                sentence = TextPatternUtils.SymTrim(sentence);
                if (sentence.Length < 2)
                {
                    continue;
                }
                sentenceNum--;
                if (sentenceNum == 0)
                {
                    return(sentence);
                }
            }
            return(sentenceIn);
        }
コード例 #6
0
 public override string ToString()
 {
     if (!AltBot.IncludeMeNeValue)
     {
         return(Text);
     }
     return(TextPatternUtils.SafeFormat("{0} (menevalue= {1:1} )", Text, Score));
 }
コード例 #7
0
        private bool IsExcludedSRV(string subject, string relation, string value, string factoidSRV,
                                   OutputDelegate writeToLog, string fmtString, params object[] fmtArgs)
        {
            bool ExcludedFactPattern = false;
            bool debug = (writeToLog != null);

            fmtString = TextPatternUtils.SafeFormat(fmtString, fmtArgs);
            if (factoidSRV == "false")
            {
                if (!debug)
                {
                    return(true);
                }
                writeToLog("ExcludedSRV: '{0}' Format '{1}'", fmtString, relation);
                ExcludedFactPattern = true;
            }
            fmtString += " " + factoidSRV;
            if (IsExcludedRelation(relation))
            {
                if (!debug)
                {
                    return(true);
                }
                writeToLog("ExcludedSRV: '{0}' Relation '{1}'", fmtString, relation);
                if (!ExtremeDebug)
                {
                    return(true);
                }
                ExcludedFactPattern = true;
            }
            if (IsExcludedSubject(subject))
            {
                if (!debug)
                {
                    return(true);
                }
                writeToLog("ExcludedSRV: '{0}' Subject '{1}'", fmtString, subject);
                if (!ExtremeDebug)
                {
                    return(true);
                }
                ExcludedFactPattern = true;
            }
            if (IsExcludedValue(value))
            {
                if (!debug)
                {
                    return(true);
                }
                writeToLog("ExcludedSRV: '{0}' Value '{1}'", fmtString, value);
                ExcludedFactPattern = true;
            }
            if (debug)
            {
                writeToLog(factoidSRV + " " + fmtString, fmtArgs);
            }
            return(ExcludedFactPattern);
        }
コード例 #8
0
        public Unifiable CycCleanupCyc(string text)
        {
            text = TextPatternUtils.ReTrimAndspace(text);
            string s = CleanupCyc0(text);

            if (s == "NIL")
            {
                writeToLog("ERROR: became nil: " + text);
                return(text);
            }
            return(s);
        }
コード例 #9
0
 public void WriteLine(string s, params object[] args)
 {
     s = TextPatternUtils.SafeFormat(s, args);
     if (s.StartsWith("Trace"))
     {
         return;
     }
     if (s.StartsWith("Debug"))
     {
         return;
     }
     TheBot.writeToLog("HTTPD: " + s);
 }
コード例 #10
0
        public static object GetParaphrase(string textstr, Request request)
        {
            string said;
            string tolang;

            if (!TextPatternUtils.SplitOff(textstr, "-", out tolang, out said))
            {
                tolang = "bg";
                said   = textstr;
            }
            textstr = GetGoogPraphrase(said, tolang);
            return(textstr);
        }
コード例 #11
0
ファイル: Utterance.cs プロジェクト: hackerlank/trunk-chatbot
        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);
        }
コード例 #12
0
        private void writeToLog(string s, params object[] p)
        {
            //bool tempB = TheBot.IsLogging;
            //TheBot.IsLogging = true;
            //TheBot.writeToLog("LUCENE: " + s, p);
            //TheBot.IsLogging = tempB;
            s = TextPatternUtils.SafeFormat(s, p);

            if (s.ToUpper().Contains("EXCLUDE"))
            {
                return;
            }
            DLRConsole.DebugWriteLine("LUCENE: " + s);
        }
コード例 #13
0
        public Unifiable GetDictValue(SettingsDictionary dict, string relation, string meta)
        {
            if (dict != null)
            {
                string formatter = dict.GetMeta(relation, meta);
                if (!TextPatternUtils.IsNullOrEmpty(formatter))
                {
                    return(formatter);
                }
            }
            string prop = relation + "." + meta;

            return(TheBot.RelationMetaProps.grabSetting(prop));
        }
コード例 #14
0
        private string GetUserMessage(string message, ref User theFactSpeaker, ref User toWhom)
        {
            string newMessage;
            string newToWhom;
            string newFromWhom;

            if (theFactSpeaker == BotAsUser &&
                TextPatternUtils.MessagePrefixName(":", message, out newToWhom, out newFromWhom, out newMessage))
            {
                message        = newMessage;
                theFactSpeaker = FindOrCreateUser(newFromWhom);
                toWhom         = FindOrCreateUser(newToWhom);
            }
            return(message);
        }
コード例 #15
0
        public string GetUserMessage(string message, ref string theFactSpeaker, ref string toWhom)
        {
            string newMessage;
            string newToWhom;
            string newFromWhom;

            if (BotAsUser.IsNamed(theFactSpeaker) &&
                TextPatternUtils.MessagePrefixName(":", message, out newToWhom, out newFromWhom, out newMessage))
            {
                message        = newMessage;
                theFactSpeaker = newFromWhom;
                toWhom         = newToWhom;
            }
            return(message);
        }
コード例 #16
0
        public object getPosterBoard(object slot)
        {
            string sslot = "" + slot;

            sslot = sslot.ToLower();
            var u = TheBot.GlobalSettings.grabSetting(sslot);

            if (Unifiable.IsNull(u))
            {
                return(null);
            }
            if (TextPatternUtils.IsNullOrEmpty(u))
            {
                return("");
            }
            return(u);//.ToValue(null);
        }
コード例 #17
0
 internal bool IsaFilter(Unifiable term, Unifiable filter)
 {
     if (!Unifiable.IsValue(term))
     {
         return(false);
     }
     if (term == "NIL")
     {
         return(false);
     }
     if (!Unifiable.IsNullOrEmpty(filter))
     {
         if (Unifiable.IsFalse(filter))
         {
             return(true);
         }
         if (this.EvalSubL(TextPatternUtils.SafeFormat("(ask-template 'T `(#$isa {0} {1}) #$EverythingPSC)", Cyclify(term), Cyclify(filter)), null) == "NIL")
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #18
0
 internal Unifiable Paraphrase0(string text)
 {
     if (!CycEnabled)
     {
         return(TextPatternUtils.ReTrimAndspace(text.Replace("#$", " ")));
     }
     if (text.StartsWith("("))
     {   //todo is a list then?
         text = String.Format("'{0}", text);
     }
     else if (text.StartsWith("'#$"))
     {
         text = text.Substring(1);
     }
     //return text;
     try
     {
         text = text.TrimEnd(".".ToCharArray());
         if (text.Trim().Length == 0)
         {
         }
         if (text == "'()" || text == "NIL")
         {
             return("");
         }
         string res = EvalSubL(String.Format("(generate-phrase {0})", text), null);
         if (String.IsNullOrEmpty(res))
         {
             return(text);
         }
         return(res);
     }
     catch (System.Exception ex)
     {
         return(text);
     }
 }
コード例 #19
0
        public virtual object AskTextStringJustHere(string textstr, Request request)
        {
            string said;
            string tolang;

            if (!TextPatternUtils.SplitOff(textstr, "-", out tolang, out said))
            {
                tolang = "";
                said   = textstr;
            }
            string res        = tolang;
            var    allResults = new List <ISearchResult>();

            foreach (ISearchResult re in Search(said, null))
            {
                allResults.Add(re);
                res += " " + re.ToString();
            }
            if (allResults.Count == 0)
            {
                return(tolang);
            }
            return(res.Trim());
        }
コード例 #20
0
        public Unifiable[] TransformU()
        {
            if (true)
            {
                var         ss = StaticAIMLUtils.SentenceBreaker(inputString, TrimEndTokens).ToArray();
                Unifiable[] us = new Unifiable[ss.Length];
                for (int i = 0; i < ss.Length; i++)
                {
                    us[i] = ss[i];
                }
                return(us);
            }
            string[] tokens = null;
            if (bot != null)
            {
                tokens = bot();
            }
            string inputStringString = this.inputString.AsString();
            string nonSplitTags      = TextPatternUtils.ReplaceMap(inputStringString,
                                                                   new string[][]
            {
                new[] { "<br>", " " },
                new[] { "<p>", " " },
                new[] { "<br/>", " " },
                new[] { "<p/>", " " }
            });

            if (nonSplitTags.Contains("<"))
            {
                return(new [] { inputString });
            }
            inputStringString = StaticAIMLUtils.ForInputTemplate(inputStringString);
            Unifiable[] nodes            = this.inputString.ToArray();
            int         currentTokenbNum = 0;
            int         startTokenNum    = 0;

            if (tokens == null)
            {
                List <Unifiable> tidyString = new List <Unifiable>();
                tokens = new[] { "! ", "? ", ". ", ", ", "br>", "<p>", "<br/>", "<p/>" };
                foreach (string token in tokens)
                {
                    inputStringString = inputStringString.Replace(token, token + " <split/> ");
                }
                string[] sss = inputStringString.Split(new[] { "<split/>" },
                                                       System.StringSplitOptions.RemoveEmptyEntries);
                foreach (string rawSentence in sss)
                {
                    string tidySentence =
                        TextPatternUtils.ReTrimAndspace(rawSentence.Replace("<p/>", " ").Replace("<br/>", " ").Replace("<br>", " ").Replace("<p>", " "));

                    tidySentence = StaticAIMLUtils.ForInputTemplate(tidySentence);
                    if (tidySentence.Length > 0)
                    {
                        tidyString.Add(tidySentence);
                    }
                    if (tidySentence == "." || tidySentence == "?")
                    {
                        continue;
                    }
                }
                if (tidyString.Count > 0)
                {
                    return(tidyString.ToArray());
                }
                else
                {
                    return(new Unifiable[] { inputStringString });
                }
                inputStringString = inputStringString.TrimStart(".!? ,".ToCharArray());
                while (inputStringString.Length > 0)
                {
                    int index = inputStringString.IndexOfAny(".!?".ToCharArray());
                    if (index > 1)
                    {
                        string ss = inputStringString.Substring(0, index + 1);
                        tidyString.Add(ss);
                        inputStringString = inputStringString.Substring(index + 1);
                        continue;
                    }
                    tidyString.Add(inputStringString);
                }
                return(tidyString.ToArray());
            }
            string[]         rawResult  = this.inputString.AsString().Split(tokens, System.StringSplitOptions.RemoveEmptyEntries);
            List <Unifiable> tidyResult = new List <Unifiable>();

            foreach (string rawSentence in rawResult)
            {
                string tidySentence = rawSentence.Trim();
                if (tidySentence.Length > 0)
                {
                    tidyResult.Add(tidySentence);
                }
            }
            return((Unifiable[])tidyResult.ToArray());
        }
コード例 #21
0
ファイル: Utterance.cs プロジェクト: hackerlank/trunk-chatbot
 public override string ToString()
 {
     return("M: " + TheMainSentence + " E: <" + TextPatternUtils.CollectionString(EnglishSentences) + ">");
 }