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 }); }
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); }
public List <ToneAnalysisRecordBLDto> GetAllAnalysisResults(int userId, string textForToneAnalysis) { ToneAnalysisResultBLDto emotionsDetected = AnalyzeTextTone(userId, textForToneAnalysis); return(Utils.Utilities.MapToneAnalysisRecordsDADtoToBLDto(striveDataRepository.GetAllAnalysisResults(userId, Utils.Utilities.MapToneAnalysisResultBLDtoToDADto(emotionsDetected)))); }
public static ToneAnalysisResultDADto MapToneAnalysisResultBLDtoToDADto(ToneAnalysisResultBLDto toneAnalysisResult) { return(toneAnalysisResult.ToToneAnalysisResultDADto()); }