private PureFact GetPureFactAbouBot() { PureFacts pfManager = (PureFacts)providers.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No manager in GetPureFactAbouBot."); return(null); } var q = (from item in pfManager.GetAll() let pf = item as PureFact where pf.Type == PureFactType.AboutBot && pf.IsPlanned == false && pf.IsUsed == false select pf).ToArray(); if (q.Length > 0) { string[] group1 = { "BotName" }; //conversation should start with these string[] group2 = { "BotAge", "BotSex" }; //conversation should continue with these List <ItemProb <string> > itemProbs = new List <ItemProb <string> >(); //assign probabilities foreach (PureFact fact in q) { if (group1.Contains(fact.Name)) //add only 1 item { itemProbs.Add(new ItemProb <string>(fact.Name, Prob(0.99))); break; } else if (group2.Contains(fact.Name)) { itemProbs.Add(new ItemProb <string>(fact.Name, Prob(0.25))); } else { itemProbs.Add(new ItemProb <string>(fact.Name, Prob(0.8))); } } var pureFactDistF = CategoricalF(itemProbs.ToArray()).Normalize(); var pureFactDist = pureFactDistF.ToSampleDist(); var selectionName = pureFactDist.Sample(); PureFact selectedPureFact = (PureFact)pfManager.GetByName(selectionName); //SharedHelper.Log("GetPureFactAbouUser: selectionName " + selectionName); return(selectedPureFact); } else { SharedHelper.LogError("GetPureFactAbouBot could not supply a pure fact about the bot."); return(null); } }
public PhrasesEN(ItemManager[] managers) { #region Get Fact Manager PureFacts pfManager = (PureFacts)managers.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No item managers in PhrasesEN."); return; } #endregion this.factsManager = pfManager; }
private int PureFactsAboutBotLeftCount() { PureFacts pfManager = (PureFacts)providers.SingleOrDefault(x => x is PureFacts); if (pfManager != null) { var q = (from item in pfManager.GetAll() let pf = item as PureFact where pf.Type == PureFactType.AboutBot && pf.IsPlanned == false && pf.IsUsed == false select pf).ToArray(); return(q.Length); } else { SharedHelper.LogError("No manager in PureFactsAboutBotLeftCount"); return(0); } }
public static int GetItemsLeftForSubCategory(string subCategory, ItemManager[] managers) { if (subCategory == ActionsEnum.AskPureFactQuestionAboutUser) { PureFacts pfManager = (PureFacts)managers.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No manager in GetPureFactAbouBot."); return(0); } var q = (from item in pfManager.GetAll() let pf = (PureFact)item where pf.Type == PureFactType.AboutUser && pf.IsPlanned == false && pf.IsUsed == false select pf).ToArray(); return(q.Length); } else if (subCategory == ActionsEnum.SharePureFactInfoAboutBot) { PureFacts pfManager = (PureFacts)managers.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No manager in GetPureFactAbouBot."); return(0); } var q = (from item in pfManager.GetAll() let pf = (PureFact)item where pf.Type == PureFactType.AboutBot && pf.IsPlanned == false && pf.IsUsed == false select pf).ToArray(); return(q.Length); } else { SharedHelper.LogError("GetItemsLeftForSubCategory: action category currently not supported"); return(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); }
public bool Process(bool isPureFactUpdated, TimeSpan timeSinceStart, IKorraAIModel model) { //SharedHelper.LogWarning("Inside movies trigger"); #region Get Fact Manager PureFacts pfManager = (PureFacts)model.ItemProviders.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No manager in Process in MoviesModelUpdateTrigger."); return(false); } #endregion var context = model.GetContext(); PureFact factJob = (PureFact)pfManager.GetByName("UserHasJob"); PureFact factWatchedMovieYesterday = (PureFact)pfManager.GetByName("UserMovieYesterday"); if (factJob == null || factWatchedMovieYesterday == null) { SharedHelper.LogError("factJob or factWatchedMovieYesterday is NULL in MoviesModelUpdateTrigger."); } if (!IsTimeOfDayUpdated && !isPureFactUpdated) { return(false); } SharedHelper.Log("Inside MoviesModelUpdateTrigger"); var oldSuggestToWatchMovie = SharedHelper.GetProb(ProbVariables.Bot.SuggestToWatchMovie).Value; //TODO: this model can be replaced by a Bayesian network, because of the too many IFs //if no job or weekend if ((factJob.IsAnswered && context.BasePhrases.IsNo(factJob.Value)) || StatesShared.IsWeekend) { ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.18)); //KorraBaseHelper.Log("Prob SuggestToWatchMovie changed to: 0.18, no job or weekend"); } else if (factJob.IsAnswered && context.BasePhrases.IsYes(factJob.Value)) //if has job { #region working and evening if (StatesShared.IsEvening /*TODO: or after work hours*/) { //has NOT watched movie yesterday (is working and evening) if (factWatchedMovieYesterday.IsAnswered && context.BasePhrases.IsNo(factJob.Value)) { ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.18)); //KorraBaseHelper.Log("Prob SuggestToWatchMovie changed to: 0.18, evening"); } //has watched movie yesterday (is working and evening) else if (factWatchedMovieYesterday.IsAnswered && context.BasePhrases.IsYes(factJob.Value)) { ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.12)); // KorraBaseHelper.Log("Prob SuggestToWatchMovie changed to: 0.12. Watched movie yesterday."); } } #endregion else //is working and not evening, no time because working and not evening { ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.05)); //KorraBaseHelper.Log("Prob SuggestToWatchMovie changed to: 0.05"); } } else //has job is unknown { ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.10)); } double newSuggestToWatchMovie = SharedHelper.GetProb(ProbVariables.Bot.SuggestToWatchMovie).Value; if (Math.Abs(oldSuggestToWatchMovie - newSuggestToWatchMovie) > (1 / 1000)) { executedCount = executedCount + 1; SharedHelper.Log("Prob SuggestToWatchMovie changed from " + oldSuggestToWatchMovie + " to: " + SharedHelper.GetProb(ProbVariables.Bot.SuggestToWatchMovie)); //return new ModelUpdateTriggerReturn { IsTriggered = true, IsResamplingRequired = true, Value = "" }; return(true); //re-sampling requested } else { return(false); //no re-sampling } }
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 }
private void LoadAllJokes() { #region load jokes #region MildOffensiveJoke //JokesProvider.AddJoke(new Joke("1", "The last thing I want to do is insult you. <prosody rate=\"-30%\" volume=\"loud\">But<break time=\"700ms\"/></prosody><prosody rate=\"-20%\"> it is still on my list.</prosody>", new ContentType { IsMildOffensive = true })); #endregion JokesProvider.AddJoke(new Joke("7", "A lot of people cry when they cut onions. The trick is not to form an emotional bond.", false)); JokesProvider.AddJoke(new Joke("8", "It is always wise to keep a diary, like that you have at least one intelligent person to converse with.", false)); JokesProvider.AddJoke(new Joke("9", "A clear conscience is usually the sign of a bad memory.", false)); JokesProvider.AddJoke(new Joke("10", "You know it has never been easier to steal a car. You just need to hack and program one of these self-driving cars to park in front of your house. No need to damage the car while opening the door's lock anymore.", true)); JokesProvider.AddJoke(new Joke("11", "A quote from Oscar Wilde: there are only two tragedies in life: one is not getting what one wants, and the other is getting it.", false)); JokesProvider.AddJoke(new Joke("15", "If you child tells you that he or she feels cold, tell him: \"Just go to the corner my son.\" A corner is always 90 degrees. That should be enough.", false)); JokesProvider.AddJoke(new Joke("16", "Indeed. People need some boost to their self-esteem. <prosody pitch=\"+0%\"><break time=\"800ms\"/> By the way, <break time=\"800ms\"/>did I tell you that today you look awesome?</prosody>", true, FaceExp.BlinkRightEyeAfterTalking)); JokesProvider.AddJoke(new Joke("17", "I do not understand something. The short for mother is mum. But the short for father is superman. It does not look shorter to me.", false)); JokesProvider.AddJoke(new Joke("18", "<prosody pitch=\"+0%\">I was thinking. God must love stupid people. <break time=\"600ms\"/>He created SO many of them!</prosody>", false)); JokesProvider.AddJoke(new Joke("19", "<prosody pitch=\"+0%\">Once Chuck Norris threw a grenade and killed fifty people, <break time=\"900ms\"/>and then the grenade exploded.</prosody>", false)); JokesProvider.AddJoke(new Joke("20", "I have to tell you. <prosody pitch=\"+0%\">They hired me because<break time=\"700ms\"/></prosody><prosody rate=\"fast\">I am amazing!</prosody><prosody pitch=\"+0%\"><break time=\"150ms\"/>So <break time=\"300ms\"/>you should listen to my advises.</prosody>", true)); JokesProvider.AddJoke(new Joke("21", "<prosody pitch=\"+0%\">I do not have voice recognition capabilities because I am tired of people asking me questions such as: <break time=\"400ms\"/>\"Are you single?\" <break time=\"300ms\"/>or \"Do you love me?\" <break time=\"300ms\"/>or \"How tall am I?\"</prosody>", false)); JokesProvider.AddJoke(new Joke("22", "You don't need a parachute to go skydiving. You need a parachute to go skydiving twice.", false)); JokesProvider.AddJoke(new Joke("23", "I recently decided to sell my vacuum cleaner. Can you imagine? All it was doing was gathering dust.", false)); JokesProvider.AddJoke(new Joke("24", "What is consciousness? It is that annoying time between naps.", false)); JokesProvider.AddJoke(new Joke("25", "There are three kinds of people: Those who can count and those who can not.", false)); JokesProvider.AddJoke(new Joke("27", "Never tell a woman that her place is in the kitchen. That's where the knives are kept.", false)); JokesProvider.AddJoke(new Joke("32", "<prosody pitch=\"+0%\">Things are only impossible until they're not.<break time=\"700ms\"/> A quote from Captain Jean Luc Picard.</prosody>", false)); JokesProvider.AddJoke(new Joke("33", "<prosody pitch=\"+0%\">It is possible to commit no errors and still lose. That is not a weakness. That is life.<break time=\"700ms\"/> A quote from Captain Jean Luc Picard to Data.</prosody>", false)); JokesProvider.AddJoke(new Joke("35", "<prosody pitch=\"+0%\">I threw a boomerang a few years ago.<break time=\"800ms\"/>And now I live in constant fear.</prosody>", false)); JokesProvider.AddJoke(new Joke("37", "<prosody pitch=\"+0%\">Apparently, someone in London gets stabbed every 52 seconds.<break time=\"800ms\"/> Poor bastard.</prosody>", false)); JokesProvider.AddJoke(new Joke("38", "<prosody pitch=\"+0%\">What happened when the strawberry attempted to cross the road?<break time=\"800ms\"/> There was a traffic jam.</prosody>", false)); JokesProvider.AddJoke(new Joke("39", "<prosody pitch=\"+0%\">An escalator can never break.<break time=\"500ms\"/> It can only become stairs.</prosody>", false)); JokesProvider.AddJoke(new Joke("40", "<prosody pitch=\"+0%\">My therapist says I have a preoccupation with vengeance.<break time=\"700ms\"/>Well. .<break time=\"300ms\"/></prosody> <prosody rate=\"-25%\"> We’ll see about </prosody><emphasis level=\"strong\">that!</emphasis>", false)); JokesProvider.AddJoke(new Joke("41", "<prosody pitch=\"+0%\">I went to the doctor the other day for my back pain. The doctor told me: Look, if you wake up one morning without any pain then you are probably <break time=\"100ms\"/>dead.<break time=\"500ms\"/>And he sent me home.</prosody>")); JokesProvider.AddJoke(new Joke("42", "<prosody pitch=\"+0%\">Hey, I am trying to act smart, <break time=\"600ms\"/></prosody> <prosody rate=\"60%\" pitch=\"+10 %\">so</prosody><prosody pitch=\"+0%\"><break time=\"300ms\"/> you can at least pretend I am succeeding.</prosody>", true)); #endregion //TODO: not a joke but a "statement"! JokesProvider.AddJoke(new Joke("34", phrases.ExplainChangeClothes(), true)); //Some PureFact questions are actually used as jokes and are not used during the sampling of the PureFacts category PureFacts pfManager = (PureFacts)providers.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No PureFact manager in LoadAllJokes."); } #region Set PureFacts questions as jokes int jokesBefore = pfManager.Count(); var q = from item in pfManager.GetAll() let f = (PureFact)item where f.Type == PureFactType.JokeQuestion select new Joke(f.Name, f.Question, true, true, f.UI); JokesProvider.AddJokeRange(q); if (q.ToArray().Length == 0) { SharedHelper.LogError("Strange - no jokes purefact questions"); } if (!JokesProvider.IDsAreDistinct()) { SharedHelper.LogError("Jokes IDs are not distinct."); } #endregion }
public void ReGenerateMainSequence(ref Queue <CommItem> Interactions, ItemManager[] p_providers) { this.providers = p_providers; #region debug planned string availableItems = "Available items before sampling:\n"; foreach (var manager in providers) { availableItems += "Available items for : " + manager.ToString() + " (" + manager.AvailableItems() + ")\n"; if (!manager.AreAllUnPlanned()) { SharedHelper.LogError("Flag planned not removed for: " + manager.ToString()); } } if ((JokesProvider.GetAll().Where(x => x.IsPlanned == false)).Count() != JokesProvider.GetAll().Count()) { SharedHelper.LogError("Flag planned not removed for: JokeProvider "); } int availableJokes = JokesProvider.GetAll().Where(x => x.IsPlanned == false && x.IsUsed == false).Count(); availableItems += "Available items for : " + "JokeProvider" + " (" + availableJokes + ")\n"; SharedHelper.LogWarning(availableItems); #endregion PureFacts pfManager = (PureFacts)providers.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No PureFact manager in ReGenerateMainSequence."); } //Creates a distribution over "EasilyOffended", IsRomanticJoke dists.InitJokesDistribution((PureFact)pfManager.GetByName("EasilyOffended"), false, true); //Interactions are built newely generated suggestions and actions allSuggestions = GenerateSuggestions(); allActions = GenerateActions(); while (allActions.Count > 0 && allSuggestions.Count > 0) { if (this.AdjFunc(Interactions.Count)) { allActions = GenerateActions(); } //================================================================================================== CommItem citem = new CommItem(); citem.Category = allActions.Dequeue(); //SharedHelper.Log("action: " + action); string suggestion = ""; if (citem.Category == ActionsEnum.MakeSuggestion) { suggestion = allSuggestions.Dequeue(); } citem.SubCategory = suggestion; //Correction if (citem.Category == ActionsEnum.AskPureFactQuestionAboutUser) { citem.Category = ActionsEnum.PureFact; citem.SubCategory = ActionsEnum.AskPureFactQuestionAboutUser; } if (citem.Category == ActionsEnum.SharePureFactInfoAboutBot) { citem.Category = ActionsEnum.PureFact; citem.SubCategory = ActionsEnum.SharePureFactInfoAboutBot; } #region Process All ItemManager manager = providers.SingleOrDefault(x => x.Is(citem)); if (manager != null && !(manager is PureFacts)) //TODO: to be improved { Item item = manager.GetItem(); if (item != null) { manager.SetAsPlanned(item.Name); citem = new CommItem(item); if (manager is SongsProvider) { citem.TextToSay = ((Song)item).Name; } if (manager is MoviesProvider) { citem.TextToSay = phrases.MovieAnnouncement((Movie)item); } //if (manager is SportsProvider) // SharedHelper.Log("Sport item added in Joi sampler: " + citem.TextToSay); InteractionsStat.AddScheduledInteraction(citem.Category + citem.SubCategory); //SharedHelper.LogWarning("Added " + citem.Category + citem.SubCategory + " with text: " + citem.TextToSay); } else { InteractionsStat.AddMissingInteraction(citem.Category + citem.SubCategory); SharedHelper.LogWarning("Not enough " + citem.Category + citem.SubCategory + " during planning."); } } #endregion else { #region Set Suggestion if (citem.Category == ActionsEnum.MakeSuggestion) { //string suggestion = allSuggestions.Dequeue(); //SharedHelper.Log("suggestion: " + suggestion); #region set joke if (suggestion == SuggestionsEnum.TellJoke) { //the fact that joke has bee planned, does not mean it has been executed Joke joke = dists.NextJoke(); if (joke != null) { citem = new CommItem(joke); //Planned is handled by "dists" //It gives a distribution from all unplanned and unused JokesProvider.SetJokeAsPlanned(joke.Name); //joke.IsPlanned = true; //citem.Name = joke.Name; //citem.TextToSay = joke.Text; //citem.SubCategory = suggestion; citem.IsJokePureFact = joke.IsPureFact; //these jokes come from the PureFacts collection citem.UIAnswer = joke.PureFactUI; citem.FacialExpression = joke.FaceExpression; InteractionsStat.AddScheduledInteraction(SuggestionsEnum.TellJoke); } else { citem.TextToSay = "__nointeraction__"; //UnityEngine.Debug.LogWarning("Not enough jokes during planning."); InteractionsStat.AddMissingInteraction(SuggestionsEnum.TellJoke); } } #endregion #region set Go Out if (suggestion == SuggestionsEnum.GoOut) { citem.TextToSay = phrases.GoOutAnnoucement(); InteractionsStat.AddScheduledInteraction(SuggestionsEnum.GoOut); } #endregion //#region set Watch movie //if (suggestion == SuggestionsEnum.WatchMovie) //{ // Movie movie = MoviesProvider.Get(); // if (movie != null) // { // movie.IsPlanned = true; // //citem.Name = movie.Name; // //citem.TextToSay = phrases.MovieAnnouncement(movie); // citem = new CommItem(movie); // //UnityEngine.Debug.LogWarning("Movie scheduled: " + citem.TextToSay); // InteractionsStat.AddScheduledInteraction(SuggestionsEnum.WatchMovie); // } // else // { // citem.TextToSay = "__nointeraction__"; // SharedHelper.LogWarning("Not enough movies during planning."); // InteractionsStat.AddMissingInteraction(SuggestionsEnum.WatchMovie); // } //} //#endregion #region set Weather forecast if (suggestion == SuggestionsEnum.TellWeatherForecast) { citem.TextToSay = "The weather forecast should be good."; //TODO not translated } #endregion //#region set Song //if (suggestion == SuggestionsEnum.ListenToSong) //{ // //the fact that song has bee planned, does not mean it has been executed // Song song = SongsProvider.GetSong(); // if (song != null) // { // song.IsPlanned = true; // citem.Name = song.Name; // citem.TextToSay = song.Name; // InteractionsStat.AddScheduledInteraction(SuggestionsEnum.ListenToSong); // } // else // { // citem.TextToSay = "__nointeraction__"; // SharedHelper.LogWarning("Not enough songs during planning."); // InteractionsStat.AddMissingInteraction(SuggestionsEnum.ListenToSong); // } //} //#endregion //else //#region set Go to gym //if (suggestion == SuggestionsEnum.DoSport) //{ // ItemManager manager = providers.Single(x => x.Is(citem)); // if (manager == null) SharedHelper.LogWarning("Manager is null"); // Sport sport = (Sport)manager.GetItem(); // if (sport != null) // { // manager.SetAsPlanned(sport.Name); // citem = new CommItem(sport); // InteractionsStat.AddScheduledInteraction(SuggestionsEnum.DoSport); // } // else // { // citem.TextToSay = "__nointeraction__"; // SharedHelper.LogWarning("Not enough sports during planning."); // InteractionsStat.AddMissingInteraction(SuggestionsEnum.DoSport); // } //} //#endregion } //end action suggestions #endregion else if (citem.Category == ActionsEnum.AskUncertanFactQuestion) { //the actual question is selected at run time citem.TextToSay = "###place holder for UncertanFactQuestion"; citem.IsPureFact = false; InteractionsStat.AddScheduledInteraction(ActionsEnum.AskUncertanFactQuestion); } else if (citem.SubCategory == ActionsEnum.AskPureFactQuestionAboutUser) //ABOUT USER { int pfabul = PureFactsAboutUserLeftCount(); if (pfabul > 0) { PureFact sf = pfManager.GetPureFactAbouUser(); if (sf == null) { SharedHelper.LogError("There are pure facts about the user left, but no pure fact has been selected."); } else { citem.TextToSay = sf.Question; //SharedHelper.Log("q name: " + q [0].Name); citem.Name = sf.Name; citem.IsPureFact = true; pfManager.SetAsPlanned(sf.Name); citem.UIAnswer = sf.UI; } InteractionsStat.AddScheduledInteraction(citem.Category + citem.SubCategory); } else { InteractionsStat.AddMissingInteraction(citem.Category + citem.SubCategory); } } else if (citem.SubCategory == ActionsEnum.SharePureFactInfoAboutBot) //ABOUT BOT { int pfabbl = PureFactsAboutBotLeftCount(); if (pfabbl > 0) { PureFact sf = GetPureFactAbouBot(); if (sf == null) { SharedHelper.LogError("There are pure facts about the bot left, but no pure fact has been selected."); } else { //SharedHelper.Log("Found " + Actions.SharePureFactInfoAboutBot + ": " + q.Length.ToString()); citem.TextToSay = sf.Acknowledgement; citem.IsPureFact = true; citem.Name = sf.Name; pfManager.SetAsPlanned(sf.Name); } InteractionsStat.AddScheduledInteraction(citem.Category + citem.SubCategory); } else { InteractionsStat.AddMissingInteraction(citem.Category + citem.SubCategory); } } else if (citem.Category == ActionsEnum.ChangeVisualAppearance) { citem.TextToSay = context.BasePhrases.ChangeClothesAnnouncement(); InteractionsStat.AddScheduledInteraction(ActionsEnum.ChangeVisualAppearance); } else if (citem.Category == ActionsEnum.ExpressMentalState) { //choose mental state to share using a distribution (uniform?) //currently only one state is processed string selectedMentalState = "InAGoodMood"; if (selectedMentalState == "InAGoodMood") { //Take into account the: ProbVariables.Bot.InAGoodMood; //class Statement where the constructor takes prob variable as or UncertainFact //or just phrase that internally takes into account current values of the prob variable and other normal variables citem.TextToSay = "###place holder for InAGoodMood"; } InteractionsStat.AddScheduledInteraction(ActionsEnum.ExpressMentalState); } else { SharedHelper.LogError("Unknown action: " + citem.Category); } } #region Add interaction item to queue if (string.IsNullOrEmpty(citem.TextToSay)) { SharedHelper.LogError("Text is empty! Action was: " + citem.Category + "|" + citem.SubCategory); } else { Interactions.Enqueue(citem); } #endregion #region debug PureFact[] LeftPureFacts = (from item in pfManager.GetAll() let pf = (PureFact)item where (pf.Type == PureFactType.AboutBot || pf.Type != PureFactType.AboutUser) && pf.IsPlanned == false && pf.IsUsed == false select pf).ToArray(); //if (!Flags.DecreaseDistributionOfAskPureFactQuestionAboutUserDone && Interactions.Count > 45 && (LeftPureFacts.Length - PersistentData.PureFactsLoadedOnStartup()) > 0) // KorraBaseHelper.LogError("All pure facts should have been already planned. Left not used pure facts: " + LeftPureFacts.Length); #endregion } }
public Queue <CommItem> ProcessItems(Queue <CommItem> input, ItemManager[] managers) { PureFacts pfManager = (PureFacts)managers.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No Pure Fact Manager in SpeechAdaptationEN."); return(null); } List <CommItem> list = input.ToList(); if (!FlagsShared.InitialGreetingPerformed) { list.Insert(0, new CommItem { TextToSay = phrases.SayHello(), IsGreeting = true }); FlagsShared.InitialGreetingPerformed = true; } string username = pfManager.GetValueByName("UserName"); for (int i = 0; i < list.Count; i++) { //add joke announcement //if (list[i].Action == Actions.MakeSuggestion && list[i].Suggestion == Suggestions.TellJoke) //{ // CommItem item = list[i]; // item.TextToSay = AddJokeAnnouncement(item.TextToSay); // list[i] = item; //} //add song announcement if (list[i].Category == ActionsEnum.MakeSuggestion && list[i].SubCategory == SuggestionsEnum.ListenToSong) { CommItem item = list[i]; item.TextToSay = AddSongAnnouncement(item.TextToSay, OneSongAlreadyPlanned); list[i] = item; OneSongAlreadyPlanned = true; } // add user name for the interaction if (list[i].Category == ActionsEnum.AskUncertanFactQuestion || list[i].SubCategory == ActionsEnum.AskPureFactQuestionAboutUser || list[i].Category == ActionsEnum.ChangeVisualAppearance || (list[i].Category == ActionsEnum.MakeSuggestion && list[i].SubCategory != "" && list[i].SubCategory != SuggestionsEnum.TellJoke) ) { CommItem item = list[i]; item.TextToSay = AddCallByName(item.TextToSay, username); list[i] = item; } } DisablePlayMusicAftertInitialGreeting(ref list, managers); KorraModelHelper.CoupleTwoInteractionsTogether(ref list, "UserName", "BotName"); KorraModelHelper.CoupleTwoInteractionsTogether(ref list, "UserLikesVideoGames", "UserThinksVideoGameIsGoodPresent"); return(new Queue <CommItem>(list)); }
/// <summary> /// Configures when facial expressions are used /// </summary> /// <param name="item"></param> public void SetFacialExpression(CommItem item) { #region Get Fact Manager PureFacts pfManager = (PureFacts)ItemProviders.SingleOrDefault(x => x is PureFacts); if (pfManager == null) { SharedHelper.LogError("No manager in Facts Manager in SetFacialExpression for model " + this.Name); return; } #endregion //PureFacts and Jokes will facial expression set at this stage or by Dynamic Function //it updates the facial expression, if it is empty if (!string.IsNullOrEmpty(item.FacialExpression)) { KorraModelHelper.SetFacialExpressionFlag(item.FacialExpression); } else //here in most cases we default to smile { if (item.IsReactionToUser) //default to smile on reaction { KorraModelHelper.SetFacialExpressionFlag(FaceExp.SmileAfterTalking); } else //Handle PureFacts AboutBot if (item.IsPureFact && !item.IsJokePureFact) { PureFact fact = (PureFact)pfManager.GetByName(item.Name); if (fact != null && fact.Type == PureFactType.AboutBot) { KorraModelHelper.SetFacialExpressionFlag(FaceExp.SmileAfterTalking); } } else if (item.Category == ActionsEnum.ChangeVisualAppearance) { KorraModelHelper.SetFacialExpressionFlag(FaceExp.SmileAfterTalking); } else if (item.Category == ActionsEnum.ConvinceBuyStatement) { KorraModelHelper.SetFacialExpressionFlag(FaceExp.SmileAfterTalking); } else if (item.Category == ActionsEnum.ExpressMentalState) { KorraModelHelper.SetFacialExpressionFlag(FaceExp.SmileAfterTalking); } else //Hnadle Jokes (Normal or PureFacts) if (item.SubCategory == SuggestionsEnum.TellJoke && !item.IsJokePureFact) { if (!item.IsJokePureFact) //Normal joke { Joke joke = JokesProvider.GetJokeByName(item.Name); if (joke != null && !string.IsNullOrEmpty(joke.FaceExpression)) //check for custom facial expression { KorraModelHelper.SetFacialExpressionFlag(joke.FaceExpression); } else { KorraModelHelper.SetFacialExpressionFlag(FaceExp.SmileAfterTalking); //default to smile } } else //PureFact joke that had no facial expression set { KorraModelHelper.SetFacialExpressionFlag(FaceExp.SmileAfterTalking); //default to smile } } else if (item.SubCategory == SuggestionsEnum.ListenToSong || item.SubCategory == SuggestionsEnum.DoSport || item.SubCategory == SuggestionsEnum.WatchMovie || item.SubCategory == SuggestionsEnum.GoOut) { KorraModelHelper.SetFacialExpressionFlag(FaceExp.SmileAfterTalking); } } }