Ejemplo n.º 1
0
        public CommItem?Process(IKorraAIModel model)
        {
            #region Get Fact Manager
            PureFacts pfManager = (PureFacts)model.ItemProviders.SingleOrDefault(x => x is PureFacts);
            if (pfManager == null)
            {
                SharedHelper.LogError("No manager in Facts Manager in MoviesModelUpdateTrigger.");
                return(null);
            }
            #endregion

            var    context = model.GetContext();
            string text    = "";

            PureFact factLikesVideoGames = (PureFact)pfManager.GetByName("UserLikesVideoGames");
            PureFact factThinksVideoGameIsGoodPresent = (PureFact)pfManager.GetByName("UserThinksVideoGameIsGoodPresent");
            PureFact userAge = (PureFact)pfManager.GetByName("UserAge");
            PureFact userSex = (PureFact)pfManager.GetByName("UserSex");

            if (factLikesVideoGames == null || factThinksVideoGameIsGoodPresent == null || userAge == null || userSex == null)
            {
                SharedHelper.LogError("factJob or factWatchedMovieYesterday is NULL in MoviesModelUpdateTrigger.");
            }

            bool UserLikesVideoGamesAnswered = factLikesVideoGames.IsAnswered;
            bool UserThinksVideoGameIsGoodPresentAnswered = factThinksVideoGameIsGoodPresent.IsAnswered;

            bool userAgeAnswered = userAge.IsAnswered;
            bool userSexAnswered = userSex.IsAnswered;

            if (!UserLikesVideoGamesAnswered)
            {
                return(null);
            }

            bool UserLikesVideoGamesAnsweredYES = context.BasePhrases.IsYes(factLikesVideoGames.Value); //only if answered

            //Calcualte 3 differerent surprises:

            //1. surprise because statistically people from this sex and age like computer games
            //Should like Video Games, but user answered No
            if (userAgeAnswered && userSexAnswered &&
                factLikesVideoGames.IsAnswered &&
                !UserLikesVideoGamesAnsweredYES //DOES NOT LIKE VIDEO GAMES
                )
            {
                int  Age    = Convert.ToInt32(userAge.Value);
                bool IsMale = userSex.Value.ToLower() == phrases.Male().ToLower();

                var likesVideoGamesInferred = BernoulliF(ProbVariables.User.playsGames(Age, IsMale)); //our estimation based on Age and Sex

                //Threshold check
                if (likesVideoGamesInferred.ProbOf(e => e == true).Value > 0.8)
                {
                    SharedHelper.LogWarning("VG S1 surprise inferred.");
                    text          = phrases.SurpriseVideoGames(1, false); //second parameter is not used
                    executedCount = executedCount + 1;

                    return(new CommItem
                    {
                        Category = ActionsEnum.MakeGeneralStatement,
                        Name = "ExpressVideoGamesSurprise",

                        TextToSay = text,
                        FacialExpression = FaceExp.SurpriseOnStartTalking,
                    });
                }
                else
                {
                    SharedHelper.LogWarning("No VG S1 surprise, because it is below threshold.");
                }
            }

            if (!UserThinksVideoGameIsGoodPresentAnswered)
            {
                return(null);
            }
            bool UserThinksVideoGameIsGoodPresentYES = context.BasePhrases.IsYes(factThinksVideoGameIsGoodPresent.Value); //only if answered

            //2. Surprise
            //Thinks games are good present - YES
            //Likes games in general - NO
            //surprise: LikesGames rendered more than 70% positive, but still answered NO by user
            //backward inference
            if (UserLikesVideoGamesAnswered &&
                !UserLikesVideoGamesAnsweredYES &&  //DOES NOT LIKE VIDEO GAMES
                UserThinksVideoGameIsGoodPresentAnswered &&
                UserThinksVideoGameIsGoodPresentYES //LIKES VG AS PRESENT
                )
            {
                var conditionThinksVideogameIsGoodPresent = ProbVariables.User.VideoGameModel.ConditionHard(e => e.ThinksVideogameIsGoodPresent);

                //for this query we are not using Age and Sex, because we already know that the user LikesVideoGames (answered by the user)
                double probLikesGamesConditionedOnThinksGamesAreGoodPresentInferred = conditionThinksVideogameIsGoodPresent.ProbOf(e => e.LikesVideoGames).Value;

                SharedHelper.LogWarning("S2 probLikesGamesConditionedOnThinksGamesAreGoodPresent: " + probLikesGamesConditionedOnThinksGamesAreGoodPresentInferred);

                //Threshold check
                if (probLikesGamesConditionedOnThinksGamesAreGoodPresentInferred > 0.6)
                {
                    SharedHelper.LogWarning("VG S2 surprise inferred.");
                    bool IsLikesGamesFirstAnswered = factLikesVideoGames.LastUpdated < factThinksVideoGameIsGoodPresent.LastUpdated;
                    text          = phrases.SurpriseVideoGames(2, IsLikesGamesFirstAnswered);
                    executedCount = executedCount + 1;

                    return(new CommItem
                    {
                        Category = ActionsEnum.MakeGeneralStatement,
                        Name = "ExpressVideoGamesSurprise",

                        TextToSay = text,
                        IsReactionToUser = true,
                        FacialExpression = FaceExp.SurpriseOnStartTalking,
                    });
                }
                else
                {
                    SharedHelper.LogWarning("No VG S2 surprise, because it is below threshold.");
                }
            }

            // 3. Surprise
            //Thinks games are a good present - NO
            //Likes games in general - YES
            //surprise: ThinkGamesGoodPresent rendered more than 70% positive, but still answered NO by user
            if (UserLikesVideoGamesAnswered &&
                UserThinksVideoGameIsGoodPresentAnswered &&
                UserLikesVideoGamesAnsweredYES &&     //LIKES VIDEO GAMES
                !UserThinksVideoGameIsGoodPresentYES) //DOES NOT LIKE VG AS PRESENT
            {
                //TODO: it should not be here, but attached to the item
                //THIS IS NEEDED FOR THE INFERRENCE BELOW ON: probThinksVideoGameIsGoodPresentInferred
                if (UserLikesVideoGamesAnsweredYES)
                {
                    ProbVariables.User.LikesVideoGames = BernoulliF(Prob(0.98));
                }

                var probThinksVideoGameIsGoodPresentInferred = ProbVariables.User.VideoGameModel.ProbOf(e => e.ThinksVideogameIsGoodPresent).Value;

                SharedHelper.LogWarning("S3 probThinksVideoGameIsGoodPresent: " + probThinksVideoGameIsGoodPresentInferred);

                //Threshold check
                if (probThinksVideoGameIsGoodPresentInferred >= 0.7)
                {
                    SharedHelper.LogWarning("VG S3 surprise inferred.");
                    bool IsLikesGamesFirstAnswered = factLikesVideoGames.LastUpdated < factThinksVideoGameIsGoodPresent.LastUpdated;
                    text          = phrases.SurpriseVideoGames(3, IsLikesGamesFirstAnswered);
                    executedCount = executedCount + 1;

                    return(new CommItem
                    {
                        Category = ActionsEnum.MakeGeneralStatement,
                        Name = "ExpressVideoGamesSurprise",

                        TextToSay = text,
                        FacialExpression = FaceExp.SurpriseOnStartTalking,
                    });
                }
                else
                {
                    SharedHelper.LogWarning("No VG S3 surprise, because it is below threshold.");
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private void LoadAllPureFacts()
        {
            PureFacts pfManager = (PureFacts)providers.SingleOrDefault(x => x is PureFacts);

            if (pfManager == null)
            {
                SharedHelper.LogError("No PureFact manager in LoadAllPureFacts.");
            }

            // enum PureFactType { AboutBot, AboutUser, UIQuestion, JokeQuestion, BuyQuestion };
            #region  Pure Facts about the User - they are provided as questions for the user

            pfManager.Add(new PureFact("UserName", PureFactType.AboutUser, "What is your name?", phrases.GreetAfterIntroduction, UIAnswer.Text));
            pfManager.Add(new PureFact("UserAge", PureFactType.AboutUser, "How old are you?", phrases.ProcessAge, UIAnswer.Text));
            pfManager.Add(new PureFact("UserLocation", PureFactType.AboutUser, "Where do you live? Which city and country?", "", "", UIAnswer.Text));
            pfManager.Add(new PureFact("UserNationality", PureFactType.AboutUser, "What is your nationality?", phrases.ProcessNationality, UIAnswer.Text));

            //Binary (Yes/No questions)
            pfManager.Add(new PureFact("UserHasJob", PureFactType.AboutUser, "Do you go to work every day?", new string[] { phrases.Yes(), phrases.No() }, "", UIAnswer.Binary));
            pfManager.Add(new PureFact("UserSex", PureFactType.AboutUser, "Are you a guy or a woman?", new string[] { phrases.Male(), phrases.Female() }, "", UIAnswer.Binary));
            pfManager.Add(new PureFact("UserHasKids", PureFactType.AboutUser, "Do you have kids?", new string[] { phrases.Yes(), phrases.No() }, phrases.ProcessHasKids, UIAnswer.Binary, new ContentType()));
            pfManager.Add(new PureFact("UserIsMarried", PureFactType.AboutUser, "Are you married?", new string[] { phrases.Yes(), phrases.No() }, phrases.ProcessMarried, UIAnswer.Binary, new ContentType()));

            pfManager.Add(new PureFact("EasilyOffended", PureFactType.AboutUser, "Are you easily offended?", new string[] { phrases.Yes(), phrases.No() }, "", UIAnswer.Binary, "OK, I promise to go easy on you.", "Nice. That gives me some liberty!", new ContentType(), FaceExp.SmileAfterTalking, FaceExp.SmileAfterTalking));

            pfManager.Add(new PureFact("UserLikesVideoGames", PureFactType.AboutUser, "Do you like video games?", new string[] { "Yes", "No" }, "", UIAnswer.Binary));
            pfManager.Add(new PureFact("UserThinksVideoGameIsGoodPresent", PureFactType.AboutUser, "Do you think video games are a good choice for a birthday's gift?", new string[] { "Yes", "No" }, "", UIAnswer.Binary));

            //joke LikesBoss
            pfManager.Add(new PureFact("UserLikesBoss", PureFactType.JokeQuestion, "Do you like your boss?", new string[] { phrases.Yes(), phrases.No() }, "", UIAnswer.Binary,
                                       "Seriously? Lucky you.",
                                       "You need to hack and land a few self driving cars in the living room of your boss. They will put the blame on the autopilot! Although sending more than five cars will look suspicious.",
                                       new ContentType(),
                                       FaceExp.SurpriseOnStartTalking,
                                       ""
                                       ));

            //joke StupidPeople
            pfManager.Add(new PureFact("StupidPeopleJoke", PureFactType.JokeQuestion, "You should not argue with stupid people, that is the path to happiness. Do you agree?",
                                       new string[] { phrases.Yes(), phrases.No() }, "", UIAnswer.Binary,
                                       "Yeah, they will drag you down to their level and then beat you with experience.",
                                       "<prosody pitch=\"+0%\">Actually<break time=\"600ms\"/>you are right.</prosody>",
                                       new ContentType()
                                       ));

            //TOO: should be a time based question: evening or after work, and repeated if date has changed
            pfManager.Add(new PureFact("UserMovieYesterday", PureFactType.AboutUser, "Did you watch a movie yesterday?", new string[] { phrases.Yes(), phrases.No() }, phrases.MovieSuggestions(), UIAnswer.Binary));

            #endregion

            #region Pure Facts about the Bot - they are provided as statements
            pfManager.Add(new PureFact("BotName", PureFactType.AboutBot, "", phrases.BotName(), "My name is " + phrases.BotName() + ".", UIAnswer.Text));
            pfManager.Add(new PureFact("BotAge", PureFactType.AboutBot, "", "30", "I am 30 years old.", UIAnswer.Text));
            pfManager.Add(new PureFact("BotSex", PureFactType.AboutBot, "", "female", phrases.IamAWoman(), UIAnswer.Text));
            pfManager.Add(new PureFact("BotVoiceRecognition", PureFactType.AboutBot, "", phrases.No(), "No need to shout. I can not access your microphone.", UIAnswer.Text));
            #endregion

            #region UI questions
            pfManager.Add(new PureFact("UIExitSystem", PureFactType.UIQuestion, phrases.ExitQuestion(), new string[] { phrases.Yes(), phrases.No() }, "", UIAnswer.Binary));
            pfManager.Add(new PureFact("SystemStartsCount", PureFactType.System, "", "0", "", UIAnswer.Text));
            #endregion
        }