internal FieldValue(FieldValue_internal fieldValue, IReadOnlyList <ReadResult> readResults) : this() { ValueType = fieldValue.Type; _fieldValue = fieldValue; _readResults = readResults; }
internal static DocumentResult_internal DeserializeDocumentResult_internal(JsonElement element) { DocumentResult_internal result = new DocumentResult_internal(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("docType")) { result.DocType = property.Value.GetString(); continue; } if (property.NameEquals("pageRange")) { foreach (var item in property.Value.EnumerateArray()) { result.PageRange.Add(item.GetInt32()); } continue; } if (property.NameEquals("fields")) { foreach (var property0 in property.Value.EnumerateObject()) { result.Fields.Add(property0.Name, FieldValue_internal.DeserializeFieldValue_internal(property0.Value)); } continue; } } return(result); }
internal FormField(string name, FieldValue_internal fieldValue, IReadOnlyList <ReadResult> readResults, bool isBusinessCard = default) { Confidence = fieldValue.Confidence ?? Constants.DefaultConfidenceValue; Name = name; LabelData = null; // Bounding box, page and text are not returned by the service in two scenarios: // - When this field is global and not associated with a specific page (e.g. ReceiptType). // - When this field is a collection, such as a list or dictionary. // // In these scenarios we do not set a ValueData. if (fieldValue.BoundingBox.Count == 0 && fieldValue.Page == null && fieldValue.Text == null) { ValueData = null; } else { IReadOnlyList <FormElement> fieldElements = ConvertTextReferences(fieldValue.Elements, readResults); // TODO: FormEnum<T> ? FieldBoundingBox boundingBox = new FieldBoundingBox(fieldValue.BoundingBox); int fieldPage = isBusinessCard ? CalculatePage(fieldValue) : fieldValue.Page.Value; ValueData = new FieldData(boundingBox, fieldPage, fieldValue.Text, fieldElements); } Value = new FieldValue(fieldValue, readResults, isBusinessCard); }
internal FormField(string name, FieldValue_internal fieldValue, IReadOnlyList <ReadResult> readResults) { Confidence = fieldValue.Confidence ?? Constants.DefaultConfidenceValue; Name = name; LabelData = null; // Bounding box, page and text are not returned by the service in two scenarios: // - When this field is global and not associated with a specific page (e.g. ReceiptType). // - When this field is a collection, such as a list or dictionary. // // In these scenarios we do not set a ValueData. if (fieldValue.BoundingBox.Count == 0 && fieldValue.Page == null && fieldValue.Text == null) { ValueData = null; } else { IReadOnlyList <FormElement> fieldElements = ConvertTextReferences(fieldValue.Elements, readResults); // TODO: FormEnum<T> ? FieldBoundingBox boundingBox = new FieldBoundingBox(fieldValue.BoundingBox); // Issue https://github.com/Azure/azure-sdk-for-net/issues/15845 int page = fieldValue.Page.HasValue ? fieldValue.Page.Value : 1; ValueData = new FieldData(boundingBox, page, fieldValue.Text, fieldElements); } Value = new FieldValue(fieldValue, readResults); }
internal FieldValue(FieldValue_internal fieldValue, IReadOnlyList <ReadResult> readResults, bool isBusinessCard) : this() { ValueType = fieldValue.Type; _fieldValue = fieldValue; _readResults = readResults; _isBusinessCard = isBusinessCard; }
internal static DocumentResult DeserializeDocumentResult(JsonElement element) { string docType = default; Optional <Guid> modelId = default; IReadOnlyList <int> pageRange = default; Optional <float> docTypeConfidence = default; IReadOnlyDictionary <string, FieldValue_internal> fields = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("docType")) { docType = property.Value.GetString(); continue; } if (property.NameEquals("modelId")) { modelId = property.Value.GetGuid(); continue; } if (property.NameEquals("pageRange")) { List <int> array = new List <int>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetInt32()); } pageRange = array; continue; } if (property.NameEquals("docTypeConfidence")) { docTypeConfidence = property.Value.GetSingle(); continue; } if (property.NameEquals("fields")) { Dictionary <string, FieldValue_internal> dictionary = new Dictionary <string, FieldValue_internal>(); foreach (var property0 in property.Value.EnumerateObject()) { if (property0.Value.ValueKind == JsonValueKind.Null) { dictionary.Add(property0.Name, null); } else { dictionary.Add(property0.Name, FieldValue_internal.DeserializeFieldValue_internal(property0.Value)); } } fields = dictionary; continue; } } return(new DocumentResult(docType, Optional.ToNullable(modelId), pageRange, Optional.ToNullable(docTypeConfidence), fields)); }
internal FormField(string name, FieldValue_internal fieldValue, IReadOnlyList <ReadResult_internal> readResults) { Confidence = fieldValue.Confidence ?? Constants.DefaultConfidenceValue; Name = name; LabelData = null; IReadOnlyList <FormElement> FormElement = fieldValue.Elements != null ? ConvertTextReferences(fieldValue.Elements, readResults) : new List <FormElement>(); // TODO: FormEnum<T> ? BoundingBox boundingBox = fieldValue.BoundingBox == null ? default : new BoundingBox(fieldValue.BoundingBox); ValueData = new FieldData(fieldValue.Text, fieldValue.Page ?? 0, boundingBox, FormElement); Value = new FieldValue(fieldValue, readResults); }
/// <summary> /// Business Cards pre-built model doesn't return a page number for the `ContactNames` field. /// This function looks into the FieldValue_internal to see if it corresponds to /// `ContactNames` and verifies that the page value before returning it. /// </summary> /// <returns>Page value if the field is `ContactNames` for Business cards. If not, defaults to 1.</returns> private static int CalculatePage(FieldValue_internal field) { int page = 1; if (field.Type == FieldValueType.Dictionary) { IReadOnlyDictionary <string, FieldValue_internal> possibleContactNamesField = field.ValueObject; if (possibleContactNamesField.Count == 2 && possibleContactNamesField.ContainsKey("FirstName") && possibleContactNamesField.ContainsKey("LastName")) { if (possibleContactNamesField["FirstName"].Page == possibleContactNamesField["LastName"].Page) { page = possibleContactNamesField["FirstName"].Page.Value; } } } return(page); }
internal FormField(string name, FieldValue_internal fieldValue, IReadOnlyList <ReadResult_internal> readResults) { Confidence = fieldValue.Confidence ?? Constants.DefaultConfidenceValue; Name = name; LabelText = null; IReadOnlyList <FormContent> formContent = default; if (fieldValue.Elements != null) { formContent = ConvertTextReferences(fieldValue.Elements, readResults); } // TODO: FormEnum<T> ? BoundingBox boundingBox = fieldValue.BoundingBox == null ? default : new BoundingBox(fieldValue.BoundingBox); ValueText = new FieldText(fieldValue.Text, fieldValue.Page ?? 0, boundingBox, formContent); Value = new FieldValue(fieldValue, readResults); }
internal static DocumentResult_internal DeserializeDocumentResult_internal(JsonElement element) { string docType = default; IReadOnlyList <int> pageRange = new List <int>(); IReadOnlyDictionary <string, FieldValue_internal> fields = new Dictionary <string, FieldValue_internal>(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("docType")) { docType = property.Value.GetString(); continue; } if (property.NameEquals("pageRange")) { List <int> array = new List <int>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetInt32()); } pageRange = array; continue; } if (property.NameEquals("fields")) { Dictionary <string, FieldValue_internal> dictionary = new Dictionary <string, FieldValue_internal>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, FieldValue_internal.DeserializeFieldValue_internal(property0.Value)); } fields = dictionary; continue; } } return(new DocumentResult_internal(docType, pageRange, fields)); }
/// <summary> /// Initializes a new instance of the <see cref="FieldValue"/> structure. This constructor /// is intended to be used for internal testing only. /// </summary> /// <param name="type">The field type.</param> internal FieldValue(FieldValueType type) : this() { ValueType = type; _fieldValue = new FieldValue_internal(type); }
internal static FieldValue_internal DeserializeFieldValue_internal(JsonElement element) { FieldValue_internal result = new FieldValue_internal(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type")) { result.Type = property.Value.GetString().ToFieldValueType(); continue; } if (property.NameEquals("valueString")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.ValueString = property.Value.GetString(); continue; } if (property.NameEquals("valueDate")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.ValueDate = property.Value.GetString(); continue; } if (property.NameEquals("valueTime")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.ValueTime = property.Value.GetString(); continue; } if (property.NameEquals("valuePhoneNumber")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.ValuePhoneNumber = property.Value.GetString(); continue; } if (property.NameEquals("valueNumber")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.ValueNumber = property.Value.GetSingle(); continue; } if (property.NameEquals("valueInteger")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.ValueInteger = property.Value.GetInt32(); continue; } if (property.NameEquals("valueArray")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.ValueArray = new List <FieldValue_internal>(); foreach (var item in property.Value.EnumerateArray()) { result.ValueArray.Add(DeserializeFieldValue_internal(item)); } continue; } if (property.NameEquals("valueObject")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.ValueObject = new Dictionary <string, FieldValue_internal>(); foreach (var property0 in property.Value.EnumerateObject()) { result.ValueObject.Add(property0.Name, DeserializeFieldValue_internal(property0.Value)); } continue; } if (property.NameEquals("text")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.Text = property.Value.GetString(); continue; } if (property.NameEquals("boundingBox")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.BoundingBox = new List <float>(); foreach (var item in property.Value.EnumerateArray()) { result.BoundingBox.Add(item.GetSingle()); } continue; } if (property.NameEquals("confidence")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.Confidence = property.Value.GetSingle(); continue; } if (property.NameEquals("elements")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.Elements = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { result.Elements.Add(item.GetString()); } continue; } if (property.NameEquals("page")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } result.Page = property.Value.GetInt32(); continue; } } return(result); }
internal FieldValue(FieldValue_internal fieldValue, IReadOnlyList <ReadResult_internal> readResults) { Type = fieldValue.Type; _fieldValue = fieldValue; _readResults = readResults; }
internal FieldValue(FieldValue_internal fieldValue, IReadOnlyList <ReadResult> readResults) : this(fieldValue, readResults, false) { }