Пример #1
0
        internal AnalyzeResult(ApiVersion apiVersion, string modelId, StringIndexType stringIndexType, string content, IEnumerable <DocumentPage> pages)
        {
            if (modelId == null)
            {
                throw new ArgumentNullException(nameof(modelId));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            if (pages == null)
            {
                throw new ArgumentNullException(nameof(pages));
            }

            ApiVersion      = apiVersion;
            ModelId         = modelId;
            StringIndexType = stringIndexType;
            Content         = content;
            Pages           = pages.ToList();
            Tables          = new ChangeTrackingList <DocumentTable>();
            KeyValuePairs   = new ChangeTrackingList <DocumentKeyValuePair>();
            Entities        = new ChangeTrackingList <DocumentEntity>();
            Styles          = new ChangeTrackingList <DocumentStyle>();
            Languages       = new ChangeTrackingList <DocumentLanguage>();
            Documents       = new ChangeTrackingList <AnalyzedDocument>();
        }
Пример #2
0
 internal AnalyzeResult(ApiVersion apiVersion, string modelId, StringIndexType stringIndexType, string content, IReadOnlyList <DocumentPage> pages, IReadOnlyList <DocumentTable> tables, IReadOnlyList <DocumentKeyValuePair> keyValuePairs, IReadOnlyList <DocumentEntity> entities, IReadOnlyList <DocumentStyle> styles, IReadOnlyList <AnalyzedDocument> documents)
 {
     ApiVersion      = apiVersion;
     ModelId         = modelId;
     StringIndexType = stringIndexType;
     Content         = content;
     Pages           = pages;
     Tables          = tables;
     KeyValuePairs   = keyValuePairs;
     Entities        = entities;
     Styles          = styles;
     Documents       = documents;
 }
        internal static AnalyzeResult DeserializeAnalyzeResult(JsonElement element)
        {
            ApiVersion      apiVersion         = default;
            string          modelId            = default;
            StringIndexType stringIndexType    = default;
            string          content            = default;
            IReadOnlyList <DocumentPage> pages = default;
            Optional <IReadOnlyList <DocumentTable> >        tables        = default;
            Optional <IReadOnlyList <DocumentKeyValuePair> > keyValuePairs = default;
            Optional <IReadOnlyList <DocumentEntity> >       entities      = default;
            Optional <IReadOnlyList <DocumentStyle> >        styles        = default;
            Optional <IReadOnlyList <DocumentLanguage> >     languages     = default;
            Optional <IReadOnlyList <AnalyzedDocument> >     documents     = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("apiVersion"))
                {
                    apiVersion = new ApiVersion(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("modelId"))
                {
                    modelId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("stringIndexType"))
                {
                    stringIndexType = new StringIndexType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("content"))
                {
                    content = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("pages"))
                {
                    List <DocumentPage> array = new List <DocumentPage>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentPage.DeserializeDocumentPage(item));
                    }
                    pages = array;
                    continue;
                }
                if (property.NameEquals("tables"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentTable> array = new List <DocumentTable>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentTable.DeserializeDocumentTable(item));
                    }
                    tables = array;
                    continue;
                }
                if (property.NameEquals("keyValuePairs"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentKeyValuePair> array = new List <DocumentKeyValuePair>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentKeyValuePair.DeserializeDocumentKeyValuePair(item));
                    }
                    keyValuePairs = array;
                    continue;
                }
                if (property.NameEquals("entities"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentEntity> array = new List <DocumentEntity>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentEntity.DeserializeDocumentEntity(item));
                    }
                    entities = array;
                    continue;
                }
                if (property.NameEquals("styles"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentStyle> array = new List <DocumentStyle>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentStyle.DeserializeDocumentStyle(item));
                    }
                    styles = array;
                    continue;
                }
                if (property.NameEquals("languages"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DocumentLanguage> array = new List <DocumentLanguage>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DocumentLanguage.DeserializeDocumentLanguage(item));
                    }
                    languages = array;
                    continue;
                }
                if (property.NameEquals("documents"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <AnalyzedDocument> array = new List <AnalyzedDocument>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(AnalyzedDocument.DeserializeAnalyzedDocument(item));
                    }
                    documents = array;
                    continue;
                }
            }
            return(new AnalyzeResult(apiVersion, modelId, stringIndexType, content, pages, Optional.ToList(tables), Optional.ToList(keyValuePairs), Optional.ToList(entities), Optional.ToList(styles), Optional.ToList(languages), Optional.ToList(documents)));
        }