internal DocumentSelectionMark(V3SelectionMarkState statePrivate, DocumentSpan span, float confidence)
 {
     StatePrivate       = statePrivate;
     BoundingBoxPrivate = new ChangeTrackingList <float>();
     Span       = span;
     Confidence = confidence;
 }
        internal static DocumentLanguage DeserializeDocumentLanguage(JsonElement element)
        {
            string languageCode = default;
            IReadOnlyList <DocumentSpan> spans = default;
            float confidence = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("languageCode"))
                {
                    languageCode = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
                if (property.NameEquals("confidence"))
                {
                    confidence = property.Value.GetSingle();
                    continue;
                }
            }
            return(new DocumentLanguage(languageCode, spans, confidence));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of DocumentSelectionMark. Used by the <see cref="DocumentAnalysisModelFactory"/>.
 /// </summary>
 internal DocumentSelectionMark(SelectionMarkState state, BoundingBox boundingBox, DocumentSpan span, float confidence)
 {
     State       = state;
     BoundingBox = boundingBox;
     Span        = span;
     Confidence  = confidence;
 }
Ejemplo n.º 4
0
 internal DocumentSelectionMark(V3SelectionMarkState statePrivate, IReadOnlyList <float> polygon, DocumentSpan span, float confidence)
 {
     StatePrivate = statePrivate;
     Polygon      = polygon;
     Span         = span;
     Confidence   = confidence;
 }
Ejemplo n.º 5
0
 internal DocumentWord(string content, IReadOnlyList <float> boundingBoxPrivate, DocumentSpan span, float confidence)
 {
     Content            = content;
     BoundingBoxPrivate = boundingBoxPrivate;
     Span       = span;
     Confidence = confidence;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of DocumentWord. Use for the <see cref="DocumentAnalysisModelFactory"/>.
 /// </summary>
 internal DocumentWord(string content, BoundingPolygon boundingPolygon, DocumentSpan span, float confidence)
 {
     Content         = content;
     BoundingPolygon = boundingPolygon;
     Span            = span;
     Confidence      = confidence;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of DocumentSelectionMark. Used by the <see cref="DocumentAnalysisModelFactory"/>.
 /// </summary>
 internal DocumentSelectionMark(SelectionMarkState state, BoundingPolygon boundingPolygon, DocumentSpan span, float confidence)
 {
     State           = state;
     BoundingPolygon = boundingPolygon;
     Span            = span;
     Confidence      = confidence;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of DocumentWord. Use for the <see cref="DocumentAnalysisModelFactory"/>.
 /// </summary>
 internal DocumentWord(string content, BoundingBox boundingBox, DocumentSpan span, float confidence)
 {
     Content     = content;
     BoundingBox = boundingBox;
     Span        = span;
     Confidence  = confidence;
 }
Ejemplo n.º 9
0
 internal DocumentImage(IReadOnlyList <float> polygon, DocumentSpan span, int pageRef, float confidence)
 {
     Polygon    = polygon;
     Span       = span;
     PageRef    = pageRef;
     Confidence = confidence;
 }
Ejemplo n.º 10
0
 internal DocumentImage(DocumentSpan span, int pageRef, float confidence)
 {
     Polygon    = new ChangeTrackingList <float>();
     Span       = span;
     PageRef    = pageRef;
     Confidence = confidence;
 }
Ejemplo n.º 11
0
 internal DocumentWord(string content, IReadOnlyList <float> polygon, DocumentSpan span, float confidence)
 {
     Content    = content;
     Polygon    = polygon;
     Span       = span;
     Confidence = confidence;
 }
 internal DocumentSelectionMark(V3SelectionMarkState statePrivate, IReadOnlyList <float> boundingBoxPrivate, DocumentSpan span, float confidence)
 {
     StatePrivate       = statePrivate;
     BoundingBoxPrivate = boundingBoxPrivate;
     Span       = span;
     Confidence = confidence;
 }
        internal static DocumentEntity DeserializeDocumentEntity(JsonElement element)
        {
            string            category    = default;
            Optional <string> subCategory = default;
            string            content     = default;
            Optional <IReadOnlyList <BoundingRegion> > boundingRegions = default;
            IReadOnlyList <DocumentSpan> spans = default;
            float confidence = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("category"))
                {
                    category = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("subCategory"))
                {
                    subCategory = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("content"))
                {
                    content = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingRegions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <BoundingRegion> array = new List <BoundingRegion>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(BoundingRegion.DeserializeBoundingRegion(item));
                    }
                    boundingRegions = array;
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
                if (property.NameEquals("confidence"))
                {
                    confidence = property.Value.GetSingle();
                    continue;
                }
            }
            return(new DocumentEntity(category, subCategory.Value, content, Optional.ToList(boundingRegions), spans, confidence));
        }
Ejemplo n.º 14
0
        internal static DocumentTable DeserializeDocumentTable(JsonElement element)
        {
            int rowCount    = default;
            int columnCount = default;
            IReadOnlyList <DocumentTableCell>          cells           = default;
            Optional <IReadOnlyList <BoundingRegion> > boundingRegions = default;
            IReadOnlyList <DocumentSpan> spans = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("rowCount"))
                {
                    rowCount = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("columnCount"))
                {
                    columnCount = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("cells"))
                {
                    List <DocumentTableCell> array = new List <DocumentTableCell>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentTableCell.DeserializeDocumentTableCell(item));
                    }
                    cells = array;
                    continue;
                }
                if (property.NameEquals("boundingRegions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <BoundingRegion> array = new List <BoundingRegion>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(BoundingRegion.DeserializeBoundingRegion(item));
                    }
                    boundingRegions = array;
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
            }
            return(new DocumentTable(rowCount, columnCount, cells, Optional.ToList(boundingRegions), spans));
        }
        internal static AnalyzedDocument DeserializeAnalyzedDocument(JsonElement element)
        {
            string docType = default;
            Optional <IReadOnlyList <BoundingRegion> > boundingRegions = default;
            IReadOnlyList <DocumentSpan> spans = default;
            IReadOnlyDictionary <string, DocumentField> fields = default;
            float confidence = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("docType"))
                {
                    docType = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingRegions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <BoundingRegion> array = new List <BoundingRegion>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(BoundingRegion.DeserializeBoundingRegion(item));
                    }
                    boundingRegions = array;
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
                if (property.NameEquals("fields"))
                {
                    Dictionary <string, DocumentField> dictionary = new Dictionary <string, DocumentField>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, DocumentField.DeserializeDocumentField(property0.Value));
                    }
                    fields = dictionary;
                    continue;
                }
                if (property.NameEquals("confidence"))
                {
                    confidence = property.Value.GetSingle();
                    continue;
                }
            }
            return(new AnalyzedDocument(docType, Optional.ToList(boundingRegions), spans, fields, confidence));
        }
        internal DocumentSelectionMark(V3SelectionMarkState statePrivate, DocumentSpan span, float confidence)
        {
            if (span == null)
            {
                throw new ArgumentNullException(nameof(span));
            }

            StatePrivate       = statePrivate;
            BoundingBoxPrivate = new ChangeTrackingList <float>();
            Span       = span;
            Confidence = confidence;
        }
Ejemplo n.º 17
0
        internal DocumentWord(string content, DocumentSpan span, float confidence)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            Content            = content;
            BoundingBoxPrivate = new ChangeTrackingList <float>();
            Span       = span;
            Confidence = confidence;
        }
Ejemplo n.º 18
0
        internal static DocumentParagraph DeserializeDocumentParagraph(JsonElement element)
        {
            Optional <ParagraphRole> role = default;
            string content = default;
            Optional <IReadOnlyList <BoundingRegion> > boundingRegions = default;
            IReadOnlyList <DocumentSpan> spans = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("role"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    role = new ParagraphRole(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("content"))
                {
                    content = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingRegions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <BoundingRegion> array = new List <BoundingRegion>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(BoundingRegion.DeserializeBoundingRegion(item));
                    }
                    boundingRegions = array;
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
            }
            return(new DocumentParagraph(Optional.ToNullable(role), content, Optional.ToList(boundingRegions), spans));
        }
Ejemplo n.º 19
0
        internal static DocumentSelectionMark DeserializeDocumentSelectionMark(JsonElement element)
        {
            V3SelectionMarkState state = default;
            Optional <IReadOnlyList <float> > boundingBox = default;
            DocumentSpan span       = default;
            float        confidence = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("state"))
                {
                    state = new V3SelectionMarkState(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("boundingBox"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <float> array = new List <float>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetSingle());
                    }
                    boundingBox = array;
                    continue;
                }
                if (property.NameEquals("span"))
                {
                    span = DocumentSpan.DeserializeDocumentSpan(property.Value);
                    continue;
                }
                if (property.NameEquals("confidence"))
                {
                    confidence = property.Value.GetSingle();
                    continue;
                }
            }
            return(new DocumentSelectionMark(state, Optional.ToList(boundingBox), span, confidence));
        }
Ejemplo n.º 20
0
        internal static DocumentImage DeserializeDocumentImage(JsonElement element)
        {
            Optional <IReadOnlyList <float> > polygon = default;
            DocumentSpan span       = default;
            int          pageRef    = default;
            float        confidence = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("polygon"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <float> array = new List <float>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetSingle());
                    }
                    polygon = array;
                    continue;
                }
                if (property.NameEquals("span"))
                {
                    span = DocumentSpan.DeserializeDocumentSpan(property.Value);
                    continue;
                }
                if (property.NameEquals("pageRef"))
                {
                    pageRef = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("confidence"))
                {
                    confidence = property.Value.GetSingle();
                    continue;
                }
            }
            return(new DocumentImage(Optional.ToList(polygon), span, pageRef, confidence));
        }
Ejemplo n.º 21
0
        internal static DocumentLine DeserializeDocumentLine(JsonElement element)
        {
            string content = default;
            Optional <IReadOnlyList <float> > boundingBox = default;
            IReadOnlyList <DocumentSpan>      spans       = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("content"))
                {
                    content = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingBox"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <float> array = new List <float>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetSingle());
                    }
                    boundingBox = array;
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
            }
            return(new DocumentLine(content, Optional.ToList(boundingBox), spans));
        }
        internal static DocumentStyle DeserializeDocumentStyle(JsonElement element)
        {
            Optional <bool> isHandwritten      = default;
            IReadOnlyList <DocumentSpan> spans = default;
            float confidence = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("isHandwritten"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    isHandwritten = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
                if (property.NameEquals("confidence"))
                {
                    confidence = property.Value.GetSingle();
                    continue;
                }
            }
            return(new DocumentStyle(Optional.ToNullable(isHandwritten), spans, confidence));
        }
Ejemplo n.º 23
0
        internal static DocumentPage DeserializeDocumentPage(JsonElement element)
        {
            DocumentPageKind kind = default;
            int pageNumber        = default;
            Optional <float>                                  angle          = default;
            Optional <float>                                  width          = default;
            Optional <float>                                  height         = default;
            Optional <V3LengthUnit>                           unit           = default;
            IReadOnlyList <DocumentSpan>                      spans          = default;
            Optional <IReadOnlyList <DocumentWord> >          words          = default;
            Optional <IReadOnlyList <DocumentSelectionMark> > selectionMarks = default;
            Optional <IReadOnlyList <DocumentImage> >         images         = default;
            Optional <IReadOnlyList <DocumentLine> >          lines          = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("kind"))
                {
                    kind = new DocumentPageKind(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("pageNumber"))
                {
                    pageNumber = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("angle"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    angle = property.Value.GetSingle();
                    continue;
                }
                if (property.NameEquals("width"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    width = property.Value.GetSingle();
                    continue;
                }
                if (property.NameEquals("height"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    height = property.Value.GetSingle();
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    unit = new V3LengthUnit(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
                if (property.NameEquals("words"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentWord> array = new List <DocumentWord>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentWord.DeserializeDocumentWord(item));
                    }
                    words = array;
                    continue;
                }
                if (property.NameEquals("selectionMarks"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentSelectionMark> array = new List <DocumentSelectionMark>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSelectionMark.DeserializeDocumentSelectionMark(item));
                    }
                    selectionMarks = array;
                    continue;
                }
                if (property.NameEquals("images"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentImage> array = new List <DocumentImage>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentImage.DeserializeDocumentImage(item));
                    }
                    images = array;
                    continue;
                }
                if (property.NameEquals("lines"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentLine> array = new List <DocumentLine>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentLine.DeserializeDocumentLine(item));
                    }
                    lines = array;
                    continue;
                }
            }
            return(new DocumentPage(kind, pageNumber, Optional.ToNullable(angle), Optional.ToNullable(width), Optional.ToNullable(height), Optional.ToNullable(unit), spans, Optional.ToList(words), Optional.ToList(selectionMarks), Optional.ToList(images), Optional.ToList(lines)));
        }
Ejemplo n.º 24
0
        internal static DocumentTableCell DeserializeDocumentTableCell(JsonElement element)
        {
            Optional <DocumentTableCellKind> kind = default;
            int            rowIndex    = default;
            int            columnIndex = default;
            Optional <int> rowSpan     = default;
            Optional <int> columnSpan  = default;
            string         content     = default;
            Optional <IReadOnlyList <BoundingRegion> > boundingRegions = default;
            IReadOnlyList <DocumentSpan> spans = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("kind"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    kind = new DocumentTableCellKind(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("rowIndex"))
                {
                    rowIndex = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("columnIndex"))
                {
                    columnIndex = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("rowSpan"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    rowSpan = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("columnSpan"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    columnSpan = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("content"))
                {
                    content = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingRegions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <BoundingRegion> array = new List <BoundingRegion>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(BoundingRegion.DeserializeBoundingRegion(item));
                    }
                    boundingRegions = array;
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
            }
            return(new DocumentTableCell(Optional.ToNullable(kind), rowIndex, columnIndex, Optional.ToNullable(rowSpan), Optional.ToNullable(columnSpan), content, Optional.ToList(boundingRegions), spans));
        }
        internal static DocumentField DeserializeDocumentField(JsonElement element)
        {
            DocumentFieldType                         type                      = default;
            Optional <string>                         valueString               = default;
            Optional <DateTimeOffset>                 valueDate                 = default;
            Optional <TimeSpan>                       valueTime                 = default;
            Optional <string>                         valuePhoneNumber          = default;
            Optional <double>                         valueNumber               = default;
            Optional <int>                            valueInteger              = default;
            Optional <V3SelectionMarkState>           valueSelectionMark        = default;
            Optional <DocumentSignatureType>          valueSignature            = default;
            Optional <string>                         valueCountryRegion        = default;
            Optional <IReadOnlyList <DocumentField> > valueArray                = default;
            Optional <IReadOnlyDictionary <string, DocumentField> > valueObject = default;
            Optional <CurrencyValue> valueCurrency = default;
            Optional <string>        content       = default;
            Optional <IReadOnlyList <BoundingRegion> > boundingRegions = default;
            Optional <IReadOnlyList <DocumentSpan> >   spans           = default;
            Optional <float> confidence = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString().ToDocumentFieldType();
                    continue;
                }
                if (property.NameEquals("valueString"))
                {
                    valueString = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("valueDate"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueDate = property.Value.GetDateTimeOffset("D");
                    continue;
                }
                if (property.NameEquals("valueTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueTime = property.Value.GetTimeSpan("T");
                    continue;
                }
                if (property.NameEquals("valuePhoneNumber"))
                {
                    valuePhoneNumber = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("valueNumber"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueNumber = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("valueInteger"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueInteger = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("valueSelectionMark"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueSelectionMark = new V3SelectionMarkState(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("valueSignature"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueSignature = new DocumentSignatureType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("valueCountryRegion"))
                {
                    valueCountryRegion = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("valueArray"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentField> array = new List <DocumentField>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DeserializeDocumentField(item));
                    }
                    valueArray = array;
                    continue;
                }
                if (property.NameEquals("valueObject"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    Dictionary <string, DocumentField> dictionary = new Dictionary <string, DocumentField>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, DeserializeDocumentField(property0.Value));
                    }
                    valueObject = dictionary;
                    continue;
                }
                if (property.NameEquals("valueCurrency"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueCurrency = CurrencyValue.DeserializeCurrencyValue(property.Value);
                    continue;
                }
                if (property.NameEquals("content"))
                {
                    content = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingRegions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <BoundingRegion> array = new List <BoundingRegion>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(BoundingRegion.DeserializeBoundingRegion(item));
                    }
                    boundingRegions = array;
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
                if (property.NameEquals("confidence"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    confidence = property.Value.GetSingle();
                    continue;
                }
            }
            return(new DocumentField(type, valueString.Value, Optional.ToNullable(valueDate), Optional.ToNullable(valueTime), valuePhoneNumber.Value, Optional.ToNullable(valueNumber), Optional.ToNullable(valueInteger), Optional.ToNullable(valueSelectionMark), Optional.ToNullable(valueSignature), valueCountryRegion.Value, Optional.ToList(valueArray), Optional.ToDictionary(valueObject), Optional.ToNullable(valueCurrency), content.Value, Optional.ToList(boundingRegions), Optional.ToList(spans), Optional.ToNullable(confidence)));
        }
Ejemplo n.º 26
0
        internal static DocumentPage DeserializeDocumentPage(JsonElement element)
        {
            int          pageNumber            = default;
            float        angle                 = default;
            float        width                 = default;
            float        height                = default;
            V3LengthUnit unit                  = default;
            IReadOnlyList <DocumentSpan> spans = default;
            IReadOnlyList <DocumentWord> words = default;
            Optional <IReadOnlyList <DocumentSelectionMark> > selectionMarks = default;
            IReadOnlyList <DocumentLine> lines = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("pageNumber"))
                {
                    pageNumber = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("angle"))
                {
                    angle = property.Value.GetSingle();
                    continue;
                }
                if (property.NameEquals("width"))
                {
                    width = property.Value.GetSingle();
                    continue;
                }
                if (property.NameEquals("height"))
                {
                    height = property.Value.GetSingle();
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    unit = new V3LengthUnit(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("spans"))
                {
                    List <DocumentSpan> array = new List <DocumentSpan>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSpan.DeserializeDocumentSpan(item));
                    }
                    spans = array;
                    continue;
                }
                if (property.NameEquals("words"))
                {
                    List <DocumentWord> array = new List <DocumentWord>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentWord.DeserializeDocumentWord(item));
                    }
                    words = array;
                    continue;
                }
                if (property.NameEquals("selectionMarks"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentSelectionMark> array = new List <DocumentSelectionMark>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentSelectionMark.DeserializeDocumentSelectionMark(item));
                    }
                    selectionMarks = array;
                    continue;
                }
                if (property.NameEquals("lines"))
                {
                    List <DocumentLine> array = new List <DocumentLine>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentLine.DeserializeDocumentLine(item));
                    }
                    lines = array;
                    continue;
                }
            }
            return(new DocumentPage(pageNumber, angle, width, height, unit, spans, words, Optional.ToList(selectionMarks), lines));
        }