public IActionResult GetSentenceBySystemFilter([FromQuery] string filter)
        {
            string entityAsJson = "";
            List <SentenceStatsEntity> systemSentenceStats = new List <SentenceStatsEntity>();

            try
            {
                _logger.LogInformation("CPAPI: Get Sentence Graph By Record Filter");

                // Deserialize the filter
                SystemFilter oFilter = new SystemFilter();
                if (filter != null && filter.Length > 0)
                {
                    _logger.LogDebug("Deserializing filter of length: " + filter.Length);
                    oFilter = JsonConvert.DeserializeObject <SystemFilter>(filter);
                }

                string storageAccountConnectionString = Utils.GetSecretOrEnvVar(ConfigurationProperties.AzureStorageAccountConnectionString, Configuration, _logger).Trim();
                // validate tika base address
                if (storageAccountConnectionString == "")
                {
                    _logger.LogWarning("Azure storage account connection string not set");
                    return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError));
                }
                else
                {
                    _logger.LogDebug("Azure storage account connection string loaded");
                }

                // Get the key phrases for the record and for the record associations
                systemSentenceStats = GetSentenceStatsForSystem(oFilter);

                // Create the visualisation nodes
                grandparent gp = new grandparent("System");
                gp.label = "System";    //TODO: set as system label

                // Add sentence schema
                // TODO: support all RAs and/or ontologies
                parent p_sentence = new parent("AFDA");
                p_sentence.label = "AFDA";
                gp.children.Add(p_sentence);

                // Add sentence stats
                int i = 0;
                foreach (SentenceStatsEntity statEntity in systemSentenceStats)
                {
                    // Get the sentence stats for this system
                    List <SentenceStat> sentences = new List <SentenceStat>();
                    if (statEntity.JsonSentenceStats != null)
                    {
                        sentences = JsonConvert.DeserializeObject <List <SentenceStat> >(statEntity.JsonSentenceStats);
                    }
                    foreach (SentenceStat stat in sentences)
                    {
                        // Create a new child object for the class
                        child c = new child(stat.ClassNo, stat.NumEntries);
                        c.label = stat.Function;
                        p_sentence.children.Add(c);
                    }

                    i++;
                }


                // Serialize
                entityAsJson = JsonConvert.SerializeObject(gp, Formatting.None);
            }
            catch (Exception ex)
            {
                string exceptionMsg = "KeyPhrase GET exception: " + ex.Message;
                //log.Info("Exception occurred extracting text from uploaded file \r\nError: " + ex.Message);
                if (ex.InnerException != null)
                {
                    exceptionMsg = exceptionMsg + "[" + ex.InnerException.Message + "]";
                }

                _logger.LogError(exceptionMsg);
                return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError));
            }

            ObjectResult result = new ObjectResult(entityAsJson);

            return(result);
        }
        public IActionResult GetByRecordFilter([FromQuery] string filter)
        {
            string entityAsJson = "";
            List <KeyPhraseCount> recordKeyPhrases            = new List <KeyPhraseCount>();
            List <KeyPhraseCount> recordAssociationKeyPhrases = new List <KeyPhraseCount>();

            try
            {
                _logger.LogInformation("CPAPI: Get By Record Filter");

                // Deserialize the filter
                KeyPhraseFilter oFilter = new KeyPhraseFilter();
                if (filter != null && filter.Length > 0)
                {
                    _logger.LogDebug("Deserializing filter of length: " + filter.Length);
                    oFilter = JsonConvert.DeserializeObject <KeyPhraseFilter>(filter);
                }

                string storageAccountConnectionString = Utils.GetSecretOrEnvVar(ConfigurationProperties.AzureStorageAccountConnectionString, Configuration, _logger).Trim();
                // validate tika base address
                if (storageAccountConnectionString == "")
                {
                    _logger.LogWarning("Azure storage account connection string not set");
                    return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError));
                }
                else
                {
                    _logger.LogDebug("Azure storage account connection string loaded");
                }

                // Get the key phrases for the record and for the record associations
                recordKeyPhrases            = GetRecordKeyPhrasesForRecordAuthority(oFilter);
                recordAssociationKeyPhrases = GetRecordKeyPhrasesForRecordAssociations(oFilter);

                // Create the visualisation nodes
                grandparent gp = new grandparent(oFilter.records[0]);
                gp.label = "Record";

                // Add record authority key phrases
                // TODO: support all RAs and/or ontologies
                parent p_ra = new parent("AFDA");
                p_ra.label = "AFDA";
                gp.children.Add(p_ra);

                // Add record authority key phrases
                int i = 0;
                foreach (KeyPhraseCount kpcount in recordKeyPhrases)
                {
                    // Create a new child object for the keyphrase
                    child c = new child(kpcount.KeyPhrase, kpcount.Count);
                    c.label = kpcount.KeyPhrase;
                    p_ra.children.Add(c);

                    // Check if we have reached maximum number
                    i++;
                    if (i >= 20)
                    {
                        break;
                    }
                }

                // Add record association key phrases
                parent p_recassociation = new parent("Default");
                p_recassociation.label = "Default";
                gp.children.Add(p_recassociation);

                // Add record association key phrases
                i = 0;
                foreach (KeyPhraseCount kpcount in recordAssociationKeyPhrases)
                {
                    // Create a new child object for the keyphrase
                    child c = new child(kpcount.KeyPhrase, kpcount.Count);
                    c.label = kpcount.KeyPhrase;
                    p_recassociation.children.Add(c);

                    // Check if we have reached maximum number
                    i++;
                    if (i >= 20)
                    {
                        break;
                    }
                }

                // Serialize
                entityAsJson = JsonConvert.SerializeObject(gp, Formatting.None);
            }
            catch (Exception ex)
            {
                string exceptionMsg = "KeyPhrase GET exception: " + ex.Message;
                //log.Info("Exception occurred extracting text from uploaded file \r\nError: " + ex.Message);
                if (ex.InnerException != null)
                {
                    exceptionMsg = exceptionMsg + "[" + ex.InnerException.Message + "]";
                }

                _logger.LogError(exceptionMsg);
                return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError));
            }

            ObjectResult result = new ObjectResult(entityAsJson);

            return(result);
        }