Пример #1
0
        internal FormField(string name, FieldValue_internal fieldValue, IReadOnlyList <ReadResult> readResults, bool isBusinessCard = default)
        {
            Confidence = fieldValue.Confidence ?? Constants.DefaultConfidenceValue;
            Name       = name;
            LabelData  = null;

            // Bounding box, page and text are not returned by the service in two scenarios:
            //   - When this field is global and not associated with a specific page (e.g. ReceiptType).
            //   - When this field is a collection, such as a list or dictionary.
            //
            // In these scenarios we do not set a ValueData.

            if (fieldValue.BoundingBox.Count == 0 && fieldValue.Page == null && fieldValue.Text == null)
            {
                ValueData = null;
            }
            else
            {
                IReadOnlyList <FormElement> fieldElements = ConvertTextReferences(fieldValue.Elements, readResults);

                // TODO: FormEnum<T> ?
                FieldBoundingBox boundingBox = new FieldBoundingBox(fieldValue.BoundingBox);

                int fieldPage = isBusinessCard ? CalculatePage(fieldValue) : fieldValue.Page.Value;

                ValueData = new FieldData(boundingBox, fieldPage, fieldValue.Text, fieldElements);
            }

            Value = new FieldValue(fieldValue, readResults, isBusinessCard);
        }
Пример #2
0
        internal FormField(string name, FieldValue_internal fieldValue, IReadOnlyList <ReadResult> readResults)
        {
            Confidence = fieldValue.Confidence ?? Constants.DefaultConfidenceValue;
            Name       = name;
            LabelData  = null;

            // Bounding box, page and text are not returned by the service in two scenarios:
            //   - When this field is global and not associated with a specific page (e.g. ReceiptType).
            //   - When this field is a collection, such as a list or dictionary.
            //
            // In these scenarios we do not set a ValueData.

            if (fieldValue.BoundingBox.Count == 0 && fieldValue.Page == null && fieldValue.Text == null)
            {
                ValueData = null;
            }
            else
            {
                IReadOnlyList <FormElement> fieldElements = ConvertTextReferences(fieldValue.Elements, readResults);

                // TODO: FormEnum<T> ?
                FieldBoundingBox boundingBox = new FieldBoundingBox(fieldValue.BoundingBox);

                // Issue https://github.com/Azure/azure-sdk-for-net/issues/15845
                int page = fieldValue.Page.HasValue ? fieldValue.Page.Value : 1;

                ValueData = new FieldData(boundingBox, page, fieldValue.Text, fieldElements);
            }

            Value = new FieldValue(fieldValue, readResults);
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormTable"/> class.
 /// </summary>
 /// <param name="pageNumber">The 1-based number of the page in which this table is present.</param>
 /// <param name="columnCount">The number of columns in this table.</param>
 /// <param name="rowCount">The number of rows in this table.</param>
 /// <param name="cells">A list of cells contained in this table.</param>
 /// <param name="boundingBox">The quadrilateral bounding box that outlines the table.</param>
 internal FormTable(int pageNumber, int columnCount, int rowCount, IReadOnlyList <FormTableCell> cells, FieldBoundingBox boundingBox)
 {
     PageNumber  = pageNumber;
     ColumnCount = columnCount;
     RowCount    = rowCount;
     Cells       = cells;
     BoundingBox = boundingBox;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormTableCell"/> class.
 /// </summary>
 /// <param name="boundingBox">The quadrilateral bounding box that outlines the text of this element.</param>
 /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
 /// <param name="text">The text of this form element.</param>
 /// <param name="columnIndex">The column index of the cell.</param>
 /// <param name="rowIndex">The row index of the cell.</param>
 /// <param name="columnSpan">The number of columns spanned by this cell.</param>
 /// <param name="rowSpan">The number of rows spanned by this cell.</param>
 /// <param name="isHeader"><c>true</c> if this cell is a header cell. Otherwise, <c>false</c>.</param>
 /// <param name="isFooter"><c>true</c> if this cell is a footer cell. Otherwise, <c>false</c>.</param>
 /// <param name="confidence">Measures the degree of certainty of the recognition result.</param>
 /// <param name="fieldElements">A list of references to the field elements constituting this cell.</param>
 internal FormTableCell(FieldBoundingBox boundingBox, int pageNumber, string text, int columnIndex, int rowIndex, int columnSpan, int rowSpan, bool isHeader, bool isFooter, float confidence, IReadOnlyList <FormElement> fieldElements)
     : base(boundingBox, pageNumber, text)
 {
     ColumnIndex   = columnIndex;
     RowIndex      = rowIndex;
     ColumnSpan    = columnSpan;
     RowSpan       = rowSpan;
     IsHeader      = isHeader;
     IsFooter      = isFooter;
     Confidence    = confidence;
     FieldElements = fieldElements;
 }
Пример #5
0
        internal FormField(string name, int pageNumber, KeyValuePair field, IReadOnlyList <ReadResult> readResults)
        {
            Confidence = field.Confidence;
            Name       = name;

            FieldBoundingBox labelBoundingBox = field.Key.BoundingBox == null ? default : new FieldBoundingBox(field.Key.BoundingBox);
                                                IReadOnlyList <FormElement> labelFormElement = field.Key.Elements != null
                ? ConvertTextReferences(field.Key.Elements, readResults)
                : new List <FormElement>();

                                                LabelData = new FieldData(labelBoundingBox, pageNumber, field.Key.Text, labelFormElement);

                                                FieldBoundingBox valueBoundingBox = field.Value.BoundingBox == null ? default : new FieldBoundingBox(field.Value.BoundingBox);
                                                                                    IReadOnlyList <FormElement> valueFormElement = field.Value.Elements != null
                ? ConvertTextReferences(field.Value.Elements, readResults)
                : new List <FormElement>();

                                                                                    ValueData = new FieldData(valueBoundingBox, pageNumber, field.Value.Text, valueFormElement);

                                                                                    Value = new FieldValue(new FieldValue_internal(field.Value.Text), readResults);
        }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormRecognizer.Models.FormWord"/> class.
 /// </summary>
 /// <param name="boundingBox">The quadrilateral bounding box that outlines the text of this element.</param>
 /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
 /// <param name="text">The text of this form element.</param>
 /// <param name="confidence">Measures the degree of certainty of the recognition result.</param>
 /// <returns>A new <see cref="FormRecognizer.Models.FormWord"/> instance for mocking.</returns>
 public static FormWord FormWord(FieldBoundingBox boundingBox, int pageNumber, string text, float confidence) =>
 new FormWord(boundingBox, pageNumber, text, confidence);
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormRecognizer.Models.FormTableCell"/> class.
        /// </summary>
        /// <param name="boundingBox">The quadrilateral bounding box that outlines the text of this element.</param>
        /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
        /// <param name="text">The text of this form element.</param>
        /// <param name="columnIndex">The column index of the cell.</param>
        /// <param name="rowIndex">The row index of the cell.</param>
        /// <param name="columnSpan">The number of columns spanned by this cell.</param>
        /// <param name="rowSpan">The number of rows spanned by this cell.</param>
        /// <param name="isHeader"><c>true</c> if this cell is a header cell. Otherwise, <c>false</c>.</param>
        /// <param name="isFooter"><c>true</c> if this cell is a footer cell. Otherwise, <c>false</c>.</param>
        /// <param name="confidence">Measures the degree of certainty of the recognition result.</param>
        /// <param name="fieldElements">A list of references to the field elements constituting this cell.</param>
        /// <returns>A new <see cref="FormRecognizer.Models.FormTableCell"/> instance for mocking.</returns>
        public static FormTableCell FormTableCell(FieldBoundingBox boundingBox, int pageNumber, string text, int columnIndex, int rowIndex, int columnSpan, int rowSpan, bool isHeader, bool isFooter, float confidence, IReadOnlyList <FormElement> fieldElements)
        {
            fieldElements = fieldElements?.ToList();

            return(new FormTableCell(boundingBox, pageNumber, text, columnIndex, rowIndex, columnSpan, rowSpan, isHeader, isFooter, confidence, fieldElements));
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormRecognizer.Models.FormTable"/> class.
        /// </summary>
        /// <param name="pageNumber">The 1-based number of the page in which this table is present.</param>
        /// <param name="columnCount">The number of columns in this table.</param>
        /// <param name="rowCount">The number of rows in this table.</param>
        /// <param name="cells">A list of cells contained in this table.</param>
        /// <param name="boundingBox">The quadrilateral bounding box that outlines the table.</param>
        /// <returns>A new <see cref="FormRecognizer.Models.FormTable"/> instance for mocking.</returns>
        public static FormTable FormTable(int pageNumber, int columnCount, int rowCount, IReadOnlyList <FormTableCell> cells, FieldBoundingBox boundingBox)
        {
            cells = cells?.ToList();

            return(new FormTable(pageNumber, columnCount, rowCount, cells, boundingBox));
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormRecognizer.Models.FormSelectionMark"/> class.
 /// </summary>
 /// <param name="boundingBox">The quadrilateral bounding box that outlines the element.</param>
 /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
 /// <param name="text">The text of selection mark value.</param>
 /// <param name="confidence">Measures the degree of certainty of the recognition result.</param>
 /// <param name="state">Selection mark state value.</param>
 /// <returns>A new <see cref="FormRecognizer.Models.FormSelectionMark"/> instance for mocking.</returns>
 public static FormSelectionMark FormSelectionMark(FieldBoundingBox boundingBox, int pageNumber, string text, float confidence, SelectionMarkState state) =>
 new FormSelectionMark(boundingBox, pageNumber, text, confidence, state);
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormRecognizer.Models.FormLine"/> class.
        /// </summary>
        /// <param name="boundingBox">The quadrilateral bounding box that outlines the text of this element.</param>
        /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
        /// <param name="text">The text of this form element.</param>
        /// <param name="words">A list of the words that make up the line.</param>
        /// <param name="appearance">An object representing the appearance of the text line.</param>
        /// <returns>A new <see cref="FormRecognizer.Models.FormLine"/> instance for mocking.</returns>
        public static FormLine FormLine(FieldBoundingBox boundingBox, int pageNumber, string text, IReadOnlyList <FormWord> words, TextAppearance appearance)
        {
            words = words?.ToList();

            return(new FormLine(boundingBox, pageNumber, text, words, appearance));
        }
Пример #11
0
 public static FormLine FormLine(FieldBoundingBox boundingBox, int pageNumber, string text, IReadOnlyList <FormWord> words) =>
 FormLine(boundingBox, pageNumber, text, words, default);
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormRecognizer.Models.FieldData"/> class.
        /// </summary>
        /// <param name="boundingBox">The quadrilateral bounding box that outlines the text of this element.</param>
        /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
        /// <param name="text">The text of this form element.</param>
        /// <param name="fieldElements">A list of references to the field elements constituting this data.</param>
        /// <returns>A new <see cref="FormRecognizer.Models.FieldData"/> instance for mocking.</returns>
        public static FieldData FieldData(FieldBoundingBox boundingBox, int pageNumber, string text, IReadOnlyList <FormElement> fieldElements)
        {
            fieldElements = fieldElements?.ToList();

            return(new FieldData(boundingBox, pageNumber, text, fieldElements));
        }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormLine"/> class.
 /// </summary>
 /// <param name="boundingBox">The quadrilateral bounding box that outlines the text of this element.</param>
 /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
 /// <param name="text">The text of this form element.</param>
 /// <param name="words">A list of the words that make up the line.</param>
 /// <param name="appearance">An object representing the appearance of the text line.</param>
 internal FormLine(FieldBoundingBox boundingBox, int pageNumber, string text, IReadOnlyList <FormWord> words, TextAppearance appearance)
     : base(boundingBox, pageNumber, text)
 {
     Words      = words;
     Appearance = appearance;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormLine"/> class.
 /// </summary>
 /// <param name="boundingBox">The quadrilateral bounding box that outlines the text of this element.</param>
 /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
 /// <param name="text">The text of this form element.</param>
 /// <param name="words">A list of the words that make up the line.</param>
 internal FormLine(FieldBoundingBox boundingBox, int pageNumber, string text, IReadOnlyList <FormWord> words)
     : base(boundingBox, pageNumber, text)
 {
     Words = words;
 }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FieldData"/> class.
 /// </summary>
 /// <param name="boundingBox">The quadrilateral bounding box that outlines the text of this element.</param>
 /// <param name="pageNumber">The 1-based number of the page in which this element is present.</param>
 /// <param name="text">The text of this form element.</param>
 /// <param name="fieldElements">A list of references to the field elements constituting this data.</param>
 internal FieldData(FieldBoundingBox boundingBox, int pageNumber, string text, IReadOnlyList <FormElement> fieldElements)
     : base(boundingBox, pageNumber, text)
 {
     FieldElements = fieldElements;
 }