public override bool ProcessUserIntent(UserIntent intent) { if (base.ProcessUserIntent(intent)) { return(true); } switch (intent.Intent) { case UserIntent.IntentType.Quit: PushState(new ConfirmState("Are you sure you want to quit? (yes/no)", OnQuitConfirmed, null)); return(true); case UserIntent.IntentType.Query: if (intent.Target == IntentTarget.Commands) { gameData.VisualConsoleHistory.AddLine("Known Commands:"); object idContext = gameData.VisualConsoleHistory.Indent(); ActiveState.SupportedCommands.ForEach(command => gameData.VisualConsoleHistory.AddLine(command)); gameData.VisualConsoleHistory.Unindent(idContext); return(true); } break; case UserIntent.IntentType.Reboot: PushState(new ConfirmState("System will restart, confirm (yes/no)", Reboot, null)); return(true); case UserIntent.IntentType.Unknown: gameData.VisualConsoleHistory.AddLine($"Unknown command"); return(true); } return(false); }
public IIntentStrategy GetStrategy(UserIntent userIntent) { if (_intentStrategies.TryGetValue( userIntent.Intent.ToString(), out var Strategy)) { return(Strategy); } throw new ArgumentException( $"The Intent {userIntent.Intent} is not handled", nameof(userIntent)); }
public override bool ProcessUserIntent(UserIntent intent) { switch (intent.Intent) { case UserIntent.IntentType.Confirm: onPromptConfirmed?.Invoke(); Done = true; break; case UserIntent.IntentType.Cancel: onPromptCanceled?.Invoke(); Done = true; break; default: gameData.VisualConsoleHistory.AddLine("Unable to parse response"); gameData.VisualConsoleHistory.AddLine(promptContent); break; } return(true); }
public override bool ProcessUserIntent(UserIntent intent) { if (base.ProcessUserIntent(intent)) { return(true); } switch (intent.Intent) { case UserIntent.IntentType.Diag: PushState(typeof(RunDiagnosticState)); return(true); case UserIntent.IntentType.Reboot: if (!gameData.ObjectiveComplete(GameData.FullyBooted)) { gameData.VisualConsoleHistory.AddLine("System unstable, reboot will likely corrupt essential processes."); return(true); } break; } return(false); }
public string[] createReplayToUser(string text, UserIntent answerIntent) { //if user pressing category if (getStudyCategory().Contains(text.Trim())) { throw new menuException(); } switch (answerIntent) { case UserIntent.dontKnow: var feedback = ConversationController.getPhrase(Pkey.neverMind); feedback = ConversationController.mergeText(feedback, ConversationController.getPhrase(Pkey.MyAnswerToQuestion)); feedback = answerArrayToString(new List <string>(studySession.CurrentSubQuestion.answerText.Split('|')), feedback); return(feedback); case UserIntent.menu: throw new menuException(); case UserIntent.stopSession: throw new StopSessionException(); case UserIntent.sessionBreak: throw new sessionBreakException(); case UserIntent.bot_questions: case UserIntent.DefaultFallbackIntent: case UserIntent.unknown: case UserIntent.historyAnswer: default: return(formatPhrases(qac.createFeedBack(checkAnswer(text)))); } return(null); }
public abstract Task ProcessIntentAsync(UserIntent userIntent);
public override async Task ProcessIntentAsync(UserIntent userIntent) => await StrategyHelper.DisplayAsync($"{userIntent.Intent} in {nameof(IntentStrategyAverage)}");
private void suggestionUtterance() { string utteranceFile = AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + Tools.utteranceFilePath; List <UserIntent> intentList; UserIntent intent = new UserIntent(); if (System.IO.File.Exists(utteranceFile)) { intentList = GenerateIntents(utteranceFile); } else { intentList = GenerateIntents(); } Match match = null; //intent override, if you need to make a linear survey like use case intent.Intent = Survey.check(this); //linq query to get the correct intent match with many utterances if (Entities.Count == 0 || match.Success) { intent = intentList.Where(f => f.Intent.ToLower() == Intent.ToLower()).FirstOrDefault(); } else { intent = intentList.Where(f => (f.Intent.ToLower() == Intent.ToLower() && f.Entity.ToLower() == Entities[0].ToLower())).FirstOrDefault(); } if (intent != null) { //picks a specific one out of many utterances string rawUtterance = intent.GetUtterance(); this.RawUtterance = rawUtterance; //turning utterance nextstate string into the next state enum and saving it to the object State state; if (Enum.TryParse(intent.nextState, out state)) { this.previousState = this.nextState; this.nextState = state; } string suggestionedUtterance = rawUtterance; var potentialEntities = suggestionedUtterance.Split('{', '}'); foreach (var potentialEntity in potentialEntities) { var currentEntity = potentialEntity; if ((currentEntity.Length < 7) || (currentEntity == "")) { continue; } //TODO: Does not work, line: string strEntityIndex = currentEntity.Substring(7, 1); //check and replace utterance if (currentEntity.Substring(0, 7) == "ENTITY[") { string sourceString = "{" + currentEntity + "}"; string strEntityIndex = currentEntity.Substring(7, 1); int entityIndex = int.Parse(strEntityIndex); string replacementString; try { replacementString = Entities[entityIndex]; suggestionedUtterance = suggestionedUtterance.Replace(sourceString, replacementString); } catch (Exception) { this.Error = "ENTITY ERROR - Index of required Entity Not Found! " + sourceString; return; } } } this.suggestionedUtterance = suggestionedUtterance; } else { this.Error = "INTENT ERROR - Could not find the intent"; } }