/// <summary> /// Asyncronous method that validate the user parameters and call <c>ApiClient</c> /// </summary> /// <param name="parameters"></param> /// <returns>Returns a <c>SentimentAnalysisDto</c> populated with the result of the call </returns> /// <seealso cref="SentimentAnalysisDto"/> public Task <SentimentAnalysisDto> CallSentimentAnalysisAsync(SentimentAnalysisParameters parameters) { ServiceUtils.ParameterValidation(parameters); if (parameters.Lang != LanguageOption.en && parameters.Lang != LanguageOption.it && parameters.Lang != LanguageOption.auto) { throw new ArgumentException(ErrorMessages.WrongLang1, ErrorMessages.Lang); } var source = SourceValidationService.verifySingleSource(parameters); return(_apiClient.CallApiAsync <SentimentAnalysisDto>(ApiClient.SentimentAnalysisUriBuilder(), ApiClient.SentimentAnalysisContentBuilder(source, parameters), parameters.HttpMethod)); }
public async void Should_ThrowException_When_CallSentimentAnalysisWithWrongParameters(SentimentAnalysisParameters parameters, string message, string wrongParameter) { //Act & Assert ArgumentException ex = await Assert.ThrowsAsync <ArgumentException>(() => _sentimentAnalysisService.CallSentimentAnalysisAsync(parameters)); if (String.IsNullOrEmpty(wrongParameter)) { Assert.Equal(message, ex.Message); } else { Assert.Equal($"{message}{Environment.NewLine}Parameter name: {wrongParameter}", ex.Message); } }
/// <summary> /// Allocates a dictionary that contains the parameters for the call /// </summary> /// <param name="source"> a dictionary that contains the text source</param> /// <param name="parameters"></param> /// <returns>Returns the dictionary </returns> public static List <KeyValuePair <string, string> > SentimentAnalysisContentBuilder(List <KeyValuePair <string, string> > source, SentimentAnalysisParameters parameters) { var content = new List <KeyValuePair <string, string> >(); content.Add(new KeyValuePair <string, string>("token", parameters.Token)); content.AddRange(source); if (parameters.Lang != DefaultValues.Lang) { content.Add(new KeyValuePair <string, string>("lang", parameters.Lang.ToString())); } return(content); }
/// <summary> /// Asyncronous method that call <see href="https://dandelion.eu/docs/api/datatxt/sent/v1/">Sentiment Analysis end-point</see> on a text source /// </summary> /// <param name="parameters"> Parameters to specify all options for the Sentiment Analysis process </param> /// <returns>Returns a <c>SentimentAnalysisDto</c> populated with the result of the Sentiment Analysis process </returns> /// <seealso cref="SentimentAnalysisDto"/> public static Task <SentimentAnalysisDto> AnalyzeSentimentsAsync(SentimentAnalysisParameters parameters) { Init(); return(_sentimentAnalysisService.CallSentimentAnalysisAsync(parameters)); }