Skip to content

✨ add support for us mail v3 #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/code_samples/us_mail_v3_async.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Mindee;
using Mindee.Input;
using Mindee.Product.Us.UsMail;

string apiKey = "my-api-key";
string filePath = "/path/to/the/file.ext";

// Construct a new client
MindeeClient mindeeClient = new MindeeClient(apiKey);

// Load an input source as a path string
// Other input types can be used, as mentioned in the docs
var inputSource = new LocalInputSource(filePath);

// Call the product asynchronously with auto-polling
var response = await mindeeClient
.EnqueueAndParseAsync<UsMailV3>(inputSource);

// Print a summary of all the predictions
System.Console.WriteLine(response.Document.ToString());

// Print only the document-level predictions
// System.Console.WriteLine(response.Document.Inference.Prediction.ToString());
50 changes: 38 additions & 12 deletions docs/us_mail_v2.md → docs/us_mail_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var inputSource = new LocalInputSource(filePath);

// Call the product asynchronously with auto-polling
var response = await mindeeClient
.EnqueueAndParseAsync<UsMailV2>(inputSource);
.EnqueueAndParseAsync<UsMailV3>(inputSource);

// Print a summary of all the predictions
System.Console.WriteLine(response.Document.ToString());
Expand All @@ -39,7 +39,20 @@ System.Console.WriteLine(response.Document.ToString());

**Output (RST):**
```rst
:Sender Name: zed
########
Document
########
:Mindee ID: f9c36f59-977d-4ddc-9f2d-31c294c456ac
:Filename: default_sample.jpg

Inference
#########
:Product: mindee/us_mail v3.0
:Rotation applied: Yes

Prediction
==========
:Sender Name: company zed
:Sender Address:
:City: Dallas
:Complete Address: 54321 Elm Street, Dallas, Texas 54321
Expand All @@ -48,11 +61,12 @@ System.Console.WriteLine(response.Document.ToString());
:Street: 54321 Elm Street
:Recipient Names: Jane Doe
:Recipient Addresses:
+-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+
| City | Complete Address | Is Address Change | Postal Code | Private Mailbox Number | State | Street |
+=================+=====================================+===================+=============+========================+=======+===========================+
| Detroit | 1234 Market Street PMB 4321, Det... | | 12345 | 4321 | MI | 1234 Market Street |
+-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+
+-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+-----------------+
| City | Complete Address | Is Address Change | Postal Code | Private Mailbox Number | State | Street | Unit |
+=================+=====================================+===================+=============+========================+=======+===========================+=================+
| Detroit | 1234 Market Street PMB 4321, Det... | False | 12345 | 4321 | MI | 1234 Market Street | |
+-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+-----------------+
:Return to Sender: False
```

# Field Types
Expand All @@ -78,13 +92,17 @@ The text field `StringField` extends `BaseField`, but also implements:
* **Value** (`string`): corresponds to the field value.
* **RawValue** (`string`): corresponds to the raw value as it appears on the document.

### BooleanField
The boolean field `BooleanField` extends BaseField, but also implements:
* **Value** (`bool?`): corresponds to the value of the field.

## Specific Fields
Fields which are specific to this product; they are not used in any other product.

### Recipient Addresses Field
The addresses of the recipients.

A `UsMailV2RecipientAddress` implements the following attributes:
A `UsMailV3RecipientAddress` implements the following attributes:

* **City** (`string`): The city of the recipient's address.
* **Complete** (`string`): The complete address of the recipient.
Expand All @@ -93,12 +111,13 @@ A `UsMailV2RecipientAddress` implements the following attributes:
* **PrivateMailboxNumber** (`string`): The private mailbox number of the recipient's address.
* **State** (`string`): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State.
* **Street** (`string`): The street of the recipient's address.
* **Unit** (`string`): The unit number of the recipient's address.
Fields which are specific to this product; they are not used in any other product.

### Sender Address Field
The address of the sender.

A `UsMailV2SenderAddress` implements the following attributes:
A `UsMailV3SenderAddress` implements the following attributes:

* **City** (`string`): The city of the sender's address.
* **Complete** (`string`): The complete address of the sender.
Expand All @@ -107,10 +126,17 @@ A `UsMailV2SenderAddress` implements the following attributes:
* **Street** (`string`): The street of the sender's address.

# Attributes
The following fields are extracted for US Mail V2:
The following fields are extracted for US Mail V3:

## Return to Sender
**IsReturnToSender**: Whether the mailing is marked as return to sender.

```csharp
System.Console.WriteLine(result.Document.Inference.Prediction.IsReturnToSender.Value);
```

## Recipient Addresses
**RecipientAddresses**(List<[UsMailV2RecipientAddress](#recipient-addresses-field)>): The addresses of the recipients.
**RecipientAddresses**(List<[UsMailV3RecipientAddress](#recipient-addresses-field)>): The addresses of the recipients.

```csharp
foreach (var RecipientAddressesElem in result.Document.Inference.Prediction.RecipientAddresses)
Expand All @@ -130,7 +156,7 @@ foreach (var RecipientNamesElem in result.Document.Inference.Prediction.Recipien
```

## Sender Address
**SenderAddress**([UsMailV2SenderAddress](#sender-address-field)): The address of the sender.
**SenderAddress**([UsMailV3SenderAddress](#sender-address-field)): The address of the sender.

```csharp
System.Console.WriteLine(result.Document.Inference.Prediction.SenderAddress.Value);
Expand Down
6 changes: 3 additions & 3 deletions src/Mindee.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
Mindee.Product.Us.BankCheck.BankCheckV1Document
>;
using PredictUsMailCommand = Mindee.Cli.PredictCommand<
Mindee.Product.Us.UsMail.UsMailV2,
Mindee.Product.Us.UsMail.UsMailV2Document,
Mindee.Product.Us.UsMail.UsMailV2Document
Mindee.Product.Us.UsMail.UsMailV3,
Mindee.Product.Us.UsMail.UsMailV3Document,
Mindee.Product.Us.UsMail.UsMailV3Document
>;
using PredictUsPayrollCheckRegisterCommand = Mindee.Cli.PredictCommand<
Mindee.Product.Us.PayrollCheckRegister.PayrollCheckRegisterV1,
Expand Down
20 changes: 20 additions & 0 deletions src/Mindee/Product/Us/UsMail/UsMailV3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;
using Mindee.Http;
using Mindee.Parsing.Common;

namespace Mindee.Product.Us.UsMail
{
/// <summary>
/// US Mail API version 3 inference prediction.
/// </summary>
[Endpoint("us_mail", "3")]
public sealed class UsMailV3 : Inference<UsMailV3Document, UsMailV3Document>
{
/// <summary>
/// The pages and the associated values which were detected on the document.
/// </summary>
[JsonPropertyName("pages")]
[JsonConverter(typeof(PagesJsonConverter<UsMailV3Document>))]
public override Pages<UsMailV3Document> Pages { get; set; }
}
}
63 changes: 63 additions & 0 deletions src/Mindee/Product/Us/UsMail/UsMailV3Document.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using Mindee.Parsing;
using Mindee.Parsing.Standard;

namespace Mindee.Product.Us.UsMail
{
/// <summary>
/// US Mail API version 3.0 document data.
/// </summary>
public class UsMailV3Document : IPrediction
{
/// <summary>
/// Whether the mailing is marked as return to sender.
/// </summary>
[JsonPropertyName("is_return_to_sender")]
public BooleanField IsReturnToSender { get; set; }

/// <summary>
/// The addresses of the recipients.
/// </summary>
[JsonPropertyName("recipient_addresses")]
[JsonConverter(typeof(ObjectListJsonConverter<UsMailV3RecipientAddresses, UsMailV3RecipientAddress>))]
public UsMailV3RecipientAddresses RecipientAddresses { get; set; }

/// <summary>
/// The names of the recipients.
/// </summary>
[JsonPropertyName("recipient_names")]
public IList<StringField> RecipientNames { get; set; } = new List<StringField>();

/// <summary>
/// The address of the sender.
/// </summary>
[JsonPropertyName("sender_address")]
public UsMailV3SenderAddress SenderAddress { get; set; }

/// <summary>
/// The name of the sender.
/// </summary>
[JsonPropertyName("sender_name")]
public StringField SenderName { get; set; }

/// <summary>
/// A prettier representation of the current model values.
/// </summary>
public override string ToString()
{
string recipientNames = string.Join(
"\n " + string.Concat(Enumerable.Repeat(" ", 17)),
RecipientNames.Select(item => item));
StringBuilder result = new StringBuilder();
result.Append($":Sender Name: {SenderName}\n");
result.Append($":Sender Address:{SenderAddress.ToFieldList()}");
result.Append($":Recipient Names: {recipientNames}\n");
result.Append($":Recipient Addresses:{RecipientAddresses}");
result.Append($":Return to Sender: {IsReturnToSender}\n");
return SummaryHelper.Clean(result.ToString());
}
}
}
Loading
Loading