Ejemplo n.º 1
0
        public Result HeardSomeoneSay1Sentence(bool saveResultsAsIfRealtime, bool useConversationDataAsIfRealtime, User theFactSpeaker, User toWhom, string message, Result result, ThreadControl control)
        {
            if (MyBot.useServitor)
            {
                return(null);
            }
            Logger.Warn("in TODO code");
            bool   toWhomNonNull        = toWhom != null;
            string whatListenerLastSaid = null;

            if (toWhomNonNull && useConversationDataAsIfRealtime)
            {
                whatListenerLastSaid = toWhom.JustSaid;
            }
            var       log    = ConversationLog.GetConversationLog(theFactSpeaker, toWhom, true);
            Utterance spoken = log.AddSpoken(this, theFactSpeaker, toWhom, message);
            Result    res    = HeardSome1Say11Sentence(saveResultsAsIfRealtime, useConversationDataAsIfRealtime, theFactSpeaker, toWhom, spoken, message, result, control);

            if (saveResultsAsIfRealtime)
            {
                if (toWhomNonNull)
                {
                    toWhom.That = message;
                }
                theFactSpeaker.JustSaid = message;
                if (toWhomNonNull)
                {
                    toWhom.JustSaid = whatListenerLastSaid;
                }
                return(res);
            }
            return(res);
        }
Ejemplo n.º 2
0
        public Utterance AddSpoken(AltBot robot, User speaker, User toWhom, Unifiable message)
        {
            var ce = new Utterance(robot.EnsureEnglish, speaker, toWhom, message, -1);

            AltBot.writeDebugLine("AddSpoken: " + ce);
            Elements.AddFirst(ce);
            return(ce);
        }
Ejemplo n.º 3
0
        private Result UnderstandSentence(bool saveResultsAsIfRealtime, bool useConversationDataAsIfRealtime, Utterance ele, User theFactSpeaker, User toWhom, string desc, string message, Result prevResult, ThreadControl control)
        {
            if (!TryUnderstandSentence)
            {
                return(null);
            }
            if (this.TurnOffSelfListening)
            {
                return(null);
            }
            if (MyBot.useServitor)
            {
                return(null);
            }
            Logger.Warn("In TODO code");
            string whatListenerLastSaid =
                (useConversationDataAsIfRealtime && toWhom == null) ? null : toWhom.JustSaid;
            string whatSpeakerLastSaid =
                (useConversationDataAsIfRealtime && theFactSpeaker == null) ? null : theFactSpeaker.JustSaid;

            //theFactSpeaker.JustSaid = message;
            if (toWhom != null)
            {
                //lock (toWhom.QueryLock)
                {
                    prevResult = prevResult ?? toWhom.GetResult(0, true, theFactSpeaker);
                    if (prevResult != null)
                    {
                        prevResult.request.AddOutputSentences(null, message, prevResult,
                                                              prevResult.request.TopLevelScore);
                    }
                }
            }
            if (AllreadyUnderstandingSentences)
            {
                writeDebugLineBannered("HEARDSELF: TOOOO FAST - " + message);
                return(null);
            }
            lock (AllreadyUnderstandingSentencesLock)
            {
                if (AllreadyUnderstandingSentences)
                {
                    writeDebugLineBannered("HEARDSELF: TWOOOO FAST - " + message);
                    return(null);
                }
                AllreadyUnderstandingSentences       = true;
                AllreadyUnderstandingSentencesThread = Thread.CurrentThread;
            }
            writeDebugLineBannered("HEARDSELF: " + theFactSpeaker + "->" + toWhom + ": " + message);
            //return LR;
            try
            {
                var HG = DefaultHeardSelfSayGraph;

                if (message == null || message.Length < 4)
                {
                    return(null);
                }
                Request r = theFactSpeaker.CreateRequest(message, toWhom, whatListenerLastSaid, HG, null, true,
                                                         RequestKind.InnerSelfTalk);
                // irregardless we only mentally played what the responder responded with
                r.ResponderSelfListens = false;
                // because the  listener cant hear this inner dialog
                r.SaveResultsOnJustHeard = false;
                if (control != null)
                {
                    control.AbortRaised += (ctl, abrtedE) =>
                    {
                        r.WhyComplete = "THREADABORTED";
                    }
                }
                ;
                var G = HG;
                if (G == null)
                {
                    writeDebugLineBannered("HeardSelfSayGraph == null: " + message + " res = " + prevResult);
                    return(null);
                }
                r.Graph             = G;
                r.IsTraced          = true;
                r.IsToplevelRequest = true;
                try
                {
                    Result res2 = Chat(r);
                    ele.IsSpeakerInputGleaned = true;
                    writeDebugLineBannered("COMPLETED HEARDSELF: " + message + " res = " + res2);
                    return(res2);
                }
                catch (ChatSignal e)
                {
                    writeDebugLineBannered("INCOMPLETE HEARDSELF: " + message + " req = " + r + " " + e);
                    throw;
                }
                catch (Exception e)
                {
                    writeToLog(e);
                    throw;
                    //return null;
                }
            }
            finally
            {
                AllreadyUnderstandingSentences = false;
                // FYI: this "JustSaid" sets "lastsaid" in dictioanry
                if (saveResultsAsIfRealtime)
                {
                    if (toWhom != null)
                    {
                        toWhom.JustSaid = whatListenerLastSaid;
                    }
                    theFactSpeaker.JustSaid = whatSpeakerLastSaid;
                }
            }
        }
Ejemplo n.º 4
0
        private Result RememberSpoken(bool saveResultsAsIfRealtime, bool useConversationDataAsIfRealtime, Utterance ele, User theFactSpeaker, User toWhom, string desc, string message, Result prevResult, ThreadControl control)
        {
            if (!TryUnderstandSentence)
            {
                return(null);
            }
            if (this.TurnOffSelfListening)
            {
                return(null);
            }
            if (MyBot.useServitor)
            {
                return(null);
            }
            if (NonSalientMessage(message))
            {
                return(null);
            }
            message = ToHeard(message);
            if (string.IsNullOrEmpty(message))
            {
                return(null);
            }
            writeChatTrace(desc);
            if (UnderstandSentenceOutsideQueue)
            {
                if (AllreadyUnderstandingSentences)
                {
                    Logger.Warn("I hope this is the correct thread!");
                }
                Result res = UnderstandSentence(saveResultsAsIfRealtime, useConversationDataAsIfRealtime, ele, theFactSpeaker, toWhom, desc, message, prevResult, control);
                if (saveResultsAsIfRealtime)
                {
                    theFactSpeaker.JustSaid = message;
                }
                return(res);
            }

            if (control != null)
            {
                control.AbortRaised += (ctl, abrtedE) => writeToLog("Aborted " + desc);
            }
            Result result;

            saveResultsAsIfRealtime = useConversationDataAsIfRealtime = false;
            HeardSelfSayQueue.EnqueueWithTimeLimit(()
                                                   => result = UnderstandSentence(saveResultsAsIfRealtime, useConversationDataAsIfRealtime, ele, theFactSpeaker, toWhom, desc, message, prevResult, control), desc,
                                                   TimeSpan.FromSeconds(10), control);
            //if (control != null) control.WaitUntilComplete();
            return(null);
        }
Ejemplo n.º 5
0
        public Result HeardSome1Say11Sentence(bool saveResultsAsIfRealtime, bool useConversationDataAsIfRealtime, User theFactSpeaker, User toWhom, Utterance ele, string message, Result prevResult, ThreadControl control)
        {
            if (this.TurnOffSelfListening)
            {
                return(null);
            }
            if (MyBot.useServitor)
            {
                return(null);
            }
            //Result LR = result;
            if (message == null)
            {
                return(null);
            }

            bool lts    = ListeningToSelf;
            bool prochp = ProcessHeardPreds;

            if (!lts && !prochp)
            {
                return(null);
            }

            message = GetUserMessage(message, ref theFactSpeaker, ref toWhom);

            bool   toWhomNonNull = toWhom != null;
            string debug         = "HeardSelfSay11Sentence: \"" + theFactSpeaker ?? "theFactSpeaker" + ": " + toWhom ?? "toWhom" + ", " + message + "\"";

            message = ToHeard(message);
            if (string.IsNullOrEmpty(message))
            {
                return(null);
            }
            //message = swapPerson(message);
            //writeDebugLine("HEARDSELF SWAP: " + message);
            User JLU = LastUser;

            if (JLU != null)
            {
                string uname = JLU.UserName;
                if (uname == null || uname.Length < 2)
                {
                }
                else
                {
                    if (message.Replace(" ", "_").ToLower().Contains(uname.Replace(" ", "_").ToLower()))
                    {
                        JLU.NameUsedOrGivenTime = DateTime.Now;
                    }
                }
            }


            if (prochp)
            {
                writeDebugLine("-----------------------------------------------------------------");
                AddHeardPreds(message, HeardPredicates);
                writeDebugLine("-----------------------------------------------------------------");
            }
            if (!lts)
            {
                writeDebugLine("-----------------------------------------------------------------");
                writeDebugLine("NO LTS " + theFactSpeaker + ": " + message);
                writeDebugLine("-----------------------------------------------------------------");
                return(null);
            }
            bool   wasQuestion = NatLangDb.WasQuestion(message);
            string desc        = string.Format("ROBOT {1} USER: {0}", message, wasQuestion ? "ASKS" : "TELLS");
            string realLast    = null;
            //if (toWhomNonNull)  realLast = toWhom.JustSaid;
            var res = RememberSpoken(saveResultsAsIfRealtime, useConversationDataAsIfRealtime, ele, theFactSpeaker, toWhom, desc, message, prevResult, control);

            //theFactSpeaker.JustSaid = message;
            //if (toWhomNonNull) toWhom.JustSaid = realLast;
            return(res);
        }