| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | |
| | | 7 | | namespace Azure.AI.FormRecognizer.Models |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Represents a table recognized from the input document. |
| | | 11 | | /// </summary> |
| | | 12 | | public class FormTable |
| | | 13 | | { |
| | 128 | 14 | | internal FormTable(DataTable table, IReadOnlyList<ReadResult> readResults, int pageIndex) |
| | | 15 | | { |
| | 128 | 16 | | ReadResult readResult = readResults[pageIndex]; |
| | | 17 | | |
| | 128 | 18 | | PageNumber = readResult.Page; |
| | 128 | 19 | | ColumnCount = table.Columns; |
| | 128 | 20 | | RowCount = table.Rows; |
| | 128 | 21 | | Cells = ConvertCells(table.Cells, readResults, readResult.Page); |
| | 128 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// The 1-based number of the page in which this table is present. |
| | | 26 | | /// </summary> |
| | 100 | 27 | | public int PageNumber { get; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// A list of cells contained in this table. |
| | | 31 | | /// </summary> |
| | 216 | 32 | | public IReadOnlyList<FormTableCell> Cells { get; } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// The number of columns in this table. |
| | | 36 | | /// </summary> |
| | 388 | 37 | | public int ColumnCount { get; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// The number of rows in this table. |
| | | 41 | | /// </summary> |
| | 388 | 42 | | public int RowCount { get; } |
| | | 43 | | |
| | | 44 | | // TODO: implement table indexer |
| | | 45 | | // TODO: Handling column-span? |
| | | 46 | | // https://github.com/Azure/azure-sdk-for-net/issues/9975 |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// </summary> |
| | | 50 | | #pragma warning disable CA1822 // Mark as static |
| | | 51 | | internal FormTableCell this[int row, int column] |
| | | 52 | | #pragma warning restore CA1822 // Mark as static |
| | | 53 | | { |
| | | 54 | | get |
| | | 55 | | { |
| | | 56 | | #pragma warning disable CA1065 // Do not raise exceptions in unexpected locations |
| | 0 | 57 | | throw new NotImplementedException(); |
| | | 58 | | #pragma warning restore CA1065 // Do not raise exceptions in unexpected locations |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | set |
| | | 62 | | { |
| | 0 | 63 | | throw new NotImplementedException(); |
| | | 64 | | } |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | private static IReadOnlyList<FormTableCell> ConvertCells(IReadOnlyList<DataTableCell> cellsResult, IReadOnlyList |
| | | 68 | | { |
| | 128 | 69 | | List<FormTableCell> cells = new List<FormTableCell>(); |
| | | 70 | | |
| | 5136 | 71 | | foreach (var cellResult in cellsResult) |
| | | 72 | | { |
| | 2440 | 73 | | cells.Add(new FormTableCell(cellResult, readResults, pageNumber)); |
| | | 74 | | } |
| | | 75 | | |
| | 128 | 76 | | return cells; |
| | | 77 | | } |
| | | 78 | | } |
| | | 79 | | } |