コード例 #1
0
 public static ToneAnalysisResultDADto ToToneAnalysisResultDADto(this ToneAnalysisResultBLDto BLLResult)
 {
     return(new ToneAnalysisResultDADto
     {
         UserId = BLLResult.UserID,
         Date = BLLResult.Date,
         Text = BLLResult.Text,
         DetectedEmotions = ToDALDetectedEmotions(BLLResult.DetectedEmotions),
         PrevailingEmotion = BLLResult.PrevailingEmotion
     });
 }
コード例 #2
0
        public ToneAnalysisResultBLDto AnalyzeTextTone(int userId, string textForToneAnalysis)
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "");
            var service = new ToneAnalyzerService("", authenticator);

            service.SetServiceUrl("");
            ToneInput toneInput = new ToneInput()
            {
                Text = textForToneAnalysis
            };
            var result = service.Tone(
                toneInput: toneInput
                );
            WatsonResponseBLDto     watsonResponse = JsonConvert.DeserializeObject <WatsonResponseBLDto>(result.Response);
            ToneAnalysisResultBLDto analysisResult = new ToneAnalysisResultBLDto {
                UserID           = userId,
                Date             = DateTime.Now,
                Text             = textForToneAnalysis,
                DetectedEmotions = watsonResponse.document_tone.tones
            };
            double emotionScore      = 0;
            string prevailingEmotion = "";

            foreach (var emotion in analysisResult.DetectedEmotions)
            {
                if (emotion.score > emotionScore)
                {
                    emotionScore      = emotion.score;
                    prevailingEmotion = emotion.tone_name;
                }
            }
            foreach (KeyValuePair <string, List <string> > emotionType in GetListOfEmotions())
            {
                if (emotionType.Value.Contains(prevailingEmotion))
                {
                    analysisResult.PrevailingEmotion = emotionType.Key;
                }
            }
            if (analysisResult.PrevailingEmotion == null)
            {
                analysisResult.PrevailingEmotion = "OtherEmotion";
            }
            return(analysisResult);
        }
コード例 #3
0
        public List <ToneAnalysisRecordBLDto> GetAllAnalysisResults(int userId, string textForToneAnalysis)
        {
            ToneAnalysisResultBLDto emotionsDetected = AnalyzeTextTone(userId, textForToneAnalysis);

            return(Utils.Utilities.MapToneAnalysisRecordsDADtoToBLDto(striveDataRepository.GetAllAnalysisResults(userId, Utils.Utilities.MapToneAnalysisResultBLDtoToDADto(emotionsDetected))));
        }
コード例 #4
0
 public static ToneAnalysisResultDADto MapToneAnalysisResultBLDtoToDADto(ToneAnalysisResultBLDto toneAnalysisResult)
 {
     return(toneAnalysisResult.ToToneAnalysisResultDADto());
 }