public string GetString(Random randomNumberGenerator, List <StringMemoryItem> queryMemoryItemList) { string outputString = ""; List <string> queryItems = new List <string>(); if (queryMemoryItemList != null) { foreach (StringMemoryItem queryMemoryItem in queryMemoryItemList) { string queryMemoryItemString = (string)queryMemoryItem.GetContent(); queryItems.Add(queryMemoryItemString); } } foreach (PatternItem patternItem in patternItemList) // Only the PositiveList is used when generating output { if (patternItem.PositiveList.Count > 0) // Should ALWAYS be the case, but just to be sure.. { if (patternItem.PositiveList[0][0] == queryStartCharacter) { string queryTagString = patternItem.PositiveList[0]; MemoryItem queryMemoryItem = queryMemoryItemList.Find(q => q.TagList.Contains(queryTagString)); outputString += queryMemoryItem.GetContent() + " "; } else { int numberOfOptions = patternItem.PositiveList.Count; int selectedIndex = randomNumberGenerator.Next(0, numberOfOptions); // Exclusive upper bound outputString += patternItem.PositiveList[selectedIndex] + " "; } } } outputString = outputString.TrimEnd(new char[] { ' ' }); return(outputString); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); string movieTitle = inputQueryTagList[0]; string movieRatingString = inputQueryTagList[1]; string currentUser = inputQueryTagList[2]; //TODO: get all in one call MemoryItem itemSought1 = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTagList[0]); if (itemSought1 != null) // 20171201 { movieTitle = (string)itemSought1.GetContent(); } MemoryItem itemSought2 = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTagList[1]); if (itemSought2 != null) // 20171201 { movieRatingString = (string)itemSought2.GetContent(); } double movieRating = Convert.ToDouble(movieRatingString); MemoryItem itemSought3 = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTagList[2]); if (itemSought3 != null) // 20171201 { currentUser = (string)itemSought3.GetContent(); } Boolean existingRating = false; foreach (var rating in _ultraManager.RatingList) { if (rating.UserName == currentUser) { if (rating.MovieTitle == movieTitle) { existingRating = true; rating.RatingValue = movieRating; } } } if (existingRating == false) { var rating = new Rating(movieTitle, currentUser, movieRating); _ultraManager.RatingList.Add(rating); } targetContext = outputAction.TargetContext; targetID = outputAction.TargetID; return(true); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { string currOrigin = ""; string currInterest = ""; base.Run(parameterList, out targetContext, out targetID); string outputString = outputAction.GetString(ownerAgent.RandomNumberGenerator, null); MemoryItem origSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_3); MemoryItem interestSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_4); if (origSought != null) { currOrigin = (string)origSought.GetContent(); } if (interestSought != null) { currInterest = (string)interestSought.GetContent(); } if (currOrigin != "") { string interest = "interest"; //puts <Q3> = currOrigin, <Q4> = currDestination, <Q5> = currTime ownerAgent.SendSpeechOutput(ItemHandler.PutTermsOnTaggedString(outputString, new List <string> { AgentConstants.QUERY_TAG_3, AgentConstants.QUERY_TAG_4 }, new List <string> { currOrigin, currInterest })); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_3, currOrigin); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_4, currInterest); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_5, interest); //signifies that this is an interestSearch } //If the user did not try to add a value, assume he wants to cancel else { ownerAgent.SendSpeechOutput("Okay then."); targetContext = denyContext; targetID = denyID; return(true); } targetContext = outputAction.TargetContext; targetID = outputAction.TargetID; return(true); }
public void SetMemoryItem(MemoryItem memoryItem) { this.memoryItem = memoryItem; InitializeRows(); this.Rows[0].Cells[0].Value = memoryItem.TagListAsString(); this.Rows[1].Cells[0].Value = memoryItem.InsertionTime.ToString(); string memoryValueString = "<Not displayable>"; if (memoryItem is StringMemoryItem) { memoryValueString = (string)memoryItem.GetContent(); } this.Rows[2].Cells[0].Value = memoryValueString; }
/* public override void Initialize(Agent ownerAgent) // TODO use patter list * { * base.Initialize(ownerAgent); * //foreach (Pattern pattern in outputAction.PatternList) * //{ * // pattern.ProcessDefinition(); * // // pattern.ProcessDefinitionList(); * //} * }*/ public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); string queryTag = inputQueryTagList[0]; //TODO maybe not needed or change GetLastStringByTag string currentUser = ""; MemoryItem itemSought = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTagList[0]); if (itemSought != null) // 20171201 { currentUser = (string)itemSought.GetContent(); } // TODO // If no currentUser in WorkingMemory --> set currentUser, else change currentUser // Check if user already exists Boolean existingUser = false; foreach (var user in _ultraManager.UserList) { if (user.Name == currentUser) { existingUser = true; } } if (existingUser) { //TODO: trigger rating dialogue targetContext = existingUserTargetContext; targetID = existingUserTargetID; //greetingString = greetingString + "Welcome back " + currentUser; } else { var user = new User(currentUser, false, ""); _ultraManager.UserList.Add(user); targetContext = newUserTargetContext; targetID = newUserTargetID; //greetingString = greetingString + "Hello " + currentUser + " it seems you are new"; } return(true); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); string queryTag = inputQueryTagList[0]; //TODO maybe not needed or change GetLastStringByTag string movieTitle = ""; string movieInformationString = ""; MemoryItem itemSought = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTagList[0]); if (itemSought != null) // 20171201 { movieTitle = (string)itemSought.GetContent(); } var _ultraManager = UltraManager.Instance; Boolean existingMovie = false; foreach (var movie in _ultraManager.MovieList) { if (movie.Title.ToLower() == movieTitle) { existingMovie = true; movieInformationString = movie.Title + " is a " + movie.Genre + " from " + movie.Year + " that has a imdb rating of " + movie.ImdbRating; } } if (existingMovie) { ownerAgent.SendSpeechOutput(movieInformationString); targetContext = successTargetContext; targetID = successTargetID; } else { targetContext = failureTargetContext; targetID = failureTargetID; } return(true); }
protected override void RunLoop(List <object> parameterList) { //pops out the remaining items MemoryItem origSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_3); MemoryItem destSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_4); string originalContext = ownerAgent.WorkingMemory.CurrentContext; int totalWaitingTime = 0; bool hasExpired = false; ownerAgent.SendExpression("squint"); //tells the agent to really think string nextID = OutputAction.TargetID; while (!(mapControl.LoadState == MapControl.LOADSTATE.DestinationComplete || mapControl.LoadState == MapControl.LOADSTATE.LocationComplete) && !hasExpired) { totalWaitingTime += step; hasExpired = totalWaitingTime >= millisecondMaxWaitingTime; System.Threading.Thread.Sleep(step); } if (hasExpired) { ownerAgent.SendSpeechOutput("Failed to search for the trip"); } else if ((mapControl.LoadState == MapControl.LOADSTATE.DestinationComplete) && !hasExpired && mapControl.DepartureTimeListBox.Items.Count > 0) { ownerAgent.SendSpeechOutput("I found your trip, the transport departs from " + mapControl.Departure + " at " + mapControl.DepartureTimeListBox.Items[0] + " o' clock"); ownerAgent.SendExpression("nodhead"); if (origSought != null && destSought != null) { string orig = origSought.GetContent().ToString(); string dest = destSought.GetContent().ToString(); //tries to remember the gathered position ItemHandler.StoreShortcut(ownerAgent, orig, mapControl.Departure, false); ItemHandler.StoreShortcut(ownerAgent, dest, mapControl.Arrival, false); } } else if (((mapControl.LoadState == MapControl.LOADSTATE.LocationComplete))) { ownerAgent.SendExpression("nodhead"); if (mapControl.LocationsOfInterest.Count > 0) { ownerAgent.SendSpeechOutput("I found " + mapControl.AddressesOfInterest.Count + " locations nearby, " + mapControl.LocationsOfInterest[0] + " is closest. Do you want to go?"); nextID = interestID; ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_3, origSought.GetContent().ToString()); } else { ownerAgent.SendSpeechOutput("I could not find any " + destSought.GetContent().ToString() + " places near you."); } } else { ownerAgent.SendExpression("shakehead"); ownerAgent.SendSpeechOutput("Uh oh. Something went wrong."); } AsynchronousDialogueItemEventArgs e = new AsynchronousDialogueItemEventArgs(originalContext, outputAction.TargetContext, nextID); OnRunCompleted(e); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); Boolean labelFound = false; List <string> itemSoughtStringList = new List <string>(); foreach (string inputQueryTag in inputQueryTagList) { MemoryItem itemSought = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTag); if (itemSought != null) // 20171201 { string itemSoughtString = (string)itemSought.GetContent(); itemSoughtStringList.Add(itemSoughtString); } } List <MemoryItem> tagMatchingItemList = null; if (memoryIdentifier == AgentConstants.LONG_TERM_MEMORY_NAME) { tagMatchingItemList = ownerAgent.LongTermMemory.GetAllItemsByTagList(searchTagList, tagSearchMode); } else { tagMatchingItemList = ownerAgent.WorkingMemory.GetAllItemsByTagList(searchTagList, tagSearchMode); } if (tagMatchingItemList != null) { foreach (MemoryItem memoryItem in tagMatchingItemList) { if (memoryItem is StringMemoryItem) // The only case covered, so far. { StringMemoryItem stringMemoryItem = (StringMemoryItem)memoryItem; stringMemoryItem.GenerateLabelContentPairs(); LabelContentPair labelContentPair = null; labelContentPair = stringMemoryItem.LabelContentPairList.Find(lcp => (lcp.Label == identificationLabel)); // && (lcp.Content.ToLower() == itemSoughtString)); if (labelContentPair != null) // 20171201 { foreach (string itemSoughtString in itemSoughtStringList) { if (!labelContentPair.Content.ToLower().Contains(itemSoughtString)) { labelContentPair = null; break; } } } if (labelContentPair != null) { // A match was found. Now check if the searchLabel can be found as well: LabelContentPair searchLabelContentPair = stringMemoryItem.LabelContentPairList.Find(lcp => lcp.Label == searchLabel); if (searchLabelContentPair != null) { labelFound = true; StringMemoryItem matchMemoryItem = new StringMemoryItem(); matchMemoryItem.TagList = new List <string>() { outputQueryTag }; matchMemoryItem.SetContent(searchLabelContentPair.Content); ownerAgent.WorkingMemory.AddItem(matchMemoryItem); break; } } } } } if (labelFound) { targetContext = successTargetContext; // ToDo - uncomment and use! targetID = successTargetID; // ToDo - uncomment and use! } else { targetContext = failureTargetContext; targetID = failureTargetID; } return(labelFound); }
private void HandleUserInput(MemoryItem inputItem) { busy = true; dialogueItemTimer.Stop(); // In case the time was running, make sure that it is stopped here, to avoid repeating the agent's previous statement. string inputString = (string)inputItem.GetContent(); string sourceTag = inputItem.TagList[0]; // Note: input items have precisely one tag; see HandleServerReceived(). List <object> parameterList = new List <object>() { inputString, sourceTag }; string targetContext = workingMemory.CurrentContext; string targetID = workingMemory.CurrentID; DialogueItem currentDialogueItem = FindCurrentDialogueItem(); Boolean itemProcessed = false; if (currentDialogueItem != null) { if (currentDialogueItem is InputItem) // OK with type comparison here (InputItem is the only possibility). { Boolean allowVisionInput = ((InputItem)currentDialogueItem).AllowVisionInput; if ((sourceTag == AgentConstants.LISTENER_INPUT_TAG) || ((sourceTag == AgentConstants.VISION_INPUT_TAG) && allowVisionInput)) { // Run the timeout timer only for those items that have the corresponding property: itemProcessed = currentDialogueItem.Run(parameterList, out targetContext, out targetID); if (itemProcessed) { busy = false; if (targetContext != workingMemory.CurrentContext) { workingMemory.CurrentContext = targetContext; } // Triggers the ContextChangedEvent in working memory else { workingMemory.CurrentID = targetID; } // Triggers the IDChangedEvent in working memory return; } } } } if (!itemProcessed) // No dialogue item found OR no dialogue matching the context found { List <Dialogue> alwaysAvailableDialogueList = GetAlwaysAvailableDialogues(); foreach (Dialogue dialogue in alwaysAvailableDialogueList) { DialogueItem dialogueItem = dialogue.DialogueItemList[0]; if (dialogueItem is InputItem) // Should be the case, but just to be sure: { Boolean allowVisionInput = ((InputItem)dialogueItem).AllowVisionInput; if ((sourceTag == AgentConstants.LISTENER_INPUT_TAG) || ((sourceTag == AgentConstants.VISION_INPUT_TAG) && allowVisionInput)) { itemProcessed = dialogueItem.Run(parameterList, out targetContext, out targetID); if (itemProcessed) { workingMemory.CurrentContext = dialogue.Context; // Set the context here. busy = false; if (targetContext != workingMemory.CurrentContext) { workingMemory.CurrentContext = targetContext; } // Triggers the ContextChangedEvent in working memory else { workingMemory.CurrentID = targetID; } // Triggers the IDChangedEvent in working memory return; } } } } } // In case no match has been found, either for the current dialogue or for any of the always available dialogues: // if the dialogue item has a customized error phrase, use it. Otherwise, use one of the default error phrases if (sourceTag == AgentConstants.VISION_INPUT_TAG) // Do not trigger errors based on vision input { busy = false; return; } else // Listener input { string failureResponsePhrase = GetFailureResponsePhrase(); if (currentDialogueItem != null) { if (currentDialogueItem is InputItem) // A bit ugly with a typecast, but OK... { InputItem currentInputItem = (InputItem)currentDialogueItem; if (currentInputItem.FailureResponsePatternList != null) { if (currentInputItem.FailureResponsePatternList.Count > 0) { failureResponsePhrase = currentInputItem.GetFailureResponsePhrase(randomNumberGenerator); } } } } SendSpeechOutput(failureResponsePhrase); busy = false; // to be removed here (see above). } }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { repetitionCount++; // These values are set in the derived classes, but must be initialized here, due to the "out" keyword. targetContext = ""; targetID = ""; base.Run(parameterList, out targetContext, out targetID); MemoryItem origSought = ItemHandler.PeekItem(ownerAgent, AgentConstants.QUERY_TAG_3); MemoryItem destSought = ItemHandler.PeekItem(ownerAgent, AgentConstants.QUERY_TAG_4); if (repetitionCount > MaximumRepetitionCount) // Giving up after repeated incomprehensible inputs: Leave the dialogue { targetContext = FinalFailureTargetContext; targetID = FinalFailureTargetID; if (doReset) { repetitionCount = 0; } return(true); } else { string inputString = (string)parameterList[0]; string tag = (string)parameterList[1]; // see Agent.HandleInput() Pattern matchingPattern = null; targetContext = context; //Boolean isMatching = inputYesAction.CheckMatch(inputString, tag, out matchingPattern); if (inputYesAction.CheckMatch(inputString, tag, out matchingPattern)) { ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_4); if (origSought != null) { string currDestination = mapControl.AddressesOfInterest[mapControl.InterestPointer]; ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_3, origSought.GetContent().ToString()); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_4, currDestination); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_5, ""); targetID = inputYesAction.TargetID; targetContext = inputYesAction.TargetContext; } } else if (inputNoAction.CheckMatch(inputString, tag, out matchingPattern)) { ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_3); ownerAgent.SendSpeechOutput("Oh ok."); targetID = inputNoAction.TargetID; targetContext = inputNoAction.TargetContext; } else if (inputBackAction.CheckMatch(inputString, tag, out matchingPattern)) { mapControl.InterestPointer = mapControl.InterestPointer - 1; if (mapControl.InterestPointer < 0) { mapControl.InterestPointer = 0; ownerAgent.SendSpeechOutput("you can't go back anymore."); targetID = id; targetContext = context; } else { targetID = inputBackAction.TargetID; targetContext = inputBackAction.TargetContext; ownerAgent.SendSpeechOutput("The previous item is " + mapControl.LocationsOfInterest[mapControl.InterestPointer] + ". Do you want this one?"); } } else if (inputNextAction.CheckMatch(inputString, tag, out matchingPattern)) { mapControl.InterestPointer = mapControl.InterestPointer + 1; if (mapControl.InterestPointer > mapControl.AddressesOfInterest.Count) { ownerAgent.SendSpeechOutput("you can't go forward anymore."); targetID = id; targetContext = context; } else { ownerAgent.SendSpeechOutput("The next one is " + mapControl.LocationsOfInterest[mapControl.InterestPointer] + ". Do you want this one?"); targetID = inputNextAction.TargetID; targetContext = inputNextAction.TargetContext; } } } if (targetID != id) { ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_3); } return(true); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); string currOrigin = ""; string currDestination = ""; string currTimeOrInterest = ""; //Sets the query items at the right object MemoryItem origSought = ItemHandler.PeekItem(ownerAgent, AgentConstants.QUERY_TAG_3); MemoryItem destSought = ItemHandler.PeekItem(ownerAgent, AgentConstants.QUERY_TAG_4); MemoryItem timeSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_5); if (timeSought != null) { currTimeOrInterest = (string)timeSought.GetContent(); } if (origSought != null && currOrigin == "") { currOrigin = (string)origSought.GetContent(); } if (destSought != null && currDestination == "") { currDestination = (string)destSought.GetContent(); } bool isTime = int.TryParse(currTimeOrInterest, out int time); isTime = (isTime && time.ToString().Length == 4); if (currOrigin != "" && (isTime || currTimeOrInterest == "")) { currDestination = ItemHandler.TryGetShortcutAddress(currDestination); currOrigin = ItemHandler.TryGetShortcutAddress(currOrigin); ownerAgent.SendSpeechOutput("Searching from " + currOrigin + " to " + currDestination + ((isTime) ? (" at " + time / 100 + ":" + time % 100) : "")); // "at mmss only when its given mapControl.NavigateDestination(currDestination, currOrigin, currTimeOrInterest); } if (currTimeOrInterest == "interest") { currOrigin = ItemHandler.TryGetShortcutAddress(currOrigin); ownerAgent.SendSpeechOutput("finding out!"); // "at mmss only when its given mapControl.NavigateLocations(currDestination, currOrigin); } if (isTime || currTimeOrInterest == "") { targetContext = outputAction.TargetContext; targetID = travelID; } else { targetContext = outputAction.TargetContext; targetID = interestID; } return(true); }
/* public override void Initialize(Agent ownerAgent) // TODO use pattern list * { * base.Initialize(ownerAgent); * //foreach (Pattern pattern in outputAction.PatternList) * //{ * // pattern.ProcessDefinition(); * // // pattern.ProcessDefinitionList(); * //} * }*/ public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); string currentUser = ""; MemoryItem itemSought = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTagList[0]); if (itemSought != null) // 20171201 { currentUser = (string)itemSought.GetContent(); } List <string> openRatings = new List <string> { }; foreach (var movie in _ultraManager.MovieList) { Boolean addItem = true; //movie.Title == foreach (var rating in _ultraManager.RatingList) { if (rating.UserName == currentUser && rating.MovieTitle == movie.Title) { addItem = false; } } if (addItem) { openRatings.Add(movie.Title); } } // return random unseen movie to rate as outputQueryTag Boolean noMoreRatngs = false; if (openRatings.Count > 0) { // Random random = new Random(); // int randomIndex = random.Next(0, openRatings.Count); int randomIndex = ownerAgent.RandomNumberGenerator.Next(0, openRatings.Count); string openRating = openRatings[randomIndex]; StringMemoryItem rateMemoryItem = new StringMemoryItem(); rateMemoryItem.TagList = new List <string>() { outputQueryTag }; rateMemoryItem.SetContent(openRating); ownerAgent.WorkingMemory.AddItem(rateMemoryItem); } else { noMoreRatngs = true; } if (repetitionCount < maximumRepetitionCount && noMoreRatngs == false) { targetContext = successTargetContext; targetID = successTargetID; } else { targetContext = failureTargetContext; targetID = failureTargetID; } return(true); }
protected override void RunLoop(List <object> parameterList) { string originalContext = ownerAgent.WorkingMemory.CurrentContext; string currentUser = ""; MemoryItem itemSought = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTagList[0]); if (itemSought != null) // 20171201 { currentUser = (string)itemSought.GetContent(); } // Recommend! // Get similarity of currentUser to all other users------------------------------------------------- // create ratingTable List <string> userList = new List <string> { }; List <string> movieList = new List <string> { }; userList.Add(currentUser); foreach (var rating in _ultraManager.RatingList) { if (!userList.Exists(x => string.Equals(x, rating.UserName, StringComparison.OrdinalIgnoreCase))) { userList.Add(rating.UserName); } } foreach (var rating in _ultraManager.RatingList) { if (!movieList.Exists(x => string.Equals(x, rating.MovieTitle, StringComparison.OrdinalIgnoreCase))) { movieList.Add(rating.MovieTitle); } } int nbrOfUsers = userList.Count; int userInsertionIndex = 0; int nbrOfMovies = movieList.Count; int movieInsertionIndex = 0; double[,] ratingTable = new double[nbrOfUsers, nbrOfMovies]; foreach (var rating in _ultraManager.RatingList) { userInsertionIndex = userList.FindIndex(x => x.StartsWith(rating.UserName)); movieInsertionIndex = movieList.FindIndex(x => x.StartsWith(rating.MovieTitle)); ratingTable[userInsertionIndex, movieInsertionIndex] = rating.RatingValue; } // calculate mean rating for each user double[] meanRatings = new double[nbrOfUsers]; for (int i = 0; i < nbrOfUsers; ++i) { double ratingSum = 0; int nbrOfRated = 0; for (int j = 0; j < nbrOfMovies; ++j) { if (ratingTable[i, j] > 0) { ratingSum = ratingSum + ratingTable[i, j]; ++nbrOfRated; } } if (ratingSum > 0 && nbrOfRated > 0) { meanRatings[i] = ratingSum / nbrOfRated; } } // calculate Pearson correlation List <double> simToUser = new List <double> { 0 }; // TODO: use dictionary for (int i = 1; i < nbrOfUsers; ++i) { List <int> setRatedBoth = new List <int> { }; for (int j = 0; j < nbrOfMovies; ++j) { if (ratingTable[0, j] > 0 && ratingTable[i, j] > 0) { setRatedBoth.Add(j); } } double sum1 = 0; double sum2 = 0; double sum3 = 0; for (int k = 0; k < setRatedBoth.Count; ++k) { sum1 = sum1 + (ratingTable[0, setRatedBoth[k]] - meanRatings[0]) * (ratingTable[i, setRatedBoth[k]] - meanRatings[i]); sum2 = sum2 + Math.Pow(ratingTable[0, setRatedBoth[k]] - meanRatings[0], 2); sum3 = sum3 + Math.Pow(ratingTable[i, setRatedBoth[k]] - meanRatings[i], 2); } simToUser.Add(sum1 / (Math.Sqrt(sum2 * sum3))); } // Get most similar user int mostSimilarUser = simToUser.IndexOf(simToUser.Max()); Debug.WriteLine(userList[mostSimilarUser]); // Return random unseen movie List <string> unseenMovies = new List <string> { }; for (int j = 0; j < nbrOfMovies; ++j) { if (ratingTable[0, j] == 0 && ratingTable[mostSimilarUser, j] > 5) { unseenMovies.Add(movieList[j]); } } Boolean noMoreRecommendations = false; if (unseenMovies.Count > 0) { int randomIndex = ownerAgent.RandomNumberGenerator.Next(0, unseenMovies.Count); string recommendation = unseenMovies[randomIndex]; StringMemoryItem rateMemoryItem = new StringMemoryItem(); rateMemoryItem.TagList = new List <string>() { outputQueryTag }; rateMemoryItem.SetContent(recommendation); ownerAgent.WorkingMemory.AddItem(rateMemoryItem); } else { noMoreRecommendations = true; } AsynchronousDialogueItemEventArgs e = new AsynchronousDialogueItemEventArgs(originalContext, outputAction.TargetContext, outputAction.TargetID); OnRunCompleted(e); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); List <double> operandList = new List <double>(); foreach (string inputQueryTag in inputQueryTagList) { MemoryItem itemSought = ownerAgent.WorkingMemory.GetLastItemByTag(inputQueryTag); string itemSoughtString = (string)itemSought.GetContent(); double operand; Boolean inputOK = double.TryParse(itemSoughtString, out operand); if (inputOK) { operandList.Add(operand); } else { return(false); } } double output = 0; if (operation.ToLower() == "addition") { output = 0; foreach (double operand in operandList) { output += operand; } } else if (operation.ToLower() == "subtraction") { if (operandList.Count == 2) { output = operandList[0] - operandList[1]; } else { return(false); } } else if (operation.ToLower() == "multiplication") { output = 1; foreach (double operand in operandList) { output *= operand; } } else { return(false); } StringMemoryItem matchMemoryItem = new StringMemoryItem(); matchMemoryItem.TagList = new List <string>() { outputQueryTag }; matchMemoryItem.SetContent(output.ToString()); ownerAgent.WorkingMemory.AddItem(matchMemoryItem); targetContext = outputTargetContext; targetID = outputTargetID; return(true); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { Boolean gotWrongRequest = false; Boolean gotNewInput = false; string currOrigin = ""; string currDestination = ""; string currTime = ""; base.Run(parameterList, out targetContext, out targetID); string prefixString = outputAction.GetString(ownerAgent.RandomNumberGenerator, null); MemoryItem norigSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_1); MemoryItem ndestSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_2); MemoryItem origSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_3); MemoryItem destSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_4); MemoryItem timeSought = ItemHandler.PopItem(ownerAgent, AgentConstants.QUERY_TAG_5); if (timeSought != null) { currTime = (string)norigSought.GetContent(); } if (norigSought != null) { currOrigin = (string)norigSought.GetContent(); gotNewInput = gotNewInput || (currOrigin != ""); } if (ndestSought != null) { currDestination = (string)ndestSought.GetContent(); gotNewInput = gotNewInput || (currDestination != ""); } if (origSought != null && currOrigin == "") { currOrigin = (string)origSought.GetContent(); gotWrongRequest = gotWrongRequest || (currOrigin == ""); } if (destSought != null && currDestination == "") { currDestination = (string)destSought.GetContent(); gotWrongRequest = gotWrongRequest || (currDestination == ""); } /* * //clears all queries * StringMemoryItem matchMemoryClean = new StringMemoryItem(); * matchMemoryClean.TagList = speechQueries; * matchMemoryClean.SetContent(""); * ownerAgent.WorkingMemory.AddItem(matchMemoryClean); */ //if the user tried to add something, put items back on stack if (gotNewInput) { //puts <Q3> = currOrigin, <Q4> = currDestination, <Q5> = currTime ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_3, currOrigin); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_4, currDestination); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_5, currTime); } //If the user did not try to add a value, assume he wants to cancel else { ownerAgent.SendSpeechOutput("Okay then."); targetContext = denyContext; targetID = denyID; return(true); } //User tried to give already given information if (gotWrongRequest) { bool originMissing = (currOrigin == ""); ownerAgent.SendSpeechOutput("I already got your " + (!originMissing ? "origin" : "destination") + " please tell me your " + (originMissing ? "origin." : "destination.")); targetContext = outputAction.TargetContext; targetID = failID; return(true); } targetContext = outputAction.TargetContext; targetID = outputAction.TargetID; return(true); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); string address = "", shortcut = ""; MemoryItem addressMemory = ItemHandler.PopItem(ownerAgent, addressQuery); MemoryItem shortcutMemory = ItemHandler.PopItem(ownerAgent, shortcutQuery); if (addressMemory != null) { address = addressMemory.GetContent().ToString(); } if (shortcutMemory != null) { shortcut = shortcutMemory.GetContent().ToString(); } if (ItemHandler.ShortcutArray.Contains(address)) { ownerAgent.SendSpeechOutput("Please only set addresses as shortcuts, you tried to put the shortcut < " + address + " > as a shortcut."); targetID = failureID; targetContext = failureContext; } else { if (ItemHandler.ShortcutArray.Contains(shortcut)) { string oldAddress = ItemHandler.TryGetShortcutAddress(shortcut); bool storedReplaced = ItemHandler.StoreShortcut(ownerAgent, shortcut, address, true); if (!storedReplaced) { ownerAgent.SendSpeechOutput(shortcut + " " + " will now behave as when you say " + address); } else { ownerAgent.SendSpeechOutput(shortcut + " replaced the old address " + oldAddress + ", and will now act as you say " + address + " instead."); } targetID = outputAction.TargetID; } else if (ItemHandler.TravelAddressesArray.Contains(shortcut)) { ownerAgent.SendSpeechOutput(" < " + shortcut + " > is an address and not a shortcut."); targetContext = failureContext; targetID = failureID; } else { ownerAgent.SendSpeechOutput("Uh oh. Something went wrong when you tried to set " + address + " as address and " + shortcut + "as shortcut."); } } /* used if strictness iss neccessary strictness * else * { * ownerAgent.SendSpeechOutput(address + " is not an address. You can only create shortcuts of an address."); * targetID = failureID; * } */ targetContext = outputAction.TargetContext; return(true); }
public override Boolean Run(List <object> parameterList, out string targetContext, out string targetID) { base.Run(parameterList, out targetContext, out targetID); string prefixString = outputAction.GetString(ownerAgent.RandomNumberGenerator, null); //The one outputaction pattern string travelDialogue = ""; string prevString = ""; string travelInfo = ""; string currOrigin = ""; string currDestination = ""; string currTime = ""; foreach (string query in speechQueries) { MemoryItem itemSought = ItemHandler.PopItem(ownerAgent, query); if (itemSought == null) { prevString = ""; continue; } string itemSoughtString = (string)itemSought.GetContent(); Console.WriteLine(itemSought.ToString() + " " + itemSought.GetContent()); if (itemSoughtString == "") { prevString = ""; continue; } if (prevString == "to") { currDestination = itemSoughtString; travelInfo += ItemHandler.SEP + ItemHandler.DESTINATION + currDestination; } else if (prevString == "from") { currOrigin = itemSoughtString; travelInfo += ItemHandler.SEP + ItemHandler.ORIGIN + currOrigin; } else if (prevString == "at") { currTime = itemSoughtString; travelInfo += ItemHandler.SEP + ItemHandler.TIME + currTime; } travelDialogue += " " + itemSoughtString; prevString = itemSoughtString; } /* * //clears all queries * StringMemoryItem matchMemoryClean = new StringMemoryItem(); * matchMemoryClean.TagList = speechQueries; * matchMemoryClean.SetContent(""); * ownerAgent.WorkingMemory.AddItem(matchMemoryClean); */ //puts <Q3> = currOrigin, <Q4> = currDestination, <Q5> = currTime ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_3, currOrigin); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_4, currDestination); ItemHandler.StoreTermOnTag(ownerAgent, AgentConstants.QUERY_TAG_5, currTime); Console.WriteLine(currDestination + " " + currOrigin + " " + currTime); if (currOrigin != "" && currDestination != "") { ownerAgent.SendExpression("squinteyes"); //ownerAgent.SendSpeechOutput(prefixString + travelDialogue); //mapControl.NavigateDestination(currDestination, currOrigin, currTime); targetID = outputAction.TargetID; } else if (currOrigin == "" && currDestination == "") { ownerAgent.SendExpression("shakehead"); ownerAgent.SendSpeechOutput("I'm sorry I could not make out your origin or destination."); targetContext = ""; targetID = ""; return(false); } else { string missingLocation = ""; if (currOrigin != "") { missingLocation = "destination"; } else { missingLocation = "origin"; } ownerAgent.SendSpeechOutput(partialFailurePrefix[random.Next(partialFailurePrefix.Length - 1)] + missingLocation); targetID = partialFailureID; } //(TRAVEL_MARK + travelInfo); Console.WriteLine(travelInfo); targetContext = outputAction.TargetContext; return(true); }