All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mindee.product.custom.CustomV1Document Maven / Gradle / Ivy

The newest version!
package com.mindee.product.custom;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.mindee.parsing.SummaryHelper;
import com.mindee.parsing.common.Prediction;
import com.mindee.parsing.custom.ClassificationField;
import com.mindee.parsing.custom.CustomV1DocumentPredictionDeserializer;
import com.mindee.parsing.custom.ListField;
import java.util.Map;
import java.util.TreeMap;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;


/**
 * Document data for custom documents, API version 1.x.
 */
@AllArgsConstructor
@Getter
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(using = CustomV1DocumentPredictionDeserializer.class)
public class CustomV1Document extends Prediction {

  /**
   * Classification fields.
   */
  private Map classificationFields;

  /**
   * Fields that are not classifications.
   */
  private Map fields;

  /**
   * Returns true if there are no predictions values.
   */
  public boolean isEmpty() {
    return fields.isEmpty() && classificationFields.isEmpty();
  }

  @Override
  public String toString() {

    TreeMap sorted = new TreeMap<>(fields);

    StringBuilder summary = new StringBuilder();

    for (Map.Entry entry : classificationFields.entrySet()) {
      summary.append(String.format(":%s: %s%n", entry.getKey(), entry.getValue()));
    }
    for (Map.Entry entry : sorted.entrySet()) {
      summary.append(String.format(":%s: %s%n", entry.getKey(), entry.getValue()));
    }

    return SummaryHelper.cleanSummary(summary.toString());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy