Esempio n. 1
0
        public ChatResponse GetResponse(Conversation analyzedConversation, List <string> excludedTypes, List <string> subjectGoals)
        {
            if (analyzedConversation.responses.Count == 0)
            {
                return(new ChatResponse()
                {
                    confidence = 0, response = new List <string>()
                });
            }

            var conversationChatResponse = conversationMatchService.GetConversationMatch(analyzedConversation, excludedTypes, subjectGoals);

            var userPropertyChatResponse = userPropertyMatchService.GetUserPropertyMatch(analyzedConversation);

            var lyricsChatResponse = lyricsService.GetLyricsMatch(analyzedConversation);

            //TODO: media comment match
            //if it's a youtube video look up comments on the video and use one, soundcloud comments, reddit post comments, if it's a tweet look up replies to the tweet, etc.

            var googleChatResponse = googleService.GetGoogleMatch(analyzedConversation);

            var urbanDictionaryChatResponse = urbanDictionaryService.GetUrbanDictionaryMatch(analyzedConversation);

            //TODO: run all matches simultaneously then decide which one to use, set a maximum time to wait for each one, ignore it if it takes too long

            var matchChat = conversationChatResponse;

            if (userPropertyChatResponse.confidence > conversationChatResponse.matchConfidence) //TODO: check the uniqueness of reply (if it was already used)
            {
                userPropertyChatResponse.response = salutationService.GetProperlyAddressedResponse(analyzedConversation, userPropertyChatResponse.response);
                return(userPropertyChatResponse);
            }

            if (conversationChatResponse.matchConfidence < googleThreshold && googleChatResponse.confidence > conversationChatResponse.matchConfidence)
            {
                googleChatResponse.response = salutationService.GetProperlyAddressedResponse(analyzedConversation, googleChatResponse.response);
                return(googleChatResponse);
            }
            if (conversationChatResponse.matchConfidence < urbanDictionaryThreshold && urbanDictionaryChatResponse.confidence > conversationChatResponse.matchConfidence)
            {
                urbanDictionaryChatResponse.response = salutationService.GetProperlyAddressedResponse(analyzedConversation, urbanDictionaryChatResponse.response);
                return(urbanDictionaryChatResponse);
            }

            if (matchChat.responseChat == null)
            {
                return(new ChatResponse {
                    confidence = 0, response = new List <string>()
                });
            }

            var response = responseConversionService.ConvertResponse(analyzedConversation.responses.Last(), matchChat);

            //TODO: alter reply to match sophistication

            var chatResponse = new ChatResponse
            {
                confidence = matchChat.matchConfidence,
                response   = salutationService.GetProperlyAddressedResponse(analyzedConversation, response)
            };

            return(chatResponse);
        }