Пример #1
0
 internal DocumentField(DocumentFieldType valueType)
 {
     ValueType       = valueType;
     ValueArray      = new ChangeTrackingList <DocumentField>();
     ValueObject     = new ChangeTrackingDictionary <string, DocumentField>();
     BoundingRegions = new ChangeTrackingList <BoundingRegion>();
     Spans           = new ChangeTrackingList <DocumentSpan>();
 }
Пример #2
0
 internal DocumentFieldSchema(DocumentFieldType type, string description, string example, DocumentFieldSchema items, IReadOnlyDictionary <string, DocumentFieldSchema> properties)
 {
     Type        = type;
     Description = description;
     Example     = example;
     Items       = items;
     Properties  = properties;
 }
Пример #3
0
        internal static DocumentFieldSchema DeserializeDocumentFieldSchema(JsonElement element)
        {
            DocumentFieldType type               = default;
            Optional <string> description        = default;
            Optional <string> example            = default;
            Optional <DocumentFieldSchema> items = default;
            Optional <IReadOnlyDictionary <string, DocumentFieldSchema> > properties = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString().ToDocumentFieldType();
                    continue;
                }
                if (property.NameEquals("description"))
                {
                    description = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("example"))
                {
                    example = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("items"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    items = DeserializeDocumentFieldSchema(property.Value);
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    Dictionary <string, DocumentFieldSchema> dictionary = new Dictionary <string, DocumentFieldSchema>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, DeserializeDocumentFieldSchema(property0.Value));
                    }
                    properties = dictionary;
                    continue;
                }
            }
            return(new DocumentFieldSchema(type, description.Value, example.Value, items.Value, Optional.ToDictionary(properties)));
        }
Пример #4
0
 internal DocumentField(DocumentFieldType valueType, string valueString, DateTimeOffset?valueDate, TimeSpan?valueTime, string valuePhoneNumber, double?valueNumber, int?valueInteger, V3SelectionMarkState?valueSelectionMarkPrivate, DocumentSignatureType?valueSignature, string valueCountryRegion, IReadOnlyList <DocumentField> valueArray, IReadOnlyDictionary <string, DocumentField> valueObject, string content, IReadOnlyList <BoundingRegion> boundingRegions, IReadOnlyList <DocumentSpan> spans, float?confidence)
 {
     ValueType                 = valueType;
     ValueString               = valueString;
     ValueDate                 = valueDate;
     ValueTime                 = valueTime;
     ValuePhoneNumber          = valuePhoneNumber;
     ValueNumber               = valueNumber;
     ValueInteger              = valueInteger;
     ValueSelectionMarkPrivate = valueSelectionMarkPrivate;
     ValueSignature            = valueSignature;
     ValueCountryRegion        = valueCountryRegion;
     ValueArray                = valueArray;
     ValueObject               = valueObject;
     Content         = content;
     BoundingRegions = boundingRegions;
     Spans           = spans;
     Confidence      = confidence;
 }
        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)));
        }
Пример #6
0
 public static string ToSerialString(this DocumentFieldType value) => value switch
 {
Пример #7
0
 internal DocumentFieldSchema(DocumentFieldType type)
 {
     Type       = type;
     Properties = new ChangeTrackingDictionary <string, DocumentFieldSchema>();
 }