Scan Invoice¶
Sends an Invoice image to the Customer Order Automation and returns the extracted invoice information.
It's possible to retrieve the output back in two ways, either in CLOB (character large object) format or in PL/SQL record format.
The method with CLOB output accepts the following parameters:
- response_, out parameter of type CLOB, to which the response will be written.
- image_data_, required parameter of type BLOB to pass the binary image data to the Customer Order Automation.
- response_format_, optional parameter to specify the response format. Possible values are 'JSON' and 'IFS_MESSAGE'. If not specified 'IFS_MESSAGE' will be used as the default format.
- ml_configuration_id_, optional parameter to specify the Configuration ID from Machine Learning Configuration (link to be added) to use. If not specified, the configuration specified in Machine Learning Pre-trained Models (link to be added) for the corresponding Model Name will be used.
DECLARE
response_ CLOB;
image_data_ BLOB;
BEGIN
Ml_Service_Util_API.Scan_Invoice(
response_ => response_, -- Clob parameter to accept response data.
image_data_ => image_data_, -- Blob parameter to pass the binary image data.
response_format_ => 'JSON', -- Response format ('JSON' / 'IFS_MESSAGE').
ml_configuration_id_ => 'DEFAULT'); -- Configuration ID to use.
END;
For the above call, the response may look as following. The response may vary depending on the IFS Machine Learning Service version being used.
{
"Entities": [
{
"Id": "amount",
"Value": "60.00",
"Probability": 0.898,
"EntityGroupId": "Line1"
},
{
"Id": "amount",
"Value": "30.00",
"Probability": 0.898,
"EntityGroupId": "Line2"
},
{
"Id": "amount",
"Value": "10.00",
"Probability": 0.898,
"EntityGroupId": "Line3"
},
{
"Id": "amount_due",
"Value": "610.00",
"Probability": 0.967,
"EntityGroupId": "Main"
},
{
"Id": "billing_address",
"Value": "123 Bill St,\nRedmond WA, 98052",
"Probability": 0.892,
"EntityGroupId": "Main"
},
{
"Id": "billing_address_recipient",
"Value": "Microsoft Finance",
"Probability": 0.934,
"EntityGroupId": "Main"
},
{
"Id": "customer_address",
"Value": "123 Other St, Redmond WA, 98052",
"Probability": 0.889,
"EntityGroupId": "Main"
},
{
"Id": "customer_address_recipient",
"Value": "Microsoft Corp",
"Probability": 0.928,
"EntityGroupId": "Main"
},
{
"Id": "customer_id",
"Value": "CID-12345",
"Probability": 0.943,
"EntityGroupId": "Main"
},
{
"Id": "customer_name",
"Value": "MICROSOFT CORPORATION",
"Probability": 0.894,
"EntityGroupId": "Main"
},
{
"Id": "date",
"Value": "2021-04-03",
"Probability": 0.898,
"EntityGroupId": "Line1"
},
{
"Id": "date",
"Value": "2021-05-03",
"Probability": 0.897,
"EntityGroupId": "Line2"
},
{
"Id": "date",
"Value": "2021-06-03",
"Probability": 0.898,
"EntityGroupId": "Line3"
},
{
"Id": "description",
"Value": "Consulting Services",
"Probability": 0.898,
"EntityGroupId": "Line1"
},
{
"Id": "description",
"Value": "Document Fee",
"Probability": 0.898,
"EntityGroupId": "Line2"
},
{
"Id": "description",
"Value": "Printing Fee",
"Probability": 0.899,
"EntityGroupId": "Line3"
},
{
"Id": "due_date",
"Value": "2019-12-15",
"Probability": 0.967,
"EntityGroupId": "Main"
},
{
"Id": "invoice_date",
"Value": "2019-11-15",
"Probability": 0.969,
"EntityGroupId": "Main"
},
{
"Id": "invoice_id",
"Value": "INV-100",
"Probability": 0.965,
"EntityGroupId": "Main"
},
{
"Id": "invoice_total",
"Value": "110.00",
"Probability": 0.966,
"EntityGroupId": "Main"
},
{
"Id": "previous_unpaid_balance",
"Value": "500.00",
"Probability": 0.951,
"EntityGroupId": "Main"
},
{
"Id": "product_code",
"Value": "A123",
"Probability": 0.896,
"EntityGroupId": "Line1"
},
{
"Id": "product_code",
"Value": "B456",
"Probability": 0.897,
"EntityGroupId": "Line2"
},
{
"Id": "product_code",
"Value": "C789",
"Probability": 0.896,
"EntityGroupId": "Line3"
},
{
"Id": "purchase_order",
"Value": "PO-3333",
"Probability": 0.942,
"EntityGroupId": "Main"
},
{
"Id": "quantity",
"Value": "2.00",
"Probability": 0.898,
"EntityGroupId": "Line1"
},
{
"Id": "quantity",
"Value": "3.00",
"Probability": 0.898,
"EntityGroupId": "Line2"
},
{
"Id": "quantity",
"Value": "10.00",
"Probability": 0.898,
"EntityGroupId": "Line3"
},
{
"Id": "raw_text",
"Value": "CONTOSO LTD.\nContoso Headquarters 123 456th St New York, NY, 10001\nINVOICE\nINVOICE: INV-100 INVOICE DATE: 11/15/2019 DUE DATE: 12/15/2019 CUSTOMER NAME: MICROSOFT CORPORATION SERVICE PERIOD: 10/14/2019 - 11/14/2019 CUSTOMER ID: CID-12345\nMicrosoft Corp 123 Other St, Redmond WA, 98052\nBILL TO:\nMicrosoft Finance\n123 Bill St,\nRedmond WA, 98052\nSHIP TO:\nMicrosoft Delivery\n123 Ship St,\nRedmond WA, 98052\nSERVICE ADDRESS:\nMicrosoft Services\n123 Service St,\nRedmond WA, 98052\nSALESPERSON\nP.O. NUMBER\nREQUISITIONER\nSHIPPED VIA\nF.O.B. POINT\nTERMS\nPO-3333\nDATE\nITEM CODE\nDESCRIPTION\nQTY\nUM\nPRICE\nTAX\nAMOUNT\n3/4/2021\nA123\nConsulting Services\n2\nhours\n$30.00\n10%\n$60.00\n3/5/2021\nB456\nDocument Fee\n3\n$10.00\n5%\n$30.00\n3/6/2021\nC789\nPrinting Fee\n10\npages\n$1.00\n20%\n$10.00\nSUBTOTAL\n$100.00\nSALES TAX\n$10.00\nTOTAL\n$110.00\nPREVIOUS UNPAID BALANCE\n$500.00\nTHANK YOU FOR YOUR BUSINESS!\nREMIT TO:\nContoso Billing\n123 Remit St\nNew York, NY, 10001\nAMOUNT DUE\n$610.00",
"Probability": 1,
"EntityGroupId": "Main"
},
{
"Id": "remittance_address",
"Value": "123 Remit St\nNew York, NY, 10001",
"Probability": 0.889,
"EntityGroupId": "Main"
},
{
"Id": "remittance_address_recipient",
"Value": "Contoso Billing",
"Probability": 0.932,
"EntityGroupId": "Main"
},
{
"Id": "service_address",
"Value": "123 Service St,\nRedmond WA, 98052",
"Probability": 0.889,
"EntityGroupId": "Main"
},
{
"Id": "service_address_recipient",
"Value": "Microsoft Services",
"Probability": 0.932,
"EntityGroupId": "Main"
},
{
"Id": "service_end_date",
"Value": "2019-11-14",
"Probability": 0.953,
"EntityGroupId": "Main"
},
{
"Id": "service_start_date",
"Value": "2019-10-14",
"Probability": 0.957,
"EntityGroupId": "Main"
},
{
"Id": "shipping_address",
"Value": "123 Ship St,\nRedmond WA, 98052",
"Probability": 0.889,
"EntityGroupId": "Main"
},
{
"Id": "shipping_address_recipient",
"Value": "Microsoft Delivery",
"Probability": 0.93,
"EntityGroupId": "Main"
},
{
"Id": "sub_total",
"Value": "100.00",
"Probability": 0.969,
"EntityGroupId": "Main"
},
{
"Id": "total_tax",
"Value": "10.00",
"Probability": 0.968,
"EntityGroupId": "Main"
},
{
"Id": "total_vat",
"Value": "10.00",
"Probability": 0.968,
"EntityGroupId": "Main"
},
{
"Id": "unit",
"Value": "hours",
"Probability": 0.896,
"EntityGroupId": "Line1"
},
{
"Id": "unit",
"Value": "pages",
"Probability": 0.896,
"EntityGroupId": "Line3"
},
{
"Id": "unit_price",
"Value": "30.00",
"Probability": 0.898,
"EntityGroupId": "Line1"
},
{
"Id": "unit_price",
"Value": "10.00",
"Probability": 0.898,
"EntityGroupId": "Line2"
},
{
"Id": "unit_price",
"Value": "1.00",
"Probability": 0.898,
"EntityGroupId": "Line3"
},
{
"Id": "vendor_address",
"Value": "123 456th St New York, NY, 10001",
"Probability": 0.889,
"EntityGroupId": "Main"
},
{
"Id": "vendor_address_recipient",
"Value": "Contoso Headquarters",
"Probability": 0.932,
"EntityGroupId": "Main"
},
{
"Id": "vendor_name",
"Value": "CONTOSO LTD.",
"Probability": 0.928,
"EntityGroupId": "Main"
}
],
"EntityGroups": [
"Line1",
"Line2",
"Line3",
"Main"
]
}
Tip: The IFS Message response format ('IFS_MESSAGE') allows using existing methods in Message_SYS package to handle the response which may be simpler to use in the PL/SQL code than 'JSON'.
The method with PL/SQL record output accepts the following parameters:
- response_rec_, out parameter of type record, to which the response will be written.
- image_data_, required parameter of type BLOB to pass the binary image data to the Customer Order Automation.
- ml_configuration_id_, optional parameter to specify the Configuration ID from Machine Learning Configuration (link to be added) to use. If not specified, the configuration specified in Machine Learning Pre-trained Models (link to be added) for the corresponding Model Name will be used.
DECLARE
response_rec_ Ml_SYS.Doc_Scan_Response_Rec;
image_data_ BLOB;
BEGIN
Ml_Service_Util_API.Scan_Invoice(
response_rec_ => response_rec_, -- Record parameter to accept response data.
image_data_ => image_data_, -- Blob parameter to pass the binary image data.
ml_configuration_id_ => 'DEFAULT'); -- Configuration ID to use.
-- Example of handling response
IF (response_rec_.entities.count > 0) THEN
FOR i_ IN response_rec_.entities.first..response_rec_.entities.last LOOP
Dbms_Output.Put_Line('Id:'||response_rec_.entities(i_).id);
Dbms_Output.Put_Line('Value:'||response_rec_.entities(i_).value);
Dbms_Output.Put_Line('Probability:'||response_rec_.entities(i_).probability);
Dbms_Output.Put_Line('EntityGroupId:'||response_rec_.entities(i_).entity_group_id);
END LOOP;
END IF;
IF (response_rec_.entity_groups.count > 0) THEN
FOR i_ IN response_rec_.entity_groups.first..response_rec_.entity_groups.last LOOP
Dbms_Output.Put_Line('EntityGroupId:'||response_rec_.entity_groups(i_));
END LOOP;
END IF;
END;
The Doc_Scan_Response_Rec response record type has the following format:
TYPE Doc_Scan_Response_Rec IS RECORD (
entities Entity_Arr,
entity_groups Entity_Group_Arr);
The Entity_Arr array type has the following format:
TYPE Entity_Arr IS TABLE OF Entity_Rec;
The Entity_Rec record type has the following format:
TYPE Entity_Rec IS RECORD (
id VARCHAR2(100),
value VARCHAR2(4000),
probability NUMBER,
entity_group_id VARCHAR2(100));
The Entity_Group_Arr array type has the following format:
TYPE Entity_Group_Arr IS TABLE OF VARCHAR2(100);
For more details about the Customer Order Automation please see the Machine Learning Service documentation.