public MatchChat GetBestMatch(Conversation targetConversation, List <ConversationList> conversationLists, List <string> subjectGoals, List <UserData> matchingUsers, List <UserData> usersMatchingBot) { var bestMatch = new MatchChat { matchConfidence = 0 }; var conversationMatchLists = _matchService.GetConversationMatchLists(targetConversation, conversationLists, subjectGoals); foreach (var conversationMatchList in conversationMatchLists) { foreach (var conversation in conversationMatchList.matchConversations) { for (var index = 0; index < conversation.responses.Count; index++) { if (conversation.responses[index].matchConfidence > bestMatch.matchConfidence && userMatch(conversation, index, matchingUsers) && userMatch(conversation, index + 1, usersMatchingBot) && index + 1 < conversation.responses.Count) { bestMatch.matchConfidence = conversation.responses[index].matchConfidence; bestMatch.analyzedChat = conversation.responses[index].analyzedChat; bestMatch.responseChat = _matchService.GetResponseChat(conversation.responses, index); } } } } return(bestMatch); }
public MatchChat GetBestMatch(Conversation targetConversation, List <ConversationList> conversationLists, List <string> subjectGoals) { var bestMatch = new MatchChat { matchConfidence = 0 }; var conversationMatchLists = _matchService.GetConversationMatchLists(targetConversation, conversationLists, subjectGoals); foreach (var conversationMatchList in conversationMatchLists) { foreach (var conversation in conversationMatchList.matchConversations) { for (var index = 0; index < conversation.responses.Count; index++) { if (conversation.responses[index].matchConfidence > bestMatch.matchConfidence && conversation.responses[index].analyzedChat.chat.reactions.Count > 0) { bestMatch.matchConfidence = conversation.responses[index].matchConfidence; bestMatch.analyzedChat = conversation.responses[index].analyzedChat; bestMatch.responseChat = getAnalyzedChatsFromReactions(conversation.responses[index].analyzedChat.chat.reactions); } } } } return(bestMatch); }
private MatchChat GetMatch(Conversation targetConversation, AnalyzedChat existingResponse, double subjectMatchConfidence, double readingLevelMatchConfidence, bool existingGroupChat, string userlessReply, List <string> pathSubjects) { //TODO: add user comparison and user similarity to the algorithm for confidence, if user has same property as bot, etc. var targetResponse = targetConversation.responses.Last(); var matchChat = new MatchChat { matchConfidence = 0, analyzedChat = existingResponse }; if (existingResponse.naturalLanguageData.responseConfidence == 0) { return(matchChat); } var uniqueConfidence = _uniqueConfidenceService.GetUniqueConfidence(userlessReply, targetConversation); var replyConfidence = existingResponse.naturalLanguageData.responseConfidence; var confidenceMultiplier = uniqueConfidence * replyConfidence; var replyMatchConfidence = _matchConfidenceService.GetMatchConfidence(targetResponse.naturalLanguageData, existingResponse.naturalLanguageData, targetResponse.botName); var replyPartScore = replyMatchConfidence * replyMatchRatio; //TODO: lower the value of replyMatchConfidence if it's a shorter reply like "yes" var conversationProximityScore = _subjectConfidenceService.GetConversationProximityMatchConfidence(targetResponse.naturalLanguageData.proximitySubjects, existingResponse.naturalLanguageData.proximitySubjects); var proximityPartScore = conversationProximityScore * conversationProximityRatio; var subjectMatchPartScore = subjectMatchConfidence * subjectMatchRatio; var readingLevelMatchPartScore = readingLevelMatchConfidence * readingLevelMatchRatio; var groupChatMatchConfidence = _groupChatConfidenceService.GetGroupChatConfidence(targetConversation.groupChat, existingGroupChat); var groupChatPartScore = groupChatMatchConfidence * groupChatRatio; var confidence = (replyPartScore + proximityPartScore + subjectMatchPartScore + readingLevelMatchPartScore + groupChatPartScore) * confidenceMultiplier; var length = 0; if (targetResponse.naturalLanguageData.sentences != null) { length = targetResponse.naturalLanguageData.sentences.SelectMany(s => s.Tokens).Count(); } if (length < 5) { var exponent = 6 - length; confidence = Math.Pow(confidence, exponent); } var bonusConfidence = getBonusConfidence(existingResponse, pathSubjects); confidence = confidence + bonusConfidence; matchChat.matchConfidence = confidence; return(matchChat); }
public List <string> GetResponse(MatchChat match) { var responses = new List <string>(); foreach (var matchChat in match.responseChat) { responses.Add(matchChat.chat.message); } return(responses); }
private string ConvertProperty(AnalyzedChat target, MatchChat match, AnalyzedChat matchChat, string chat, UserData userData) { var property = _userPropertyService.GetProperty(matchChat, match.analyzedChat); var botUserData = UserDatabase.UserDatabase.userDatabase.FirstOrDefault(u => u.userName == target.chat.botName); if (!string.IsNullOrEmpty(property.name)) { var botProperty = _propertyValueService.getPropertyByValue(property.name, userData); if (!string.IsNullOrEmpty(botProperty.value)) { chat.Replace(property.value, botProperty.value); } } return(chat); }
public List <string> ConvertResponse(AnalyzedChat target, MatchChat match) { var responses = new List <string>(); foreach (var matchChat in match.responseChat) { var chat = PaddedString(matchChat.chat.message); chat = chat.Replace("@" + match.analyzedChat.chat.user, "@" + target.chat.user); var originalUser = PaddedString(match.analyzedChat.chat.user); var user = PaddedString(target.chat.user); chat = chat.Replace(originalUser, user); var userData = UserDatabase.UserDatabase.userDatabase.FirstOrDefault(u => u.userName == target.chat.user); if (userData != null) { user = PaddedString(userData.nickNames.Last()); } var originalUserData = UserDatabase.UserDatabase.userDatabase.FirstOrDefault(u => u.userName == match.analyzedChat.chat.user); if (originalUserData != null) { foreach (var originalUserName in originalUserData.nickNames) { chat = chat.Replace(PaddedString(originalUserName), user); } } chat = ConvertProperty(target, match, matchChat, chat, userData); responses.Add(chat.Trim()); } return(responses); }