Esempio n. 1
0
        public Conversation AnalyzeConversation(Conversation conversation)
        {
            var users = conversation.responses.Select(r => r.chat.user).Distinct().ToList();

            foreach (var response in conversation.responses)
            {
                if (string.IsNullOrWhiteSpace(response.chat.user))
                {
                    response.chat.user = "******";
                }
                if (string.IsNullOrWhiteSpace(response.chat.message))
                {
                    response.chat.message = " ";
                }
                response.naturalLanguageData = NaturalLanguageService.NaturalLanguageService.AnalyzeMessage(response.chat);
                response.naturalLanguageData.userlessMessage = userlessMessageService.GetMessageWithoutUsers(response.chat.message, users);
                response.naturalLanguageData.subjects        = responseSubjectService.GetSubjects(response);
            }

            conversation.groupChat = conversationTypeService.GetConversationGroupChatType(conversation.responses);

            for (var index = 0; index < conversation.responses.Count; index++)
            {
                conversation.responses[index].naturalLanguageData.responseConfidence = 0;

                if (conversation.responses.Count > index + 1)
                {
                    var nextResponse = conversation.responses[index + 1];
                    if (responseAnalyzationService.MessageHasUsableResponse(conversation.responses[index].chat, nextResponse.chat))
                    {
                        conversation.responses[index].naturalLanguageData.responseConfidence = responseAnalyzationService.getReplyConfidence(conversation.responses[index], nextResponse, UserDatabase.UserDatabase.userDatabase, conversation.groupChat);
                        conversation.responses[index].naturalLanguageData.responseSubjects   = nextResponse.naturalLanguageData.subjects;
                    }
                }

                conversation.responses[index].naturalLanguageData.proximitySubjects = conversationSubjectService.GetProximitySubjects(conversation, index);
            }

            conversation.subjects = conversationSubjectService.GetConversationSubjects(conversation.responses);

            conversation.readingLevel = conversationReadingLevelService.GetReadingLevel(conversation.responses);

            conversation.analyzationVersion = ConfigurationService.AnalyzationVersion;

            return(conversation);
        }
Esempio n. 2
0
        public Conversation AnalyzeConversationAsync(Conversation conversation)
        {
            var users = conversation.responses.Select(r => r.chat.user).Distinct().ToList();

            foreach (var response in conversation.responses)
            {
                if (string.IsNullOrWhiteSpace(response.chat.user))
                {
                    response.chat.user = "******";
                }
                if (string.IsNullOrWhiteSpace(response.chat.message))
                {
                    response.chat.message = " ";
                }
                if (response.naturalLanguageData == null || response.naturalLanguageData.AnalyzationVersion != ConfigurationService.AnalyzationVersion)
                {
                    response.naturalLanguageData = new NaturalLanguageData {
                        AnalyzationVersion = ConfigurationService.AnalyzationVersion
                    };

                    try
                    {
                        var result = Task.Run(async() => await _naturalLanguageApiService.AnalyzeMessageAsync(response.chat.message)).ConfigureAwait(false);
                        response.naturalLanguageData.sentences = result.GetAwaiter().GetResult();
                    }
                    catch (Exception)
                    {
                    }
                }

                response.naturalLanguageData.userlessMessage = _userlessMessageService.GetMessageWithoutUsers(response.chat.message, users);
                response.naturalLanguageData.subjects        = _responseSubjectService.GetSubjects(response);
            }

            conversation.groupChat = _conversationTypeService.GetConversationGroupChatType(conversation.responses);

            for (var index = 0; index < conversation.responses.Count; index++)
            {
                conversation.responses[index].naturalLanguageData.responseConfidence = 0;

                if (conversation.responses.Count > index + 1)
                {
                    var nextResponse = conversation.responses[index + 1];
                    if (_responseAnalyzationService.MessageHasUsableResponse(conversation.responses[index].chat, nextResponse.chat))
                    {
                        conversation.responses[index].naturalLanguageData.responseConfidence = _responseAnalyzationService.GetReplyConfidence(conversation.responses[index], nextResponse, UserDatabase.UserDatabase.userDatabase, conversation.groupChat);
                        conversation.responses[index].naturalLanguageData.responseSubjects   = nextResponse.naturalLanguageData.subjects;
                    }
                }

                conversation.responses[index].naturalLanguageData.proximitySubjects = _conversationSubjectService.GetProximitySubjects(conversation, index);
            }

            conversation.subjects = _conversationSubjectService.GetConversationSubjects(conversation.responses);

            conversation.readingLevel = _conversationReadingLevelService.GetReadingLevel(conversation.responses);

            conversation.analyzationVersion = ConfigurationService.AnalyzationVersion;

            return(conversation);
        }