<commit_before>﻿using AlchemyAPIClient.Responses;
using System;
using System.Collections.Generic;
using System.Linq;

namespace AlchemyAPIClient.Requests.Combined
{
    public abstract class AlchemyCombinedRequestBase : AlchemyRequestBase<IEnumerable<AlchemyResponseBase<ICombinableAlchemyAPIRequest>>, AlchemyCombinedResponse>
    {
        private const string showSourceTextKey = "showSourceText";
        private const string extractKey = "extract";
        public AlchemyCombinedRequestBase(AlchemyClient client, IEnumerable<ICombinableAlchemyAPIRequest> combinedCalls) : base(client)
        {
            if (combinedCalls == null && !combinedCalls.Any())
                throw new ArgumentNullException(nameof(combinedCalls));
            CombinedCalls = combinedCalls;
            AddRequiredParameter(extractKey);
        }
        protected override T GetTypedResponseFromText<T, U>(string textResponse)
        {
            var combined = base.GetTypedResponseFromText<AlchemyCombinedResponse, IEnumerable<AlchemyResponseBase<ICombinableAlchemyAPIRequest>>>(textResponse);
            combined.AuthorResponse = base.GetTypedResponseFromText<AlchemyAuthorResponse, string>(textResponse);
            combined.SentimentResponse = base.GetTypedResponseFromText<AlchemySentimentResponse, AlchemySentiment>(textResponse);
            combined.KeywordsResponse = base.GetTypedResponseFromText<AlchemyKeywordsResponse, AlchemyKeyword>(textResponse);
            combined.EntitiesResponse = base.GetTypedResponseFromText<AlchemyEntitiesResponse, AlchemyEntity>(textResponse);
            combined.ConceptsResponse = base.GetTypedResponseFromText<AlchemyConceptsResponse, AlchemyConcept>(textResponse);
            combined.RelationResponse = base.GetTypedResponseFromText<AlchemyRelationsResponse, AlchemyRelation>(textResponse);
            combined.TaxonomiesResponse = base.GetTypedResponseFromText<AlchemyTaxonomiesResponse, AlchemyTaxonomy>(textResponse);
            combined.TitleResponse = base.GetTypedResponseFromText<AlchemyTitleResponse, string>(textResponse);
            return combined as T;
        }
        protected override void AdditionalParametersHandling()
        {
            AddOrUpdateParameter(extractKey, CombinedCalls.Select(x => x.CallName).Distinct().Aggregate((x, y) => x + "," + y));
        }
        public IEnumerable<ICombinableAlchemyAPIRequest> CombinedCalls { get; private set; }
        public bool ShowSourceText { get { return GetBooleanParameter(showSourceTextKey); } set { AddOrUpdateParameter(showSourceTextKey, value); } }
    }
}
<commit_msg>adding a check if the request has been asked before unserializing it to improve performances<commit_after>﻿using AlchemyAPIClient.Responses;
using System;
using System.Collections.Generic;
using System.Linq;

namespace AlchemyAPIClient.Requests.Combined
{
    public abstract class AlchemyCombinedRequestBase : AlchemyRequestBase<IEnumerable<AlchemyResponseBase<ICombinableAlchemyAPIRequest>>, AlchemyCombinedResponse>
    {
        private const string showSourceTextKey = "showSourceText";
        private const string extractKey = "extract";
        public AlchemyCombinedRequestBase(AlchemyClient client, IEnumerable<ICombinableAlchemyAPIRequest> combinedCalls) : base(client)
        {
            if (combinedCalls == null && !combinedCalls.Any())
                throw new ArgumentNullException(nameof(combinedCalls));
            CombinedCalls = combinedCalls;
            AddRequiredParameter(extractKey);
        }
        protected override T GetTypedResponseFromText<T, U>(string textResponse)
        {
            var combined = base.GetTypedResponseFromText<AlchemyCombinedResponse, IEnumerable<AlchemyResponseBase<ICombinableAlchemyAPIRequest>>>(textResponse);
            if (CombinedCalls.Any(x => x is AlchemyAuthorRequestBase))
                combined.AuthorResponse = base.GetTypedResponseFromText<AlchemyAuthorResponse, string>(textResponse);
            if (CombinedCalls.Any(x => x is AlchemySentimentRequestBase))
                combined.SentimentResponse = base.GetTypedResponseFromText<AlchemySentimentResponse, AlchemySentiment>(textResponse);
            if (CombinedCalls.Any(x => x is AlchemyKeywordsRequestBase))
                combined.KeywordsResponse = base.GetTypedResponseFromText<AlchemyKeywordsResponse, AlchemyKeyword>(textResponse);
            if (CombinedCalls.Any(x => x is AlchemyEntitiesRequestBase))
                combined.EntitiesResponse = base.GetTypedResponseFromText<AlchemyEntitiesResponse, AlchemyEntity>(textResponse);
            if (CombinedCalls.Any(x => x is AlchemyConceptsRequestBase))
                combined.ConceptsResponse = base.GetTypedResponseFromText<AlchemyConceptsResponse, AlchemyConcept>(textResponse);
            if (CombinedCalls.Any(x => x is AlchemyRelationsRequestBase))
                combined.RelationResponse = base.GetTypedResponseFromText<AlchemyRelationsResponse, AlchemyRelation>(textResponse);
            if (CombinedCalls.Any(x => x is AlchemyTaxonomiesRequestBase))
                combined.TaxonomiesResponse = base.GetTypedResponseFromText<AlchemyTaxonomiesResponse, AlchemyTaxonomy>(textResponse);
            if (CombinedCalls.Any(x => x is AlchemyTitleRequestBase))
                combined.TitleResponse = base.GetTypedResponseFromText<AlchemyTitleResponse, string>(textResponse);
            return combined as T;
        }
        protected override void AdditionalParametersHandling()
        {
            AddOrUpdateParameter(extractKey, CombinedCalls.Select(x => x.CallName).Distinct().Aggregate((x, y) => x + "," + y));
        }
        public IEnumerable<ICombinableAlchemyAPIRequest> CombinedCalls { get; private set; }
        public bool ShowSourceText { get { return GetBooleanParameter(showSourceTextKey); } set { AddOrUpdateParameter(showSourceTextKey, value); } }
    }
}

{'fraction_non_alphanumeric': 0.07914402173913043, 'fraction_numerical': 0.0, 'mean_word_length': 4.143231441048035, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677751', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1533, 'n_words': 264}