Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of DocumentPage. Used by the <see cref="DocumentAnalysisModelFactory"/>.
 /// </summary>
 internal DocumentPage(DocumentPageKind kind, int pageNumber, float?angle, float?width, float?height, LengthUnit?unit, IReadOnlyList <DocumentSpan> spans, IReadOnlyList <DocumentWord> words, IReadOnlyList <DocumentSelectionMark> selectionMarks, IReadOnlyList <DocumentLine> lines)
 {
     Kind           = kind;
     PageNumber     = pageNumber;
     Angle          = angle;
     Width          = width;
     Height         = height;
     Unit           = unit;
     Spans          = spans;
     Words          = words;
     SelectionMarks = selectionMarks;
     Lines          = lines;
 }
Exemplo n.º 2
0
        internal DocumentPage(DocumentPageKind kind, int pageNumber, IEnumerable <DocumentSpan> spans)
        {
            if (spans == null)
            {
                throw new ArgumentNullException(nameof(spans));
            }

            Kind           = kind;
            PageNumber     = pageNumber;
            Spans          = spans.ToList();
            Words          = new ChangeTrackingList <DocumentWord>();
            SelectionMarks = new ChangeTrackingList <DocumentSelectionMark>();
            Images         = new ChangeTrackingList <DocumentImage>();
            Lines          = new ChangeTrackingList <DocumentLine>();
        }
Exemplo n.º 3
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)));
        }