/// <summary>
 ///     Asyncronous method that validate the <c>EntityExtractionParameters</c> and <c>TextSimilarityParameters</c> in <see href="https://dandelion.eu/docs/api/datatxt/sim/v1/">special cases</see>
 /// </summary>
 /// <param name="parameters"></param>
 public static void ValidateParameters(EntityExtractionParameters parameters)
 {
     ServiceUtils.ParameterValidation(parameters);
     if (parameters.Epsilon < 0.0 || parameters.Epsilon > 0.5)
     {
         throw new ArgumentException(ErrorMessages.WrongEpsilon, ErrorMessages.Epsilon);
     }
     if (parameters.TopEntities < 0)
     {
         throw new ArgumentException(ErrorMessages.WrongTopEntities, ErrorMessages.TopEntities);
     }
     if (parameters.MinConfidence < 0.0 || parameters.MinConfidence > 1.0)
     {
         throw new ArgumentException(ErrorMessages.WrongMinConfidence, ErrorMessages.MinConfidence);
     }
     if (parameters.MinLength < 2)
     {
         throw new ArgumentException(ErrorMessages.WrongMinLength, ErrorMessages.MinLength);
     }
     if (parameters.Include != null)
     {
         if (parameters.Include.FindAll(x => x == IncludeOption.score_details).ToList().Count > 0)
         {
             throw new ArgumentException(ErrorMessages.WrongInclude1, ErrorMessages.Include);
         }
     }
     if (parameters.Include.hasDuplicates())
     {
         parameters.Include = parameters.Include.Distinct().ToList();
     }
     if (parameters.ExtraTypes.hasDuplicates())
     {
         parameters.ExtraTypes = parameters.ExtraTypes.Distinct().ToList();
     }
 }
        /// <summary>
        ///     Asyncronous method that validate the user parameters and call <c>ApiClient</c>
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns>Returns a <c>EntityExtractionDto</c> populated with the result of the call </returns>
        /// <seealso cref="EntityExtractionDto"/>
        public Task <EntityExtractionDto> CallEntityExtractionAsync(EntityExtractionParameters parameters)
        {
            ValidateParameters(parameters);
            var source = SourceValidationService.verifySingleSource(parameters);

            return(_apiClient.CallApiAsync <EntityExtractionDto>(ApiClient.EntityExtractionUriBuilder(), ApiClient.EntityExtractionContentBuilder(source, parameters), parameters.HttpMethod));
        }
Exemple #3
0
        /// <summary>
        ///     Allocates a dictionary that contains the parameters for the call
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="prefix"> set to "nex." in case of a Text Similarity process</param>
        /// <returns>Returns the dictionary </returns>
        public static List <KeyValuePair <string, string> > NexContentBuilder(EntityExtractionParameters parameters, string prefix = "")
        {
            var content = new List <KeyValuePair <string, string> >();

            content.Add(new KeyValuePair <string, string>("token", parameters.Token));
            if (parameters.Epsilon != DefaultValues.Epsilon)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}epsilon", $"{parameters.Epsilon}"));
            }
            if (parameters.Lang != DefaultValues.Lang)
            {
                content.Add(new KeyValuePair <string, string>("lang", $"{parameters.Lang}"));
            }
            if (parameters.TopEntities != DefaultValues.TopEntities)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}top_entities", $"{parameters.TopEntities}"));
            }
            if (parameters.MinConfidence != DefaultValues.MinConfidence)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}min_confidence", $"{parameters.MinConfidence}"));
            }
            if (parameters.SocialHashtag != DefaultValues.SocialHashtag)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}social.hashtag", $"{parameters.SocialHashtag}"));
            }
            if (parameters.SocialMention != DefaultValues.SocialMention)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}social.mention", $"{parameters.SocialMention}"));
            }
            if (parameters.Include != DefaultValues.Include)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}include", $"{String.Join(" , ", parameters.Include)}"));
            }
            if (parameters.ExtraTypes != DefaultValues.ExtraTypes)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}extra_types", $"{String.Join(" , ", parameters.ExtraTypes)}"));
            }
            if (parameters.Country != DefaultValues.Country)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}country", $"{parameters.Country}"));
            }
            if (parameters.CustomSpots != DefaultValues.CustomSpots)
            {
                content.Add(new KeyValuePair <string, string>($"{prefix}custom_spots", $"{parameters.CustomSpots}"));
            }
            return(content);
        }
        public async void Should_ThrowException_When_CallEntityExtractionWithWrongParameters(EntityExtractionParameters parameters, string message, string wrongParameter)
        {
            //Act & Assert

            ArgumentException ex = await Assert.ThrowsAsync <ArgumentException>(() => _entityExtractionService.CallEntityExtractionAsync(parameters));

            if (String.IsNullOrEmpty(wrongParameter))
            {
                Assert.Equal(message, ex.Message);
            }
            else
            {
                Assert.Equal($"{message}{Environment.NewLine}Parameter name: {wrongParameter}", ex.Message);
            }
        }
Exemple #5
0
        /// <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> > EntityExtractionContentBuilder(List <KeyValuePair <string, string> > source, EntityExtractionParameters parameters)
        {
            var content = NexContentBuilder(parameters);

            content.AddRange(source);
            return(content);
        }
Exemple #6
0
 /// <summary>
 ///     Asyncronous method that call <see href="https://dandelion.eu/docs/api/datatxt/nex/v1/">EntityExtraction end-point</see> on a text source
 /// </summary>
 /// <param name="parameters"> Parameters to specify all options for the EntityExtraction process </param>
 /// <returns>Returns a <c>EntityExtractionDto</c> populated with the result of the EntityExtraction process </returns>
 /// <seealso cref="EntityExtractionDto"/>
 public static Task <EntityExtractionDto> GetEntitiesAsync(EntityExtractionParameters parameters)
 {
     Init();
     return(_entityExtractionService.CallEntityExtractionAsync(parameters));
 }