/// <summary>
        ///     Asyncronous method that validate the user parameters and call <c>ApiClient</c>
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns>Returns a <c>TextSimilarityDto</c> populated with the result of the call </returns>
        /// <seealso cref="TextSimilarityDto"/>
        public Task <TextSimilarityDto> CallTextSimilaritiesAsync(TextSimilarityParameters parameters)
        {
            EntityExtractionService.ValidateParameters(parameters);
            var source = SourceValidationService.verifyMultipleSources(parameters);

            return(_apiClient.CallApiAsync <TextSimilarityDto>(ApiClient.TextSimilarityUriBuilder(), ApiClient.TextSimilarityContentBuilder(source, parameters), parameters.HttpMethod));
        }
예제 #2
0
        /// <summary>
        ///     Asyncronous method that validate the sources parameters
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns>Returns a dictionary populated with the sources parameters</returns>
        public static List <KeyValuePair <string, string> > verifyMultipleSources(TextSimilarityParameters parameters)
        {
            var key1   = "";
            var value1 = "";
            var key2   = "";
            var value2 = "";

            if (!String.IsNullOrEmpty(parameters.Text1))
            {
                key1   = "text1";
                value1 = $"{parameters.Text1}";
            }
            if (!String.IsNullOrEmpty(parameters.Url1) && Uri.IsWellFormedUriString(parameters.Url1, UriKind.Absolute))
            {
                if (!String.IsNullOrEmpty(value1))
                {
                    throw new ArgumentException(ErrorMessages.WrongSource1, ErrorMessages.Url1);
                }
                key1   = "url1";
                value1 = $"{parameters.Url1}";
            }
            if (!String.IsNullOrEmpty(parameters.Html1))
            {
                if (!String.IsNullOrEmpty(value1))
                {
                    throw new ArgumentException(ErrorMessages.WrongSource1, ErrorMessages.Html1);
                }
                key1   = "html1";
                value1 = $"{parameters.Html1}";
            }
            if (!String.IsNullOrEmpty(parameters.HtmlFragment1))
            {
                if (!String.IsNullOrEmpty(value1))
                {
                    throw new ArgumentException(ErrorMessages.WrongSource1, ErrorMessages.HtmlFragment1);
                }
                key1   = "html_fragment1";
                value1 = $"{parameters.HtmlFragment1}";
            }

            if (!String.IsNullOrEmpty(parameters.Text2))
            {
                key2   = "text2";
                value2 = $"{parameters.Text2}";
            }
            if (!String.IsNullOrEmpty(parameters.Url2) && Uri.IsWellFormedUriString(parameters.Url2, UriKind.Absolute))
            {
                if (!String.IsNullOrEmpty(value2))
                {
                    throw new ArgumentException(ErrorMessages.WrongSource2, ErrorMessages.Url2);
                }
                key2   = "url2";
                value2 = $"{parameters.Url2}";
            }
            if (!String.IsNullOrEmpty(parameters.Html2))
            {
                if (!String.IsNullOrEmpty(value2))
                {
                    throw new ArgumentException(ErrorMessages.WrongSource2, ErrorMessages.Html2);
                }
                key2   = "html2";
                value2 = $"{parameters.Html2}";
            }
            if (!String.IsNullOrEmpty(parameters.HtmlFragment2))
            {
                if (!String.IsNullOrEmpty(value2))
                {
                    throw new ArgumentException(ErrorMessages.WrongSource2, ErrorMessages.HtmlFragment2);
                }
                key2   = "html_fragment2";
                value2 = $"{parameters.HtmlFragment2}";
            }

            if (String.IsNullOrEmpty(value1) || String.IsNullOrEmpty(value2))
            {
                throw new ArgumentException(ErrorMessages.WrongSources);
            }

            var source = new List <KeyValuePair <string, string> >();

            source.Add(new KeyValuePair <string, string>(key1, value1));
            source.Add(new KeyValuePair <string, string>(key2, value2));
            return(source);
        }
예제 #3
0
        public void Should_ThrowException_When_CallVerifyMultipleSourcesWithWrongParameters(TextSimilarityParameters parameters, string message, string wrongParameter)
        {
            //Act & Assert
            ArgumentException ex = Assert.Throws <ArgumentException>(() => SourceValidationService.verifyMultipleSources(parameters));

            if (String.IsNullOrEmpty(wrongParameter))
            {
                Assert.Equal(message, ex.Message);
            }
            else
            {
                Assert.Equal($"{message}{Environment.NewLine}Parameter name: {wrongParameter}", ex.Message);
            }
        }
예제 #4
0
        /// <summary>
        ///     Allocates a dictionary that contains the parameters for the call
        /// </summary>
        /// <param name="source"> a dictionary that contains the text sources</param>
        /// <param name="parameters"></param>
        /// <returns>Returns the dictionary </returns>
        public static List <KeyValuePair <string, string> > TextSimilarityContentBuilder(List <KeyValuePair <string, string> > source, TextSimilarityParameters parameters)
        {
            var content = NexContentBuilder(parameters, "nex.");

            content.AddRange(source);

            if (parameters.Bow != DefaultValues.Bow)
            {
                content.Add(new KeyValuePair <string, string>("bow", parameters.Bow.ToString()));
            }
            return(content);
        }
예제 #5
0
 /// <summary>
 ///     Asyncronous method that call <see href="https://dandelion.eu/docs/api/datatxt/sim/v1/">Text Similarity end-point</see> to compare two text sources
 /// </summary>
 /// <param name="parameters"> Parameters to specify all options for the Text Similarity process </param>
 /// <returns>Returns a <c>TextSimilarityDto</c> populated with the result of the Text Similarity process </returns>
 /// <seealso cref="TextSimilarityDto"/>
 public static Task <TextSimilarityDto> GetSimilaritiesAsync(TextSimilarityParameters parameters)
 {
     Init();
     return(_textSimilarityService.CallTextSimilaritiesAsync(parameters));
 }