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
11 changes: 11 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## Code Converting
- When given code in another language for conversion, keep the original's overall naming for class, variable, and function names.
Adjust as needed to conform to this project's Java conventions.

## Code Linting
- Run `prek run -a` to lint and format the code.

## Testing
- We do not support direct initialization of classes with a builder pattern.
When testing, these classes should only be initialized using the builder pattern.

## Releases
- A release must be in a separate branch called `release/X.X.X` where X.X.X is the version number.
- The version number is defined in `project.properties.revision` of the `pom.xml` file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mindee.v2.clientoptions;

import java.util.HashMap;
import java.util.Map;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
* Base parameters for classification-based utility products.
*/
@Getter
@EqualsAndHashCode(callSuper = true)
public abstract class BaseClassificationProductParameters extends BaseProductParameters {
/**
* Pass additional context to the extraction model chained to this utility inference.
*/
protected final String extractionTextContext;

protected BaseClassificationProductParameters(
String modelId,
String alias,
String[] webhookIds,
String extractionTextContext
) {
super(modelId, alias, webhookIds);
this.extractionTextContext = extractionTextContext;
}

@Override
public Map<String, String> getRequestParameters() {
var parameters = new HashMap<>(super.getRequestParameters());

if (this.getExtractionTextContext() != null) {
parameters.put("extraction_text_context", this.getExtractionTextContext());
}

return parameters;
}

protected static abstract class BaseBuilder<T extends BaseBuilder<T>>
extends BaseProductParameters.BaseBuilder<T> {
protected String extractionTextContext;

protected BaseBuilder(String modelId) {
super(modelId);
}

/** Pass additional context to the extraction model chained to this utility inference. */
public T extractionTextContext(String extractionTextContext) {
this.extractionTextContext = extractionTextContext;
return self();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.mindee.v2.product.classification.params;

import com.mindee.v2.clientoptions.BaseProductParameters;
import com.mindee.v2.clientoptions.BaseClassificationProductParameters;
import com.mindee.v2.product.ProductAttributes;

@ProductAttributes(slug = "classification")
public class ClassificationParameters extends BaseProductParameters {
public class ClassificationParameters extends BaseClassificationProductParameters {
public ClassificationParameters(String modelId, String alias, String[] webhookIds) {
super(modelId, alias, webhookIds);
this(modelId, alias, webhookIds, null);
}

public ClassificationParameters(
String modelId,
String alias,
String[] webhookIds,
String extractionTextContext
) {
super(modelId, alias, webhookIds, extractionTextContext);
}

/**
Expand All @@ -19,15 +28,16 @@ public static Builder builder(String modelId) {
return new Builder(modelId);
}

public static final class Builder extends BaseProductParameters.BaseBuilder<Builder> {
public static final class Builder
extends BaseClassificationProductParameters.BaseBuilder<Builder> {

Builder(String modelId) {
super(modelId);
}

/** Build an immutable {@link ClassificationParameters} instance. */
public ClassificationParameters build() {
return new ClassificationParameters(modelId, alias, webhookIds);
return new ClassificationParameters(modelId, alias, webhookIds, extractionTextContext);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.mindee.v2.product.crop.params;

import com.mindee.v2.clientoptions.BaseProductParameters;
import com.mindee.v2.clientoptions.BaseClassificationProductParameters;
import com.mindee.v2.product.ProductAttributes;

@ProductAttributes(slug = "crop")
public class CropParameters extends BaseProductParameters {
public class CropParameters extends BaseClassificationProductParameters {

public CropParameters(String modelId, String alias, String[] webhookIds) {
super(modelId, alias, webhookIds);
this(modelId, alias, webhookIds, null);
}

public CropParameters(
String modelId,
String alias,
String[] webhookIds,
String extractionTextContext
) {
super(modelId, alias, webhookIds, extractionTextContext);
}

/**
Expand All @@ -20,15 +29,16 @@ public static Builder builder(String modelId) {
return new Builder(modelId);
}

public static final class Builder extends BaseProductParameters.BaseBuilder<Builder> {
public static final class Builder
extends BaseClassificationProductParameters.BaseBuilder<Builder> {

Builder(String modelId) {
super(modelId);
}

/** Build an immutable {@link CropParameters} instance. */
public CropParameters build() {
return new CropParameters(modelId, alias, webhookIds);
return new CropParameters(modelId, alias, webhookIds, extractionTextContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AnnotatedDynamicField {

/**
* Constructor for a simple field.
*
*
* @param field the {@link AnnotatedSimpleField}
*/
public AnnotatedDynamicField(AnnotatedSimpleField field) {
Expand All @@ -54,7 +54,7 @@ public AnnotatedDynamicField(AnnotatedSimpleField field) {

/**
* Constructor for a list field.
*
*
* @param field the {@link AnnotatedListField}
*/
public AnnotatedDynamicField(AnnotatedListField field) {
Expand All @@ -66,7 +66,7 @@ public AnnotatedDynamicField(AnnotatedListField field) {

/**
* Constructor for an object field.
*
*
* @param field the {@link AnnotatedObjectField}
*/
public AnnotatedDynamicField(AnnotatedObjectField field) {
Expand All @@ -78,7 +78,7 @@ public AnnotatedDynamicField(AnnotatedObjectField field) {

/***
* Get the field for JSON serialization.
*
*
* @return the field:
* one of {@link AnnotatedSimpleField}, {@link AnnotatedListField}, or
* {@link AnnotatedObjectField}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AnnotatedListField extends AnnotatedBaseField {

/**
* Default constructor.
*
*
* @param items the list of {@link AnnotatedDynamicField}
*/
public AnnotatedListField(
Expand All @@ -44,7 +44,7 @@ public AnnotatedListField(

/**
* List of simple fields.
*
*
* @return the list of {@link AnnotatedSimpleField}
*/
@JsonIgnore
Expand All @@ -68,7 +68,7 @@ public List<AnnotatedSimpleField> getSimpleItems() {

/**
* List of object fields.
*
*
* @return the list of {@link AnnotatedObjectField}
*/
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AnnotatedObjectField extends AnnotatedBaseField {

/**
* Default constructor.
*
*
* @param fields Sub-fields of the field.
*/
public AnnotatedObjectField(AnnotatedFields fields, boolean selected, String guidelines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AnnotatedSimpleField extends AnnotatedBaseField {

/**
* Default constructor.
*
*
* @param value field value, one of: string, bool, int, double, null.
*/
public AnnotatedSimpleField(Object value, boolean selected, String guidelines) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.mindee.v2.product.split.params;

import com.mindee.v2.clientoptions.BaseProductParameters;
import com.mindee.v2.clientoptions.BaseClassificationProductParameters;
import com.mindee.v2.product.ProductAttributes;

@ProductAttributes(slug = "split")
public class SplitParameters extends BaseProductParameters {
public class SplitParameters extends BaseClassificationProductParameters {

public SplitParameters(String modelId, String alias, String[] webhookIds) {
super(modelId, alias, webhookIds);
this(modelId, alias, webhookIds, null);
}

public SplitParameters(
String modelId,
String alias,
String[] webhookIds,
String extractionTextContext
) {
super(modelId, alias, webhookIds, extractionTextContext);
}

/**
Expand All @@ -20,15 +29,16 @@ public static Builder builder(String modelId) {
return new Builder(modelId);
}

public static final class Builder extends BaseProductParameters.BaseBuilder<Builder> {
public static final class Builder
extends BaseClassificationProductParameters.BaseBuilder<Builder> {

Builder(String modelId) {
super(modelId);
}

/** Build an immutable {@link SplitParameters} instance. */
public SplitParameters build() {
return new SplitParameters(modelId, alias, webhookIds);
return new SplitParameters(modelId, alias, webhookIds, extractionTextContext);
}
}
}
18 changes: 18 additions & 0 deletions src/test/java/com/mindee/v2/product/ClassificationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import static com.mindee.TestingUtilities.getV2ProductPath;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import com.mindee.v2.parsing.LocalResponse;
import com.mindee.v2.product.classification.ClassificationResponse;
import com.mindee.v2.product.classification.params.ClassificationParameters;
import com.mindee.v2.product.extraction.ExtractionResponse;
import java.io.IOException;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -15,6 +17,22 @@

@DisplayName("MindeeV2 - Classification Response")
public class ClassificationTest {
@Test
@DisplayName("parameters should initialize with and without extraction context")
void parametersMustInit() {
var productParams = ClassificationParameters
.builder("invalid-model-id")
.extractionTextContext("context")
.build();
assertEquals("invalid-model-id", productParams.getModelId());
assertEquals("context", productParams.getExtractionTextContext());
assertEquals("context", productParams.getRequestParameters().get("extraction_text_context"));

var withoutContext = ClassificationParameters.builder("invalid-model-id").build();
assertNull(withoutContext.getExtractionTextContext());
assertFalse(withoutContext.getRequestParameters().containsKey("extraction_text_context"));
}

private ClassificationResponse loadResponse(String filePath) throws IOException {
var localResponse = new LocalResponse(getV2ProductPath(filePath));
return localResponse.deserializeResponse(ClassificationResponse.class);
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/mindee/v2/product/CropTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import static com.mindee.TestingUtilities.getResourcePath;
import static com.mindee.TestingUtilities.getV2ProductPath;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.mindee.input.LocalInputSource;
import com.mindee.v2.fileoperations.Crop;
import com.mindee.v2.parsing.LocalResponse;
import com.mindee.v2.product.crop.CropResponse;
import com.mindee.v2.product.crop.params.CropParameters;
import com.mindee.v2.product.extraction.ExtractionResponse;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -25,6 +28,22 @@
public class CropTest {
private static final Path outputPath = getResourcePath("output/v2/product/crop");

@Test
@DisplayName("parameters should initialize with and without extraction context")
void parametersMustInit() {
var productParams = CropParameters
.builder("invalid-model-id")
.extractionTextContext("context")
.build();
assertEquals("invalid-model-id", productParams.getModelId());
assertEquals("context", productParams.getExtractionTextContext());
assertEquals("context", productParams.getRequestParameters().get("extraction_text_context"));

var withoutContext = CropParameters.builder("invalid-model-id").build();
assertNull(withoutContext.getExtractionTextContext());
assertFalse(withoutContext.getRequestParameters().containsKey("extraction_text_context"));
}

@BeforeAll
public static void setup() throws IOException {
deleteRecursively(outputPath);
Expand Down
Loading