Process Result Fields
Reference documentation on processing result fields of the response using the Mindee client libraries.
Requirements
You'll need to have a response object as described in the Process the Response section.
Accessing Result Fields
Fields are completely dynamic and depend on your model's Data Schema.
In the client library, you'll have access to the various fields as a key-value mapping type (Python's dict, Java's HashMap, etc).
Accessing a field is done via its name in the Data Schema.
Each field will be one of the following types:
- A single value, - SimpleFieldclass.
- A nested object (sub-fields), - ObjectFieldclass.
- A list or array of fields, - ListFieldclass.
SimpleField - Single-Value Field
SimpleField - Single-Value FieldBasic field type having the value attribute.
See the value section below.
In addition, the Simplefield class has confidence and locations attributes.
Using the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    my_simple_field = fields["my_simple_field"]Using the response deserialized object from either the polling response or a webhook payload.
handleResponse(response) {
  const fields = response.inference.result.fields;
  const simpleField = fields.getSimpleField("my_simple_field");
}Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    $simpleField = $fields->getSimpleField('my_simple_field');
}Using the response deserialized object from either the polling response or a webhook payload.
def handle_response(response)
  fields = response.inference.result.fields
  simple_field = fields.get_simple_field('my_simple_field')
endUsing the response deserialized object from either the polling response or a webhook payload.
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.InferenceFields;
import com.mindee.parsing.v2.field.SimpleField;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = response.inference.getResult().getFields();
  SimpleField simpleField = fields.getSimpleField("my_simple_field");
}Using the response deserialized object from either the polling response or a webhook payload.
using Mindee.Parsing.V2.Field;
public void HandleResponse(InferenceResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;
    SimpleField mySimpleField = fields["my_simple_field"].SimpleField;
}value
valueThe extracted data value. Possible types: string, number (integer or floating-point), boolean. All types can be null.
On the platform, you can specify date and classification types. These are returned as strings.
For statically-typed languages (C#, Java), the client library will always return a nullable double for number values.
Using the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
  fields: dict = response.inference.result.fields
  # texts, dates, classifications ...
  string_field_value: str | None = fields["string_field"].value
  # a JSON float will be a float
  float_field_value: float | None = fields["float_field"].value
  # even if the API always returns an integer, the type will be float
  int_field_value: float | None = fields["int_field"].value
  # booleans
  bool_field_value: bool | None = fields["bool_field"].valueThe value attribute is an Object type under the hood.
You should use the explicitly-typed accessors, this is recommended for clarity. Take a look at your Data Schema to know which typed accessor to use.
handleResponse(response) {
  const fields = response.inference.result.fields;
  
  // texts, dates, classifications ...
  const stringFieldValue = fields.getSimpleField("string_field").stringValue;
  
  // no distinction between floats and integers
  const floatFieldValue = fields.getSimpleField("float_field").numberValue;
  const intFieldValue = fields.getSimpleField("int_field").numberValue;
  
  // booleans
  const boolFieldValue = fields.getSimpleField("bool_field").booleanValue;
}If the wrong accessor type is used, an exception will be thrown, something like this:
"Value is not a number"Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    // texts, dates, classifications ...
    $stringFieldValue = $fields->getSimpleField('string_field')->value;
    // a JSON float will be a float
    $floatFieldValue = $fields->getSimpleField('float_field')->value;
    // even if the API always returns an integer, the type will be float
    $intFieldValue = $fields->getSimpleField('int_field')->value;
    // booleans
    $boolFieldValue = $fields->getSimpleField('bool_field')->value;
}Using the response deserialized object from either the polling response or a webhook payload.
def handle_response(response)
  fields = response.inference.result.fields
  # texts, dates, classifications ...
  string_field_value = fields.get_simple_field('string_field').value
  # a JSON float will be a float
  float_field_value = fields.get_simple_field('float_field').value
  # even if the API always returns an integer, the type will be float
  int_field_value = fields.get_simple_field('int_field').value
  # booleans
  bool_field_value = fields.get_simple_field('bool_field').value
endThe value attribute is an Object type under the hood.
You'll need to explicitly declare the type, otherwise the code will likely not compile. Take a look at your Data Schema to know which type to declare.
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.InferenceFields;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = response.inference.getResult().getFields();
  // texts, dates, classifications ...
  String stringFieldValue = fields.getSimpleField("string_field")
        .getStringValue();
  // a JSON float will be a Double
  Double floatFieldValue = fields.getSimpleField("float_field")
      .getDoubleValue();
  // even if the API always returns an integer, the type will be Double
  Double intFieldValue = fields.getSimpleField("int_field")
      .getDoubleValue();
  // booleans
  Boolean boolFieldValue = fields.getSimpleField("bool_field")
      .getBooleanValue();
}If the wrong type method is used, an exception will be thrown, something like this:
ClassCast class java.lang.String cannot be cast to class java.lang.DoubleThe Value attribute is a dynamic type under the hood.
You should explicitly declare the type, this is recommended for clarity. Take a look at your Data Schema to know which type to declare.
using Mindee.Parsing.V2.Field;
public void HandleResponse(InferenceResponse response)
{
    // texts, dates, classifications ...
    string stringFieldValue = fields["string_field"].SimpleField.Value;
    // a JSON float will be a Double
    Double floatFieldValue = fields["float_field"].SimpleField.Value;
    // even if the API always returns an integer, the type will be Double
    Double intFieldValue = fields["int_field"].SimpleField.Value;
    // booleans
    Boolean boolFieldValue = fields["bool_field"].SimpleField.Value;
}If the wrong type is declared, an exception will be raised, something like this:
RuntimeBinderException : Cannot implicitly convert type 'string' to 'double'ObjectField - Nested Object Field
ObjectField - Nested Object FieldField having a fields attribute which is a hash table (Python's dict, Java's HashMap, etc) of sub-fields.
See the fields section below.
In addition, the ObjectField class has confidence and locations attributes.
Using the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    object_field = fields["my_object_field"]Using the response deserialized object from either the polling response or a webhook payload.
handleResponse(response) {
  const fields = response.inference.result.fields;
  const objectField = fields.getObjectField("my_object_field");
}Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    $objectField = $fields->getObjectField('my_object_field');
}Using the response deserialized object from either the polling response or a webhook payload.
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.InferenceFields;
import com.mindee.parsing.v2.field.ObjectField;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = response.inference.getResult().getFields();
  ObjectField objectField = fields.getObjectField("my_object_field");
}Using the response deserialized object from either the polling response or a webhook payload.
using Mindee.Parsing.V2.Field;
public void HandleResponse(InferenceResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;
    ObjectField myObjectField = fields["my_object_field"].ObjectField;
}fields
fieldsThe sub-fields as a key-value mapping type (Python dict, Java HashMap, etc).
Accessing a sub-field is done via its name in the Data Schema.
Each sub-field will be a Process Result Fields.
Using the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    object_field = fields["my_object_field"]
    sub_fields: dict = object_field.fields
    # grab a single sub-field
    subfield_1 = sub_fields["subfield_1"]
    # loop over sub-fields
    for field_name, sub_field in sub_fields.items():
        sub_field.valueUsing the response deserialized object from either the polling response or a webhook payload.
handleResponse(response) {
  const fields = response.inference.result.fields;
  const objectField = fields.getObjectField("my_object_field");
  const subFields = objectField.simpleFields;
  // grab a single sub-field
  const subfield1 = subFields.get("subfield_1");
  // loop over sub-fields
  subFields.forEach((subField, fieldName) => {
    // Choose the appropriate accessor:
    // stringValue, doubleValue, booleanValue
    const fieldValue = subField.stringValue;
  });
}Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    $objectField = $fields->getObjectField('my_object_field');
    $subFields = $objectField->fields;
    // grab a single sub-field
    $subfield1 = $subFields->getSimpleField('subfield_1');
    // loop over sub-fields
    foreach ($subFields as $fieldName => $subField) {
        $fieldValue = $subField->value;
    }
}Using the response deserialized object from either the polling response or a webhook payload.
def handle_response(response)
  fields = response.inference.result.fields
  object_field = fields.get_object_field('my_object_field')
  sub_fields = object_field.fields
  
  # grab a single sub-field
  sub_field_value = sub_fields.get_simple_field('sub_field').value
  
  # loop over sub-fields
  sub_fields.each_value do |sub_field|
    field_value = sub_field.value
  end
endUsing the response deserialized object from either the polling response or a webhook payload.
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.InferenceFields;
import com.mindee.parsing.v2.field.ListField;
import com.mindee.parsing.v2.field.ObjectField;
import com.mindee.parsing.v2.field.SimpleField;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = response.inference.getResult().getFields();
  ObjectField objectField = fields.getObjectField("my_object_field");
  HashMap<String, SimpleField> subFields = objectField.getSimpleFields();
  // grab a single sub-field
  SimpleField subfield1 = subFields.get("subfield_1");
  // loop over sub-fields
  for (Map.Entry<String, SimpleField> entry : subFields.entrySet()) {
    String fieldName = entry.getKey();
    SimpleField subField = entry.getValue();
    
    // Choose the appropriate value type accessor method:
    // String, Double, Boolean
    String fieldValue = subField.getStringValue();
  }
}Using the response deserialized object from either the polling response or a webhook payload.
using Mindee.Parsing.V2.Field;
public void HandleResponse(InferenceResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;
    ObjectField objectField = fields["my_object_field"].ObjectField;
    Dictionary<string, SimpleField> subFields = objectField.SimpleFields;
    // grab a single sub-field
    SimpleField subField1 = subFields["subfield_1"];
    // loop over sub-fields
    foreach (KeyValuePair<string, SimpleField> entry in subFields)
    {
        string fieldName = entry.Key;
        SimpleField subField = entry.Value;
        
        // process the SimpleField ...
    }
}ListField - List of Fields
ListField - List of FieldsField having an items attribute which is a list of fields.
See the items section below.
In addition, the ListField class has a confidence attribute.
Using the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    my_list_field = fields["my_list_field"]Using the response deserialized object from either the polling response or a webhook payload.
handleResponse(response) {
  const fields = response.inference.result.fields;
  const listField = fields.getListField("my_list_field");
}Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    
    $listField = $fields->getListField('my_list_field');
}Using the response deserialized object from either the polling response or a webhook payload.
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.InferenceFields;
import com.mindee.parsing.v2.field.ListField;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = response.inference.getResult().getFields();
  ListField listField = fields.getListField("my_list_field");
}Using the response deserialized object from either the polling response or a webhook payload.
using Mindee.Parsing.V2.Field;
public void HandleResponse(InferenceResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;
    ListField myListField = fields["my_list_field"].ListField;
}items
itemsList of fields as a variable-length array type (Python list, Java List, etc).
Each item in the list will be one of:
There will not be a mix of both types in the same list.
List of SimpleField
SimpleFieldUsing the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    simple_list_field = fields["my_simple_list_field"]
    # Loop over the list of Simple fields
    for list_item in simple_list_field.items:
        item_value = list_item.valueUsing the response deserialized object from either the polling response or a webhook payload.
handleResponse(response) {
  const fields = response.inference.result.fields;
  const simpleListField = fields.getListField("my_simple_list_field");
  const simpleItems = simpleListField.simpleItems;
  // Loop over the list of Simple fields
  for (const itemField of simpleItems) {
    // Choose the appropriate accessor:
    // stringValue, doubleValue, booleanValue
    const fieldValue = itemField.stringValue;
  }
}Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    $simpleListField = $fields->getListField('my_simple_list_field');
    // access a value at a given position
    $fieldFirstValue = $simpleListField->items[0]->value;
    // Loop over the list of Simple fields
    foreach ($simpleListField->items as $listItem) {
        $itemValue = $listItem->value;
    }
}Using the response deserialized object from either the polling response or a webhook payload.
def handle_response(response)
  fields = response.inference.result.fields
  
  my_list_field = fields.get_list_field('my_simple_list_field')
  # access a value at a given position
  simple_list_field = my_list_field.simple_items[0].value
  # Loop over the list of Simple fields
  simple_list_field.simple_items.each do |list_item|
    item_value = list_item.value
  end
endUsing the response deserialized object from either the polling response or a webhook payload.
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.InferenceFields;
import com.mindee.parsing.v2.field.ListField;
import com.mindee.parsing.v2.field.SimpleField;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = response.inference.getResult().getFields();
  ListField simpleListField = fields.getListField("my_simple_list_field");
  List<SimpleField> simpleItems = simpleListField.getSimpleItems();
  // Loop over the list of Simple fields
  for (SimpleField itemField : simpleItems) {
    // Choose the appropriate value type accessor method:
    // String, Double, Boolean
    String fieldValue = itemField.getStringValue();
  }
}Using the response deserialized object from either the polling response or a webhook payload.
using Mindee.Parsing.V2.Field;
public void HandleResponse(InferenceResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;
    ListField simpleListField = fields["my_simple_list_field"].ListField;
    List<SimpleField> simpleItems = simpleListField.SimpleItems;
    // Loop over the list of Simple fields
    foreach (SimpleField itemField in simpleItems)
    {
        // Choose the appropriate value type:
        // string, Double, Boolean
        string fieldValue = itemField.Value;
    }
}List of ObjectField
ObjectFieldUsing the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    object_list_field = fields["my_object_list_field"]
    # Loop over the list of Object fields
    for object_item in object_list_field.items:
        # grab a single sub-field
        sub_field_value = object_item.fields["sub_field"].value
        
        # loop over sub-fields
        for field_name, sub_field in object_item.fields.items():
            sub_field.valueUsing the response deserialized object from either the polling response or a webhook payload.
handleResponse(response) {
  const fields = response.inference.result.fields;
  const fieldObjectList = fields.getListField("my_object_list_field");
  const objectItems = fieldSimpleList.objectItems;
  // Loop over the list of Object fields
  for (const itemField of objectItems) {
    const subFields = itemField.simpleFields;
    // grab a single sub-field
    const subField1 = subFields.get("subfield_1");
    // Choose the appropriate accessor:
    // stringValue, doubleValue, booleanValue
    const subFieldValue = subField1.stringValue;
    // loop over sub-fields
    subFields.forEach((subField, fieldName) => {
      // Choose the appropriate accessor:
      // stringValue, doubleValue, booleanValue
      const fieldValue = subField.stringValue;
    });
  }
}Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    $fieldObjectList = $fields->getObjectField('my_object_list_field');
    // access an object at a given position
    $objectItem0 = $fieldObjectList->items[0];
    $subField0Value = $objectItem0->fields->get('sub_field')->value;
    // Loop over the list of Object fields
    foreach ($myObjectListField->items as $objectItem) {
        $subFieldValue = $objectItem->fields->get('sub_field')->value;
    }
}Using the response deserialized object from either the polling response or a webhook payload.
def handle_response(response)
  fields = response.inference.result.fields
  
  object_list_field = fields.get('my_object_list_field')
  # access an object at a given position
  object_item_0 = object_list_field.items[0]
  sub_field_0_value = object_item_0.fields.get('sub_field').value
  # Loop over the list of Object fields
  object_list_field.fields.each do |object_item|
    sub_field_value = object_item.fields.get('sub_field').value
  end
endUsing the response deserialized object from either the polling response or a webhook payload.
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.InferenceFields;
import com.mindee.parsing.v2.field.ListField;
import com.mindee.parsing.v2.field.ObjectField;
import com.mindee.parsing.v2.field.SimpleField;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = response.inference.getResult().getFields();
  ListField fieldObjectList = fields.getListField("my_object_list_field");
  List<ObjectField> objectItems = listField.getObjectItems();
  // Loop over the list of Object fields
  for (ObjectField itemField : objectItems) {
    // Object sub-fields will always be Simple fields
    HashMap<String, SimpleField> subFields = itemField.getSimpleFields();
    // grab a single sub-field
    SimpleField subfield1 = subFields.get("subfield_1");
    
    // Choose the appropriate value type accessor method:
    // String, Double, Boolean
    String subFieldValue = subfield1.getStringValue();
    // loop over sub-fields
    for (Map.Entry<String, SimpleField> entry : subFields.entrySet()) {
      String fieldName = entry.getKey();
      SimpleField subField = entry.getValue();
    }
  }
}Using the response deserialized object from either the polling response or a webhook payload.
using Mindee.Parsing.V2.Field;
public void HandleResponse(InferenceResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;
    ListField fieldObjectList = fields["my_simple_list_field"].ListField;
    List<ObjectField> objectItems = fieldObjectList.ObjectItems;
    // Loop over the list of Object fields
    foreach (ObjectField itemField in objectItems)
    {
        Dictionary<string, SimpleField> subFields = objectField.SimpleFields;
    
        // grab a single sub-field
        SimpleField subField1 = subFields["subfield_1"];
        
        // Choose the appropriate value type:
        // string, Double, Boolean
        string subFieldValue = subField1.Value;
    
        // loop over sub-fields
        foreach (KeyValuePair<string, SimpleField> entry in subFields)
        {
            string fieldName = entry.Key;
            SimpleField subField = entry.Value;
        }
    }
}Optional Field Attributes
These field attributes are only filled when their respective features are activated.
The attributes are always present even when not activated.
confidence
confidenceThe confidence level of the extracted value.
The data are only filled if the Confidence Score and Accuracy Boost feature is activated.
The attribute is always present, in case of Confidence Score not activated, it will always be null.
The attribute value will be one of: Certain, High, Medium, Low .
All languages use the appropriate enum type.
Using the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
from mindee.parsing.v2.field import FieldConfidence
def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    confidence = fields["my_simple_field"].confidence
    # compare using the enum `FieldConfidence`
    is_certain = confidence == FieldConfidence.CERTAIN
    is_lte_medium = confidence <= FieldConfidence.MEDIUM
    is_gte_low = confidence >= FieldConfidence.LOWUsing the response deserialized object from either the polling response or a webhook payload.
handleResponse(response) {
  const fields = response.inference.result.fields;
  const confidence = fields.getSimpleField("my_simple_field")?.confidence
  // compare using the enum `FieldConfidence`
  const isCertain = confidence === FieldConfidence.Certain;
  const isLteMedium = FieldConfidence.lessThanOrEqual(
    confidence, FieldConfidence.Medium
  );
  const isGteLow = FieldConfidence.greaterThanOrEqual(
    confidence, FieldConfidence.Low
  );
}Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
use Mindee\Parsing\V2\Field\FieldConfidence;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    $confidence = $fields->get('my_simple_field')->confidence;
    // compare using the enum `FieldConfidence`
    $isCertain = $confidence === FieldConfidence::Certain;
}Using the response deserialized object from either the polling response or a webhook payload.
def handle_response(response)
  fields = response.inference.result.fields
  confidence = fields["my_simple_field"].confidence
  # compare using the class `FieldConfidence`
  FieldConfidence = Mindee::Parsing::V2::Field::FieldConfidence
  
  is_certain = confidence == FieldConfidence.CERTAIN
  is_lte_medium = confidence <= FieldConfidence.MEDIUM
  is_gte_low = confidence >= FieldConfidence.LOW
endUsing the response deserialized object from either the polling response or a webhook payload.
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.FieldConfidence;
import com.mindee.parsing.v2.field.InferenceFields;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = inference.getResult().getFields();
  // choose the appropriate field type accessor method: Simple, Object, List
  FieldConfidence confidence = fields.getSimpleField("my_simple_field")
      .getConfidence();
  // compare using the enum `FieldConfidence`
  boolean isCertain = confidence === FieldConfidence.Certain;
  boolean isLteMedium = confidence.lessThanOrEqual(FieldConfidence.Medium);
  boolean isGteLow = confidence.greaterThanOrEqual(FieldConfidence.Low);
}Using the response deserialized object from either the polling response or a webhook payload.
using Mindee.Parsing.V2.Field;
public void HandleResponse(InferenceResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;
    // nullable enum since presence depends on feature activation
    FieldConfidence? confidence = fields["my_simple_field"]
        .SimpleField.Confidence;
    // compare using the enum `FieldConfidence`
    bool isCertain = confidence == FieldConfidence.Certain;
    // cast to int for relative inequalities
    bool isLteMedium = (int?)confidence <= (int)FieldConfidence.Medium;
    bool isGteLow = (int?)confidence >= (int)FieldConfidence.Low;
}locations
locationsA list of the field's locations on the document.
The data are only filled if the Polygons (Bounding Boxes) feature is activated.
It's possible for a single field to have multiple locations, for example when an invoice item spans two pages.
Each location has a page index and a Polygon.
Page indexes are 0-based, so the first page is 0.
A Polygon class contains a list of Points, the specific implementation will depend on the language.
Points are listed in clockwise order, where index 0 is top left.
Point X,Y coordinates are normalized floats from 0.0 to 1.0, relative to the page dimensions.
Using the response deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    
    locations = fields["my_simple_field"].locations
    # accessing the polygon
    polygon = locations[0].polygon
    # accessing points: the Polygon class extends List[Point]
    top_x = polygon[0].x
    # alternative syntax, since the Point class extends List<float>
    # top_x = polygon[0][0]
    # there are geometry functions available in the Polygon class
    center = polygon.centroid
    # accessing the page index on which the polygon is
    page_index = locations[0].pageUsing the response deserialized object from either the polling response or a webhook payload.
handleResponse(response) {
  const fields = response.inference.result.fields;
  const locations = fields.getSimpleField("my_simple_field")?.locations;
  // accessing the polygon
  const polygon = locations![0].polygon!;
  // accessing points: the Polygon class extends Array<Point>
  const topX = polygon[0][0];
  // there are geometry functions available in the Polygon class
  const center = polygon.getCentroid();
  // accessing the page index on which the polygon is
  const pageIndex = locations![0].page!;
}Using the $response deserialized object from either the polling response or a webhook payload.
use Mindee\Parsing\V2\InferenceResponse;
use Mindee\Parsing\V2\Field\FieldConfidence;
public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    $locations = $fields->get('my_simple_field')->locations;
    // accessing the polygon
    $polygon = $locations[0]->polygon;
    
    // accessing points:
    $points = $polygon->coordinates;
    $topX = $points[0]->getX();
    // alternative syntax, since the Point class extends Array<float>
    // $topX = $points[0][0]
    // there are geometry functions available in the Polygon class
    $center = $polygon->getCentroid();
    
    // accessing the page index on which the polygon is
    $pageIndex = $locations[0]->page;
}Using the $response deserialized object from either the polling response or a webhook payload.
def handle_response(response)
  fields = response.inference.result.fields
  locations = fields.get_simple_field('my_simple_field').locations
  # accessing the polygon
  polygon = locations[0].polygon
  # accessing points:
  top_x = polygon[0].x
  # alternative syntax
  # top_x = polygon[0][0]
  # there are geometry functions available in the Polygon class
  center = polygon.centroid
  # accessing the page index on which the polygon is
  page_index = locations[0].page
endUsing the response deserialized object from either the polling response or a webhook payload.
import com.mindee.geometry.Point;
import com.mindee.geometry.Polygon;
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.FieldLocation;
import com.mindee.parsing.v2.field.InferenceFields;
import java.util.List;
public void handleResponse(InferenceResponse response) {
  InferenceFields fields = response.inference.getResult().getFields();
  // choose the appropriate field type accessor method: Simple, Object
  List<FieldLocation> locations = fields.getSimpleField("my_simple_field")
      .getLocations();
  
  // accessing the polygon
  Polygon polygon = locations.get(0).getPolygon();
  // accessing points
  List<Point> points = polygon.getCoordinates();
  double topX = points.get(0).getX();
  // there are geometry functions available in the Polygon class
  Point center = polygon.getCentroid();
  // accessing the page index on which the polygon is
  int pageIndex = locations.get(0).getPage();
}Using the response deserialized object from either the polling response or a webhook payload.
using Mindee.Parsing.V2.Field;
using Mindee.Geometry;
public void HandleResponse(InferenceResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;
    List<FieldLocation> locations = fields["my_simple_field"]
        .SimpleField.Locations;
    // accessing the polygon
    Polygon polygon = locations.First().Polygon;
    // accessing points: the Polygon class extends List<Point>
    double topX = polygon[0].X;
    // alternative notation, since the Point class extends List<double>
    // double topX = polygon[0][0];
    // there are geometry functions available in the Polygon class
    Point center = polygon.GetCentroid();
    // accessing the page index on which the polygon is
    int pageIndex = locations.First().Page;
}Last updated
Was this helpful?

