internal ErrorResponse(ErrorInformation error) { if (error == null) { throw new ArgumentNullException(nameof(error)); } Error = error; }
internal static ErrorResponse DeserializeErrorResponse(JsonElement element) { ErrorInformation error = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("error")) { error = ErrorInformation.DeserializeErrorInformation(property.Value); continue; } } return(new ErrorResponse(error)); }
internal static TrainingDocumentInfo DeserializeTrainingDocumentInfo(JsonElement element) { string documentName = default; int pages = default; IReadOnlyList <ErrorInformation> errors = default; TrainStatus status = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("documentName")) { documentName = property.Value.GetString(); continue; } if (property.NameEquals("pages")) { pages = property.Value.GetInt32(); continue; } if (property.NameEquals("errors")) { List <ErrorInformation> array = new List <ErrorInformation>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(ErrorInformation.DeserializeErrorInformation(item)); } } errors = array; continue; } if (property.NameEquals("status")) { status = property.Value.GetString().ToTrainStatus(); continue; } } return(new TrainingDocumentInfo(documentName, pages, errors, status)); }
internal static CopyResult DeserializeCopyResult(JsonElement element) { Guid modelId = default; IReadOnlyList <ErrorInformation> errors = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("modelId")) { modelId = property.Value.GetGuid(); continue; } if (property.NameEquals("errors")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <ErrorInformation> array = new List <ErrorInformation>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(ErrorInformation.DeserializeErrorInformation(item)); } } errors = array; continue; } } return(new CopyResult(modelId, errors)); }
internal static TrainResult DeserializeTrainResult(JsonElement element) { IReadOnlyList <TrainingDocumentInfo> trainingDocuments = default; IReadOnlyList <FormFieldsReport> fields = default; float?averageModelAccuracy = default; IReadOnlyList <ErrorInformation> errors = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("trainingDocuments")) { List <TrainingDocumentInfo> array = new List <TrainingDocumentInfo>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(TrainingDocumentInfo.DeserializeTrainingDocumentInfo(item)); } } trainingDocuments = array; continue; } if (property.NameEquals("fields")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <FormFieldsReport> array = new List <FormFieldsReport>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(FormFieldsReport.DeserializeFormFieldsReport(item)); } } fields = array; continue; } if (property.NameEquals("averageModelAccuracy")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } averageModelAccuracy = property.Value.GetSingle(); continue; } if (property.NameEquals("errors")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <ErrorInformation> array = new List <ErrorInformation>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(ErrorInformation.DeserializeErrorInformation(item)); } } errors = array; continue; } } return(new TrainResult(trainingDocuments, fields, averageModelAccuracy, errors)); }
internal static AnalyzeResult DeserializeAnalyzeResult(JsonElement element) { string version = default; IReadOnlyList <ReadResult> readResults = default; IReadOnlyList <PageResult> pageResults = default; IReadOnlyList <DocumentResult> documentResults = default; IReadOnlyList <ErrorInformation> errors = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("version")) { version = property.Value.GetString(); continue; } if (property.NameEquals("readResults")) { List <ReadResult> array = new List <ReadResult>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(ReadResult.DeserializeReadResult(item)); } } readResults = array; continue; } if (property.NameEquals("pageResults")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <PageResult> array = new List <PageResult>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(PageResult.DeserializePageResult(item)); } } pageResults = array; continue; } if (property.NameEquals("documentResults")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <DocumentResult> array = new List <DocumentResult>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(DocumentResult.DeserializeDocumentResult(item)); } } documentResults = array; continue; } if (property.NameEquals("errors")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <ErrorInformation> array = new List <ErrorInformation>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(ErrorInformation.DeserializeErrorInformation(item)); } } errors = array; continue; } } return(new AnalyzeResult(version, readResults, pageResults, documentResults, errors)); }