Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using Mindee.V2.Product.Extraction;

namespace Mindee.V2.Product.Classification
{
Expand All @@ -13,6 +14,12 @@ public class ClassificationClassifier
[JsonPropertyName("document_type")]
public string DocumentType { get; set; }

/// <summary>
/// The extraction response associated with the classification.
/// </summary>
[JsonPropertyName("extraction_response")]
public ExtractionResponse ExtractionResponse { get; set; }

/// <summary>
/// A prettier representation of the feature values.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Mindee/V2/Product/Crop/CropItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Mindee.Image;
using Mindee.Input;
using Mindee.V2.Parsing.Inference.Field;
using Mindee.V2.Product.Extraction;

namespace Mindee.V2.Product.Crop
{
Expand All @@ -25,6 +26,12 @@ public class CropItem
[JsonPropertyName("location")]
public FieldLocation Location { get; set; }

/// <summary>
/// The extraction response associated with the crop.
/// </summary>
[JsonPropertyName("extraction_response")]
public ExtractionResponse ExtractionResponse { get; set; }

/// <summary>
/// String representation of the crop item.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Mindee/V2/Product/Split/SplitRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json.Serialization;
using Mindee.Input;
using Mindee.Pdf;
using Mindee.V2.Product.Extraction;

namespace Mindee.V2.Product.Split
{
Expand All @@ -22,6 +23,12 @@ public class SplitRange
[JsonPropertyName("document_type")]
public string DocumentType { get; set; }

/// <summary>
/// The extraction response associated with the split.
/// </summary>
[JsonPropertyName("extraction_response")]
public ExtractionResponse ExtractionResponse { get; set; }

/// <summary>
/// String representation of the split item.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ClassificationTest()
public async Task Classification_DefaultSample_MustSucceed()
{
var inputSource = new LocalInputSource(
Constants.V2ProductDir + "classification/default_invoice.jpg");
Constants.V2ProductDir + "classification/default_sample.jpg");
var productParams = new ClassificationParameters(_classificationModelId);

var response = await _client.EnqueueAndGetResultAsync<ClassificationResponse>(
Expand All @@ -34,7 +34,7 @@ public async Task Classification_DefaultSample_MustSucceed()

var file = response.Inference.File;
Assert.NotNull(file);
Assert.Equal("default_invoice.jpg", file.Name);
Assert.Equal("default_sample.jpg", file.Name);

var result = response.Inference.Result;
Assert.NotNull(result);
Expand Down
30 changes: 29 additions & 1 deletion tests/Mindee.UnitTests/V2/Product/ClassificationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Mindee.V2.Product;
using Mindee.V2.Product.Classification;
using Mindee.V2.Product.Classification.Params;
using Mindee.V2.Product.Extraction;

namespace Mindee.UnitTests.V2.Product
{
Expand All @@ -23,7 +24,7 @@ public void Parameters_MustInit()
[Fact]
public void Classification_WhenSingle_MustHaveValidProperties()
{
var response = GetInference("classification/classification_single.json");
var response = GetInference("classification/default_sample.json");
AssertInferenceResponse(response);

var inference = response.Inference;
Expand All @@ -40,6 +41,33 @@ public void Classification_WhenSingle_MustHaveValidProperties()
Assert.Equal("invoice", classification.DocumentType);
}

[Fact]
public void Classification_WithExtraction_MustHaveValidProperties()
{
var response = GetInference("classification/default_sample_extraction.json");
Assert.NotNull(response.Inference);
Assert.Equal(
"invoice",
response.Inference.Result.Classification.DocumentType
);

ExtractionResponse extractionResponse = response
.Inference
.Result
.Classification
.ExtractionResponse;
Assert.NotNull(extractionResponse);
Assert.Equal(
"Jiro Doi",
extractionResponse
.Inference
.Result
.Fields["customer_name"]
.SimpleField
.Value
);
}

private static ClassificationResponse GetInference(string path)
{
var localResponse = new LocalResponse(
Expand Down
44 changes: 44 additions & 0 deletions tests/Mindee.UnitTests/V2/Product/CropTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,50 @@ public void Crop_WhenMultiple_MustHaveValidProperties()
Assert.Equal(new Point(0.547, 0.97), secondPolygon[3]);
}

[Fact(DisplayName = "extraction properties must be valid")]
public void Crop_WithExtraction_MustHaveValidProperties()
{
var response = GetInference("crop/default_sample_extraction.json");
Assert.NotNull(response.Inference);

var crops = response.Inference.Result.Crops;
Assert.Equal(2, crops.Count);

var crop0 = crops[0];
Assert.Equal("receipt", crop0.ObjectType);
Assert.NotNull(crop0.Location.Polygon);
Assert.Equal(0, crop0.Location.Page);

var extractionResponse0 = crop0.ExtractionResponse;
Assert.NotNull(extractionResponse0);
Assert.Equal(
"CHEZ ALAIN MIAM MIAM",
extractionResponse0
.Inference
.Result
.Fields["supplier_name"]
.SimpleField
.Value
);

var crop1 = crops[1];
Assert.Equal("receipt", crop1.ObjectType);
Assert.NotNull(crop1.Location.Polygon);
Assert.Equal(0, crop1.Location.Page);

var extractionResponse1 = crop1.ExtractionResponse;
Assert.NotNull(extractionResponse1);
Assert.Equal(
"La cerise sur la pizza",
extractionResponse1
.Inference
.Result
.Fields["supplier_name"]
.SimpleField
.Value
);
}

[Fact(DisplayName = "crop_single.rst – RST display must be parsed and exposed")]
public void RstDisplay_MustBeAccessible()
{
Expand Down
42 changes: 42 additions & 0 deletions tests/Mindee.UnitTests/V2/Product/SplitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,48 @@ public void Split_WhenMultiple_MustHaveValidProperties()
Assert.Equal(3, secondSplit.PageRange[1]);
}

[Fact]
public void Split_WithExtraction_MustHaveValidProperties()
{
var response = GetInference("split/default_sample_extraction.json");
Assert.NotNull(response.Inference);

var splits = response.Inference.Result.Splits;
Assert.Equal(2, splits.Count);

var split0 = splits[0];
Assert.Equal("invoice", split0.DocumentType);
Assert.Equal(0, split0.PageRange[0]);

var extractionResponse0 = split0.ExtractionResponse;
Assert.NotNull(extractionResponse0);
Assert.Equal(
"05 05 44 44 90",
extractionResponse0
.Inference
.Result
.Fields["supplier_phone_number"]
.SimpleField
.Value
);

var split1 = splits[1];
Assert.Equal("invoice", split1.DocumentType);
Assert.Equal(1, split1.PageRange[0]);

var extractionResponse1 = split1.ExtractionResponse;
Assert.NotNull(extractionResponse1);
Assert.Equal(
"416-555-1212",
extractionResponse1
.Inference
.Result
.Fields["supplier_phone_number"]
.SimpleField
.Value
);
}

private static SplitResponse GetInference(string path)
{
var localResponse = new LocalResponse(
Expand Down
Loading