Universal
The Ruby Client Library implements a universal wrapper class for all products.
Product Specs
Specification Details Endpoint Name <name_of_the_endpoint>
Recommended Version v<version_of_the_endpoint>
Defaults to 1 for custom products.Supports Polling/Webhooks ❓️ Variable Support Synchronous HTTP Calls ❓ Variable Geography ❓ Variable
Polling Limitations
Setting Parameter name Default Value Initial Delay Before Polling initial_delay_seconds
2 seconds Default Delay Between Calls delay_sec
1.5 seconds Polling Attempts Before Timeout max_retries
80 retries
The Universal
product supports all products in a catch-all generic format, and can be used in the following manner:
Quick-Start
require 'mindee'
# Init a new client
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
# Load a file from disk
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
# Initialize a custom endpoint for this product
custom_endpoint = mindee_client.create_endpoint(
account_name: 'my-account',
endpoint_name: 'my-endpoint',
version: 'my-version'
)
# Parse the file
result = mindee_client.parse(
input_source,
Mindee::Product::Universal::Universal,
endpoint: custom_endpoint
# Note: On compatible APIs, you can run this HTTP call synchronously by setting `enqueue: false`
)
# Print a full summary of the parsed data in RST format
puts result.document
Universal Endpoints
You may have noticed in the previous step that in order to access a universal build, you will need to provide an account and an endpoint name at the very least.
Although it is optional, the version number should match the latest version of your build in most use-cases.
If it is not set, it will default to "1".
Field Types
Universal Fields
Universal List Field
A UniversalListField
is a special type of custom list that implements the following:
- values (
Array<StringField
UniversalObjectField>
): the confidence score of the field prediction. - page_id (
Integer
): only available for some documents ATM.
Since the inner contents can vary, the value isn't accessed through a property, but rather through the following functions:
- contents_list() (
-> Array<String, Float>>
): returns a list of values for each element. - contents_string(separator=" ") (
-> String
): returns a list of concatenated values, with an optional separatorString
between them.Note: the
to_s
method returns a string representation of all values of this object, with an empty space between each of them.
Universal Object Field
Unrecognized structures and sometimes values of ListField
s are stored in a UniversalObjectField
structure, which is implemented dynamically depending on the object's structure.
- page_id (
[Integer, nil]
): the ID of the page, isnil
when at document-level. - raw_value (
[String, nil]
): an optional field for when some post-processing has been done on fields (e.g. amounts).nil
in most instances. - confidence (
[Float, nil]
): the confidence score of the field prediction. Warning: support isn't guaranteed on all APIs.
Other fields:No matter what, other fields will be stored in a dictionary-like structure with a
key: value
pair wherekey
is a string andvalue
is a nullable string. They can be accessed like any other regular value, but won't be suggested by your IDE.
StringField
The text field StringField
only has one constraint: its value is an Optional[str]
.
Attributes
Universal builds always have access to at least two attributes:
Fields
fields (Hash<String, Array<
UniversalListField,UniversalObjectField, (#stringfield)[StringField]>>
):
puts result.document.inference.prediction.fields["my-field"].to_s
Questions?
Updated about 15 hours ago