internal ExtractedLayoutPage(PageResult_internal pageResult, ReadResult_internal readResult)
        {
            PageNumber = pageResult.Page;
            Tables     = ConvertTables(pageResult.Tables, readResult);

            if (readResult != null)
            {
                RawExtractedPage = new RawExtractedPage(readResult);
            }
        }
예제 #2
0
        private static IReadOnlyList <FormTable> ConvertTables(PageResult_internal pageResult, IReadOnlyList <ReadResult_internal> readResults, int pageIndex)
        {
            List <FormTable> tables = new List <FormTable>();

            foreach (var table in pageResult.Tables)
            {
                tables.Add(new FormTable(table, readResults, pageIndex));
            }

            return(tables);
        }
예제 #3
0
 internal RecognizedForm(PageResult_internal pageResult, IReadOnlyList <ReadResult_internal> readResults)
 {
     // Recognized form from a model trained without labels.
     FormType  = $"form-{pageResult.ClusterId}";
     PageRange = new FormPageRange(pageResult.Page, pageResult.Page);
     Fields    = ConvertFields(pageResult.Page, pageResult.KeyValuePairs, readResults);
     Pages     = ConvertPages(new List <PageResult_internal>()
     {
         pageResult
     }, readResults);
 }
        // Supervised
        internal ExtractedPage(int pageNumber, List <ExtractedField> fields, PageResult_internal pageResult, ReadResult_internal readResult)
        {
            PageNumber = pageNumber;
            Fields     = ConvertFields(fields);
            Tables     = ExtractedLayoutPage.ConvertTables(pageResult.Tables, readResult);

            if (readResult != null)
            {
                RawExtractedPage = new RawExtractedPage(readResult);
            }
        }
        // Unsupervised
        internal ExtractedPage(PageResult_internal pageResult, ReadResult_internal readResult)
        {
            PageNumber = pageResult.Page;
            Fields     = ConvertFields(pageResult.KeyValuePairs, readResult);
            Tables     = ExtractedLayoutPage.ConvertTables(pageResult.Tables, readResult);

            if (readResult != null)
            {
                RawExtractedPage = new RawExtractedPage(readResult);
            }
        }
예제 #6
0
        internal RecognizedForm(PageResult_internal pageResult, IReadOnlyList <ReadResult_internal> readResults, int pageIndex)
        {
            // Recognized form from a model trained without labels.
            FormType  = $"form-{pageResult.ClusterId}";
            PageRange = new FormPageRange(pageResult.Page, pageResult.Page);
            Fields    = ConvertUnsupervisedFields(pageResult.Page, pageResult.KeyValuePairs, readResults);

            // For models trained without labels, the service treats every page as a separate form, so
            // we end up with a single page per form.

            Pages = new List <FormPage> {
                new FormPage(pageResult, readResults, pageIndex)
            };
        }
        internal static PageResult_internal DeserializePageResult_internal(JsonElement element)
        {
            PageResult_internal result = new PageResult_internal();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("page"))
                {
                    result.Page = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("clusterId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.ClusterId = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("keyValuePairs"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.KeyValuePairs = new List <KeyValuePair_internal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.KeyValuePairs.Add(KeyValuePair_internal.DeserializeKeyValuePair_internal(item));
                    }
                    continue;
                }
                if (property.NameEquals("tables"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.Tables = new List <DataTable_internal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.Tables.Add(DataTable_internal.DeserializeDataTable_internal(item));
                    }
                    continue;
                }
            }
            return(result);
        }
예제 #8
0
        internal FormPage(PageResult_internal pageResult, IReadOnlyList <ReadResult_internal> readResults, int pageIndex)
        {
            ReadResult_internal readResult = readResults[pageIndex];

            PageNumber = readResult.Page;
            TextAngle  = readResult.Angle;
            Width      = readResult.Width;
            Height     = readResult.Height;
            Unit       = readResult.Unit;
            Lines      = readResult.Lines != null
                ? ConvertLines(readResult.Lines, readResult.Page)
                : new List <FormLine>();

            Tables = pageResult?.Tables != null
                ? ConvertTables(pageResult, readResults, pageIndex)
                : new List <FormTable>();
        }
예제 #9
0
        internal FormPage(PageResult_internal pageResult, IReadOnlyList <ReadResult_internal> readResults, int pageIndex)
        {
            ReadResult_internal readResult = readResults[pageIndex];

            PageNumber = readResult.Page;

            // Workaround because the service can sometimes return angles between 180 and 360 (bug).
            // Currently tracked by: https://github.com/Azure/azure-sdk-for-net/issues/12319
            TextAngle = readResult.Angle <= 180.0f ? readResult.Angle : readResult.Angle - 360.0f;

            Width  = readResult.Width;
            Height = readResult.Height;
            Unit   = readResult.Unit;
            Lines  = readResult.Lines != null
                ? ConvertLines(readResult.Lines, readResult.Page)
                : new List <FormLine>();

            Tables = pageResult?.Tables != null
                ? ConvertTables(pageResult, readResults, pageIndex)
                : new List <FormTable>();
        }
예제 #10
0
        private IReadOnlyList <ExtractedPage> SetPages(ICollection <PageResult_internal> pageResults, ICollection <ReadResult_internal> readResults)
        {
            // TODO: Add validation and appropriate exception if these don't match.
            // https://github.com/Azure/azure-sdk-for-net/issues/10366
            Debug.Assert(pageResults.Count == readResults.Count);

            List <ExtractedPage> pages = new List <ExtractedPage>();

            for (int i = 0; i < pageResults.Count; i++)
            {
                PageResult_internal pageResult       = pageResults.ElementAt(i);
                ReadResult_internal rawExtractedPage = readResults.ElementAt(i);

                SetLearnedFormType(pageResult.ClusterId);

                ExtractedPage page = new ExtractedPage(pageResult, rawExtractedPage);
                pages.Add(page);
            }

            return(pages);
        }
예제 #11
0
        internal static AnalyzeResult_internal DeserializeAnalyzeResult_internal(JsonElement element)
        {
            AnalyzeResult_internal result = new AnalyzeResult_internal();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("version"))
                {
                    result.Version = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("readResults"))
                {
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.ReadResults.Add(ReadResult_internal.DeserializeReadResult_internal(item));
                    }
                    continue;
                }
                if (property.NameEquals("pageResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.PageResults = new List <PageResult_internal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.PageResults.Add(PageResult_internal.DeserializePageResult_internal(item));
                    }
                    continue;
                }
                if (property.NameEquals("documentResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.DocumentResults = new List <DocumentResult_internal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.DocumentResults.Add(DocumentResult_internal.DeserializeDocumentResult_internal(item));
                    }
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.Errors = new List <FormRecognizerError>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.Errors.Add(FormRecognizerError.DeserializeFormRecognizerError(item));
                    }
                    continue;
                }
            }
            return(result);
        }
예제 #12
0
        internal static AnalyzeResult_internal DeserializeAnalyzeResult_internal(JsonElement element)
        {
            string version = default;
            IReadOnlyList <ReadResult_internal>     readResults     = default;
            IReadOnlyList <PageResult_internal>     pageResults     = default;
            IReadOnlyList <DocumentResult_internal> documentResults = default;
            IReadOnlyList <FormRecognizerError>     errors          = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("version"))
                {
                    version = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("readResults"))
                {
                    List <ReadResult_internal> array = new List <ReadResult_internal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ReadResult_internal.DeserializeReadResult_internal(item));
                        }
                    }
                    readResults = array;
                    continue;
                }
                if (property.NameEquals("pageResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <PageResult_internal> array = new List <PageResult_internal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(PageResult_internal.DeserializePageResult_internal(item));
                        }
                    }
                    pageResults = array;
                    continue;
                }
                if (property.NameEquals("documentResults"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <DocumentResult_internal> array = new List <DocumentResult_internal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(DocumentResult_internal.DeserializeDocumentResult_internal(item));
                        }
                    }
                    documentResults = array;
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <FormRecognizerError> array = new List <FormRecognizerError>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(FormRecognizerError.DeserializeFormRecognizerError(item));
                        }
                    }
                    errors = array;
                    continue;
                }
            }
            return(new AnalyzeResult_internal(version, readResults, pageResults, documentResults, errors));
        }