Exemple #1
0
        private async Task <IReasoningTask> ContinueReasoningStepByStep(IReasoningTask reasoningTask)
        {
            reasoningTask.ReasoningProcess = _reasoningService.ContinueReasoning(reasoningTask.ReasoningProcess);

            IList <IVariableSource> sources          = reasoningTask.Sources?.ToList() ?? new List <IVariableSource>();
            IList <string>          missingVariables = _reasoningService.GetAllMissingVariableIds(reasoningTask.ReasoningProcess).ToList();

            while (CanContinueReasoning(reasoningTask.ReasoningProcess, sources, missingVariables))
            {
                var missingVariableId = missingVariables.First();

                var source            = sources.FirstOrDefault(src => src.VariableIds.Contains(missingVariableId));
                var variablesResource = await _httpClientService.ExecuteTaskAsync <VariablesResource>(source?.Request);

                sources.Remove(source);

                if (variablesResource?.Variables == null)
                {
                    _logger.LogError($"Couldn't parse values from {source.Request.Uri}");
                    continue;
                }

                variablesResource.Variables.ToList().ForEach(variable => missingVariables.Remove(variable.Id));

                reasoningTask.ReasoningProcess = _reasoningService.SetValues(reasoningTask.ReasoningProcess, variablesResource.Variables);
                reasoningTask.ReasoningProcess = _reasoningService.ContinueReasoning(reasoningTask.ReasoningProcess);
            }

            return(reasoningTask);
        }