Repository navigation
Data schema #370
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
Data schema #370
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/main/java/com/mindee/v2/product/extraction/params/DataSchema.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.mindee.v2.product.extraction.params; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.mindee.exceptions.MindeeInputException; | ||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| /** | ||
| * Modify the Data Schema. | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @EqualsAndHashCode | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public class DataSchema { | ||
|
|
||
| /** | ||
| * If set, completely replaces the data schema of the model. | ||
| */ | ||
| @JsonProperty("replace") | ||
| private DataSchemaReplace replace; | ||
|
|
||
| /** | ||
| * Construct a new instance from a DataSchemaReplace object. | ||
| * | ||
| * @param replace The replacement schema structure. | ||
| */ | ||
| public DataSchema(DataSchemaReplace replace) { | ||
| this.replace = replace; | ||
| } | ||
|
|
||
| /** | ||
| * Construct a new instance from a Map/Dictionary. | ||
| * | ||
| * @param dataSchema Dictionary containing the data schema configuration. | ||
| */ | ||
| public DataSchema(Map<String, Object> dataSchema) { | ||
| setup(dataSchema); | ||
| } | ||
|
|
||
| /** | ||
| * Construct a new instance from a JSON string. | ||
| * | ||
| * @param jsonString JSON string containing the data schema configuration. | ||
| */ | ||
| public DataSchema(String jsonString) { | ||
| if (jsonString == null || jsonString.trim().isEmpty()) { | ||
| return; | ||
| } | ||
| try { | ||
| var objectMapper = new ObjectMapper(); | ||
| Map<String, Object> dataSchema = objectMapper | ||
| .readValue(jsonString, new TypeReference<Map<String, Object>>() { | ||
| }); | ||
| setup(dataSchema); | ||
| } catch (IOException e) { | ||
| throw new MindeeInputException("Invalid Data Schema format.", e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Initializes the 'replace' property. | ||
| * | ||
| * @param dataSchema The map containing data schema configuration. | ||
| */ | ||
| private void setup(Map<String, Object> dataSchema) { | ||
| if (dataSchema == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (!dataSchema.containsKey("replace")) { | ||
| throw new MindeeInputException("Invalid Data Schema format."); | ||
| } | ||
|
|
||
| try { | ||
| var objectMapper = new ObjectMapper(); | ||
| this.replace = objectMapper.convertValue(dataSchema.get("replace"), DataSchemaReplace.class); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new MindeeInputException("Invalid Data Schema format.", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| try { | ||
| return new ObjectMapper().writeValueAsString(this); | ||
| } catch (JsonProcessingException e) { | ||
| return super.toString(); | ||
| } | ||
| } | ||
| } |
103 changes: 103 additions & 0 deletions
103
src/main/java/com/mindee/v2/product/extraction/params/DataSchemaField.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package com.mindee.v2.product.extraction.params; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| /** | ||
| * Data Schema Field. | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @EqualsAndHashCode | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| @JsonPropertyOrder( | ||
| { "name", "title", "is_array", "type", "description", "guidelines", "unique_values", | ||
| "nested_fields", "classification_values" } | ||
| ) | ||
| public class DataSchemaField { | ||
|
|
||
| /** | ||
| * Name of the field in the data schema. | ||
| */ | ||
| @JsonProperty("name") | ||
| private String name; | ||
|
|
||
| /** | ||
| * Display name for the field. Also impacts inference results. | ||
| */ | ||
| @JsonProperty("title") | ||
| private String title; | ||
|
|
||
| /** | ||
| * Whether this field can contain multiple values. | ||
| */ | ||
| @JsonProperty("is_array") | ||
| private boolean isArray; | ||
|
|
||
| /** | ||
| * Data type of the field. | ||
| */ | ||
| @JsonProperty("type") | ||
| private String type; | ||
|
|
||
| /** | ||
| * Detailed description of what this field represents. | ||
| */ | ||
| @JsonProperty("description") | ||
| private String description; | ||
|
|
||
| /** | ||
| * Optional extraction guidelines. | ||
| */ | ||
| @JsonProperty("guidelines") | ||
| private String guidelines; | ||
|
|
||
| /** | ||
| * Whether to remove duplicate values in the array. | ||
| * Only applicable if `is_array` is True. | ||
| */ | ||
| @JsonProperty("unique_values") | ||
| private Boolean uniqueValues; | ||
|
|
||
| /** | ||
| * Subfields when type is `nested_object`. Leave empty for other types. | ||
| */ | ||
| @JsonProperty("nested_fields") | ||
| private Map<String, Object> nestedFields; | ||
|
|
||
| /** | ||
| * Allowed values when type is `classification`. Leave empty for other types. | ||
| */ | ||
| @JsonProperty("classification_values") | ||
| private List<String> classificationValues; | ||
|
|
||
| /** | ||
| * Getter for isArray. | ||
| */ | ||
| public boolean getIsArray() { | ||
| return isArray; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| try { | ||
| return new ObjectMapper().writeValueAsString(this); | ||
| } catch (JsonProcessingException e) { | ||
| return super.toString(); | ||
| } | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/mindee/v2/product/extraction/params/DataSchemaReplace.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.mindee.v2.product.extraction.params; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.util.List; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| /** | ||
| * The structure to completely replace the data schema of the model. | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @EqualsAndHashCode | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public class DataSchemaReplace { | ||
|
|
||
| /** | ||
| * List of fields in the Data Schema. | ||
| */ | ||
| @JsonProperty("fields") | ||
| private List<DataSchemaField> fields; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| try { | ||
| return new ObjectMapper().writeValueAsString(this); | ||
| } catch (JsonProcessingException e) { | ||
| return super.toString(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.