internal RecognizedForm(DocumentResult documentResult, IReadOnlyList <PageResult> pageResults, IReadOnlyList <ReadResult> readResults, string modelId)
        {
            // Recognized form from a model trained with labels.
            FormType = documentResult.DocType;

            PageRange = new FormPageRange(documentResult.PageRange[0], documentResult.PageRange[1]);

            // documentResult.Fields is required and not null, according to the swagger file, but it's not
            // present when a blank receipt is submitted for recognition.

            Fields = documentResult.Fields == null
                ? new Dictionary <string, FormField>()
                : ConvertSupervisedFields(documentResult.Fields, readResults);
            Pages              = ConvertSupervisedPages(pageResults, readResults);
            ModelId            = documentResult.ModelId.HasValue ? documentResult.ModelId.Value.ToString() : modelId;
            FormTypeConfidence = documentResult.DocTypeConfidence ?? Constants.DefaultConfidenceValue;
        }
예제 #2
0
        internal RecognizedForm(DocumentResult documentResult, IReadOnlyList <PageResult> pageResults, IReadOnlyList <ReadResult> readResults)
        {
            // Recognized form from a model trained with labels.
            FormType = documentResult.DocType;

            // TODO: validate that PageRange.Length == 2.
            // https://github.com/Azure/azure-sdk-for-net/issues/10547

            PageRange = new FormPageRange(documentResult.PageRange[0], documentResult.PageRange[1]);

            // documentResult.Fields is required and not null, according to the swagger file, but it's not
            // present when a blank receipt is submitted for recognition.

            Fields = documentResult.Fields == null
                ? new Dictionary <string, FormField>()
                : ConvertSupervisedFields(documentResult.Fields, readResults);
            Pages = ConvertSupervisedPages(pageResults, readResults);
        }
        internal static V2AnalyzeResult DeserializeV2AnalyzeResult(JsonElement element)
        {
            string version = default;
            Optional <IReadOnlyList <ReadResult> >          readResults     = default;
            Optional <IReadOnlyList <PageResult> >          pageResults     = default;
            Optional <IReadOnlyList <DocumentResult> >      documentResults = default;
            Optional <IReadOnlyList <FormRecognizerError> > errors          = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("version"))
                {
                    version = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("readResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        readResults = null;
                        continue;
                    }
                    List <ReadResult> array = new List <ReadResult>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ReadResult.DeserializeReadResult(item));
                    }
                    readResults = array;
                    continue;
                }
                if (property.NameEquals("pageResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        pageResults = null;
                        continue;
                    }
                    List <PageResult> array = new List <PageResult>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(PageResult.DeserializePageResult(item));
                    }
                    pageResults = array;
                    continue;
                }
                if (property.NameEquals("documentResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        documentResults = null;
                        continue;
                    }
                    List <DocumentResult> array = new List <DocumentResult>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentResult.DeserializeDocumentResult(item));
                    }
                    documentResults = array;
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <FormRecognizerError> array = new List <FormRecognizerError>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(FormRecognizerError.DeserializeFormRecognizerError(item));
                    }
                    errors = array;
                    continue;
                }
            }
            return(new V2AnalyzeResult(version, Optional.ToList(readResults), Optional.ToList(pageResults), Optional.ToList(documentResults), Optional.ToList(errors)));
        }
예제 #4
0
 internal RecognizedForm(DocumentResult documentResult, IReadOnlyList <PageResult> pageResults, IReadOnlyList <ReadResult> readResults, string modelId)
     : this(documentResult, pageResults, readResults, modelId, false)
 {
 }
        internal static AnalyzeResult DeserializeAnalyzeResult(JsonElement element)
        {
            string version = default;
            IReadOnlyList <ReadResult>       readResults     = default;
            IReadOnlyList <PageResult>       pageResults     = default;
            IReadOnlyList <DocumentResult>   documentResults = default;
            IReadOnlyList <ErrorInformation> errors          = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("version"))
                {
                    version = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("readResults"))
                {
                    List <ReadResult> array = new List <ReadResult>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ReadResult.DeserializeReadResult(item));
                        }
                    }
                    readResults = array;
                    continue;
                }
                if (property.NameEquals("pageResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <PageResult> array = new List <PageResult>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(PageResult.DeserializePageResult(item));
                        }
                    }
                    pageResults = array;
                    continue;
                }
                if (property.NameEquals("documentResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <DocumentResult> array = new List <DocumentResult>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(DocumentResult.DeserializeDocumentResult(item));
                        }
                    }
                    documentResults = array;
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ErrorInformation> array = new List <ErrorInformation>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ErrorInformation.DeserializeErrorInformation(item));
                        }
                    }
                    errors = array;
                    continue;
                }
            }
            return(new AnalyzeResult(version, readResults, pageResults, documentResults, errors));
        }