예제 #1
0
 /// <summary>
 /// </summary>
 /// <param name="jobState"></param>
 /// <param name="idToIndexMap"></param>
 internal AnalyzeOperationResult(AnalyzeJobState jobState, IDictionary <string, int> idToIndexMap)
 {
     Errors      = Transforms.ConvertToErrors(jobState.Errors);
     Statistics  = jobState.Statistics;
     DisplayName = jobState.DisplayName;
     Status      = jobState.Status;
     Tasks       = new AnalyzeTasks(jobState.Tasks, idToIndexMap);
 }
        internal AnalyzeBatchActionsResult(AnalyzeJobState jobState, IDictionary <string, int> map)
        {
            AnalyzeBatchActionsResult actionResults = Transforms.ConvertToAnalyzeBatchActionsResult(jobState, map);

            ExtractKeyPhrasesActionsResults    = actionResults.ExtractKeyPhrasesActionsResults;
            RecognizeEntitiesActionsResults    = actionResults.RecognizeEntitiesActionsResults;
            RecognizePiiEntitiesActionsResults = actionResults.RecognizePiiEntitiesActionsResults;
            Statistics = actionResults.Statistics;
        }
예제 #3
0
        internal static AnalyzeActionsResult ConvertToAnalyzeActionsResult(AnalyzeJobState jobState, IDictionary <string, int> map)
        {
            IDictionary <int, TextAnalyticsErrorInternal> keyPhraseErrors                  = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> entitiesRecognitionErrors        = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> entitiesPiiRecognitionErrors     = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> entitiesLinkingRecognitionErrors = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> analyzeSentimentErrors           = new Dictionary <int, TextAnalyticsErrorInternal>();

            if (jobState.Errors.Any())
            {
                foreach (TextAnalyticsErrorInternal error in jobState.Errors)
                {
                    string[] targetPair = parseActionErrorTarget(error.Target);
                    if (targetPair == null)
                    {
                        throw new InvalidOperationException("Invalid action/id error");
                    }

                    string taskName  = targetPair[0];
                    int    taskIndex = int.Parse(targetPair[1], CultureInfo.InvariantCulture);

                    if ("entityRecognitionTasks".Equals(taskName))
                    {
                        entitiesRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("entityRecognitionPiiTasks".Equals(taskName))
                    {
                        entitiesPiiRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("keyPhraseExtractionTasks".Equals(taskName))
                    {
                        keyPhraseErrors.Add(taskIndex, error);
                    }
                    else if ("entityLinkingTasks".Equals(taskName))
                    {
                        entitiesLinkingRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("sentimentAnalysisTasks".Equals(taskName))
                    {
                        analyzeSentimentErrors.Add(taskIndex, error);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Invalid task name in target reference - {taskName}");
                    }
                }
            }

            return(new AnalyzeActionsResult(
                       ConvertToExtractKeyPhrasesActionResults(jobState, map, keyPhraseErrors),
                       ConvertToRecognizeEntitiesActionsResults(jobState, map, entitiesRecognitionErrors),
                       ConvertToRecognizePiiEntitiesActionsResults(jobState, map, entitiesPiiRecognitionErrors),
                       ConvertToRecognizeLinkedEntitiesActionsResults(jobState, map, entitiesLinkingRecognitionErrors),
                       ConvertToAnalyzeSentimentActionsResults(jobState, map, analyzeSentimentErrors)));
        }
 private static bool CheckIfGenericError(AnalyzeJobState jobState)
 {
     foreach (TextAnalyticsErrorInternal error in jobState.Errors)
     {
         if (string.IsNullOrEmpty(error.Target))
         {
             return(true);
         }
     }
     return(false);
 }
        internal static AnalyzeBatchActionsResult ConvertToAnalyzeBatchActionsResult(AnalyzeJobState jobState, IDictionary <string, int> map)
        {
            IDictionary <int, TextAnalyticsErrorInternal> keyPhraseErrors              = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> entitiesRecognitionErrors    = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> entitiesPiiRecognitionErrors = new Dictionary <int, TextAnalyticsErrorInternal>();

            if (jobState.Errors.Any())
            {
                foreach (TextAnalyticsErrorInternal error in jobState.Errors)
                {
                    string[] targetPair = parseActionErrorTarget(error.Target);
                    string   taskName   = targetPair[0];
                    int      taskIndex  = int.Parse(targetPair[1], CultureInfo.InvariantCulture);

                    if ("entityRecognitionTasks".Equals(taskName))
                    {
                        entitiesRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("entityRecognitionPiiTasks".Equals(taskName))
                    {
                        entitiesPiiRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("keyPhraseExtractionTasks".Equals(taskName))
                    {
                        keyPhraseErrors.Add(taskIndex, error);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Invalid task name in target reference - {taskName}");
                    }
                }
            }

            var extractKeyPhrasesActionResult     = ConvertToExtractKeyPhrasesActionResults(jobState, map, keyPhraseErrors);
            var recognizeEntitiesActionResults    = ConvertToRecognizeEntitiesActionsResults(jobState, map, entitiesRecognitionErrors);
            var recognizePiiEntitiesActionResults = ConvertToRecognizePiiEntitiesActionsResults(jobState, map, entitiesPiiRecognitionErrors);

            return(new AnalyzeBatchActionsResult(extractKeyPhrasesActionResult, recognizeEntitiesActionResults, recognizePiiEntitiesActionResults, jobState.Statistics));
        }
예제 #6
0
        private static IReadOnlyCollection <RecognizeEntitiesActionResult> ConvertToRecognizeEntitiesActionsResults(AnalyzeJobState jobState, IDictionary <string, int> idToIndexMap, IDictionary <int, TextAnalyticsErrorInternal> tasksErrors)
        {
            var collection = new List <RecognizeEntitiesActionResult>();
            int index      = 0;

            foreach (EntityRecognitionTasksItem task in jobState.Tasks.EntityRecognitionTasks)
            {
                tasksErrors.TryGetValue(index, out TextAnalyticsErrorInternal taskError);

                tasksErrors.TryGetValue(index, out taskError);

                if (taskError != null)
                {
                    collection.Add(new RecognizeEntitiesActionResult(null, task.LastUpdateDateTime, taskError));
                }
                else
                {
                    collection.Add(new RecognizeEntitiesActionResult(ConvertToRecognizeEntitiesResultCollection(task.Results, idToIndexMap), task.LastUpdateDateTime, taskError));
                }
                index++;
            }

            return(collection);
        }
예제 #7
0
 internal static AnalyzeOperationResult ConvertToAnalyzeOperationResult(AnalyzeJobState jobState, IDictionary <string, int> map)
 {
     return(new AnalyzeOperationResult(jobState, map));
 }
        internal static IReadOnlyCollection <ExtractKeyPhrasesActionResult> ConvertToExtractKeyPhrasesActionResults(AnalyzeJobState jobState, IDictionary <string, int> idToIndexMap, IDictionary <int, TextAnalyticsErrorInternal> tasksErrors)
        {
            var collection = new List <ExtractKeyPhrasesActionResult>();
            int index      = 0;

            foreach (KeyPhraseExtractionTasksItem task in jobState.Tasks.KeyPhraseExtractionTasks)
            {
                tasksErrors.TryGetValue(index, out TextAnalyticsErrorInternal taskError);

                if (taskError != null)
                {
                    collection.Add(new ExtractKeyPhrasesActionResult(null, task.LastUpdateDateTime, taskError));
                }
                else
                {
                    collection.Add(new ExtractKeyPhrasesActionResult(ConvertToExtractKeyPhrasesResultCollection(task.ResultsInternal, idToIndexMap), task.LastUpdateDateTime, null));
                }
                index++;
            }

            return(collection);
        }
예제 #9
0
        internal static IReadOnlyCollection <RecognizePiiEntitiesActionResult> ConvertToRecognizePiiEntitiesActionsResults(AnalyzeJobState jobState, IDictionary <string, int> idToIndexMap, IDictionary <int, TextAnalyticsErrorInternal> errors)
        {
            var collection = new List <RecognizePiiEntitiesActionResult>();
            int index      = 0;

            foreach (EntityRecognitionPiiTasksItem task in jobState.Tasks.EntityRecognitionPiiTasks)
            {
                TextAnalyticsErrorInternal error;
                errors.TryGetValue(index, out error);

                collection.Add(new RecognizePiiEntitiesActionResult(ConvertToRecognizePiiEntitiesResultCollection(task.ResultsInternal, idToIndexMap), task.LastUpdateDateTime, error));
                index++;
            }

            return(collection);
        }
        private static IReadOnlyCollection <ExtractSummaryActionResult> ConvertToExtractSummaryActionsResults(AnalyzeJobState jobState, IDictionary <string, int> idToIndexMap, IDictionary <int, TextAnalyticsErrorInternal> tasksErrors)
        {
            var collection = new List <ExtractSummaryActionResult>(jobState.Tasks.ExtractiveSummarizationTasks.Count);
            int index      = 0;

            foreach (ExtractiveSummarizationTasksItem task in jobState.Tasks.ExtractiveSummarizationTasks)
            {
                tasksErrors.TryGetValue(index, out TextAnalyticsErrorInternal taskError);

                if (taskError != null)
                {
                    collection.Add(new ExtractSummaryActionResult(task.TaskName, task.LastUpdateDateTime, taskError));
                }
                else
                {
                    collection.Add(new ExtractSummaryActionResult(ConvertToExtractSummaryResultCollection(task.Results, idToIndexMap), task.TaskName, task.LastUpdateDateTime));
                }
                index++;
            }

            return(collection);
        }
        internal static AnalyzeActionsResult ConvertToAnalyzeActionsResult(AnalyzeJobState jobState, IDictionary <string, int> map)
        {
            IDictionary <int, TextAnalyticsErrorInternal> keyPhraseErrors                  = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> entitiesRecognitionErrors        = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> entitiesPiiRecognitionErrors     = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> entitiesLinkingRecognitionErrors = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> analyzeSentimentErrors           = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> extractSummaryErrors             = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> customEntitiesRecognitionErrors  = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> singleCategoryClassifyErrors     = new Dictionary <int, TextAnalyticsErrorInternal>();
            IDictionary <int, TextAnalyticsErrorInternal> multiCategoryClassifyErrors      = new Dictionary <int, TextAnalyticsErrorInternal>();

            if (jobState.Errors.Any())
            {
                foreach (TextAnalyticsErrorInternal error in jobState.Errors)
                {
                    string[] targetPair = parseActionErrorTarget(error.Target);
                    if (targetPair == null)
                    {
                        throw new InvalidOperationException($"Invalid action/id error. \n Additional information: Error code: {error.Code} Error message: {error.Message}");
                    }

                    string taskName  = targetPair[0];
                    int    taskIndex = int.Parse(targetPair[1], CultureInfo.InvariantCulture);

                    if ("entityRecognitionTasks".Equals(taskName))
                    {
                        entitiesRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("entityRecognitionPiiTasks".Equals(taskName))
                    {
                        entitiesPiiRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("keyPhraseExtractionTasks".Equals(taskName))
                    {
                        keyPhraseErrors.Add(taskIndex, error);
                    }
                    else if ("entityLinkingTasks".Equals(taskName))
                    {
                        entitiesLinkingRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("sentimentAnalysisTasks".Equals(taskName))
                    {
                        analyzeSentimentErrors.Add(taskIndex, error);
                    }
                    else if ("extractiveSummarizationTasks".Equals(taskName))
                    {
                        extractSummaryErrors.Add(taskIndex, error);
                    }
                    else if ("customEntityRecognitionTasks".Equals(taskName))
                    {
                        customEntitiesRecognitionErrors.Add(taskIndex, error);
                    }
                    else if ("customSingleClassificationTasks".Equals(taskName))
                    {
                        singleCategoryClassifyErrors.Add(taskIndex, error);
                    }
                    else if ("customMultiClassificationTasks".Equals(taskName))
                    {
                        multiCategoryClassifyErrors.Add(taskIndex, error);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Invalid task name in target reference - {taskName}. \n Additional information: Error code: {error.Code} Error message: {error.Message}");
                    }
                }
            }

            return(new AnalyzeActionsResult(
                       ConvertToExtractKeyPhrasesActionResults(jobState, map, keyPhraseErrors),
                       ConvertToRecognizeEntitiesActionsResults(jobState, map, entitiesRecognitionErrors),
                       ConvertToRecognizePiiEntitiesActionsResults(jobState, map, entitiesPiiRecognitionErrors),
                       ConvertToRecognizeLinkedEntitiesActionsResults(jobState, map, entitiesLinkingRecognitionErrors),
                       ConvertToAnalyzeSentimentActionsResults(jobState, map, analyzeSentimentErrors),
                       ConvertToExtractSummaryActionsResults(jobState, map, extractSummaryErrors),
                       ConvertToRecognizeCustomEntitiesActionsResults(jobState, map, customEntitiesRecognitionErrors),
                       ConvertToSingleCategoryClassifyResults(jobState, map, singleCategoryClassifyErrors),
                       ConvertToMultiCategoryClassifyActionsResults(jobState, map, multiCategoryClassifyErrors)
                       ));
        }