< Summary

Class:Azure.AI.TextAnalytics.Transforms
Assembly:Azure.AI.TextAnalytics
File(s):C:\Git\azure-sdk-for-net\sdk\textanalytics\Azure.AI.TextAnalytics\src\Transforms.cs
Covered lines:16
Uncovered lines:3
Coverable lines:19
Total lines:65
Line coverage:84.2% (16 of 19)
Covered branches:6
Total branches:8
Branch coverage:75% (6 of 8)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ConvertToError(...)-85.71%50%
ConvertToDetectedLanguage(...)-50%50%
ConvertLanguageResult(...)-100%100%
SortHeterogeneousCollection(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\textanalytics\Azure.AI.TextAnalytics\src\Transforms.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.Linq;
 6using Azure.AI.TextAnalytics.Models;
 7
 8namespace Azure.AI.TextAnalytics
 9{
 10    internal static class Transforms
 11    {
 12        internal static TextAnalyticsError ConvertToError(TextAnalyticsError_internal error)
 13        {
 814            string errorCode = error.Code;
 815            string message = error.Message;
 816            string target = error.Target;
 817            InnerError innerError = error.Innererror;
 18
 819            if (innerError != null)
 20            {
 21                // Return the innermost error, which should be only one level down.
 822                return new TextAnalyticsError(innerError.Code, innerError.Message, innerError.Target);
 23            }
 24
 025            return new TextAnalyticsError(errorCode, message, target);
 26        }
 27
 28        internal static DetectedLanguage ConvertToDetectedLanguage(DocumentLanguage documentLanguage)
 29        {
 8430            var warnings = new List<TextAnalyticsWarning>();
 031            foreach (TextAnalyticsWarning_internal warning in documentLanguage.Warnings)
 32            {
 033                warnings.Add(new TextAnalyticsWarning(warning));
 34            }
 35
 8436            return new DetectedLanguage(documentLanguage.DetectedLanguage, warnings);
 37        }
 38
 39        internal static DetectLanguageResultCollection ConvertLanguageResult(LanguageResult results, IDictionary<string,
 40        {
 2041            var detectedLanguages = new List<DetectLanguageResult>();
 42
 43            //Read errors
 4844            foreach (DocumentError error in results.Errors)
 45            {
 446                detectedLanguages.Add(new DetectLanguageResult(error.Id, ConvertToError(error.Error)));
 47            }
 48
 49            //Read languages
 16050            foreach (DocumentLanguage language in results.Documents)
 51            {
 6052                detectedLanguages.Add(new DetectLanguageResult(language.Id, language.Statistics ?? default, ConvertToDet
 53            }
 54
 2055            detectedLanguages = SortHeterogeneousCollection(detectedLanguages, idToIndexMap);
 56
 2057            return new DetectLanguageResultCollection(detectedLanguages, results.Statistics, results.ModelVersion);
 58        }
 59
 60        private static List<T> SortHeterogeneousCollection<T>(List<T> collection, IDictionary<string, int> idToIndexMap)
 61        {
 8462            return collection.OrderBy(result => idToIndexMap[result.Id]).ToList();
 63        }
 64    }
 65}