Skip to content

Scan Expense Receipt

Sends an Expense Receipt image to the Expense Receipt Automation and returns the extracted expense 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 Expense Receipt Analyzer.
  • 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_Expense_Receipt(
      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": "5.00",
      "Probability": 0.957,
      "EntityGroupId": "Line1"
    },
    {
      "Id": "amount",
      "Value": "3.00",
      "Probability": 0.958,
      "EntityGroupId": "Line2"
    },
    {
      "Id": "amount",
      "Value": "4.00",
      "Probability": 0.956,
      "EntityGroupId": "Line3"
    },
    {
      "Id": "amount_due",
      "Value": "12.00",
      "Probability": 1,
      "EntityGroupId": "Main"
    },
    {
      "Id": "description",
      "Value": "Chocolate Chip Cooki",
      "Probability": 0.954,
      "EntityGroupId": "Line1"
    },
    {
      "Id": "description",
      "Value": "Apple Pie",
      "Probability": 0.958,
      "EntityGroupId": "Line2"
    },
    {
      "Id": "description",
      "Value": "Lava Cake",
      "Probability": 0.959,
      "EntityGroupId": "Line3"
    },
    {
      "Id": "due_date",
      "Value": "2017-07-04",
      "Probability": 0.6,
      "EntityGroupId": "Main"
    },
    {
      "Id": "invoice_date",
      "Value": "2017-04-07",
      "Probability": 0.957,
      "EntityGroupId": "Main"
    },
    {
      "Id": "invoice_total",
      "Value": "12.00",
      "Probability": 0.971,
      "EntityGroupId": "Main"
    },
    {
      "Id": "previous_unpaid_balance",
      "Value": "12.00",
      "Probability": 1,
      "EntityGroupId": "Main"
    },
    {
      "Id": "raw_text",
      "Value": "Main Street Restaurant 6332 Business Drive Suite 528 Palo Alto California 94301 575-1628095\nFri 04/07/2017 3:57 PM\nOrder ID: #4a59c18f Order Number: 1\n-\n-\n-\n-\n-\n-\n-\nChocolate Chip Cooki\n5.00\nApple Pie\n3.00\nLava Cake\n4.00\n-- -- - - - -\nSub Total\nUSD$ 12.00\n-\n-\n----\n-\n-\n-\n-\n-\nGrand Total:\n$12.00\nCard: XXXXXXXXXXXX0\n14.16\nTip\n2.16",
      "Probability": 1,
      "EntityGroupId": "Main"
    },
    {
      "Id": "service_end_date",
      "Value": "2017-07-04",
      "Probability": 0.6,
      "EntityGroupId": "Main"
    },
    {
      "Id": "service_start_date",
      "Value": "2017-07-04",
      "Probability": 0.6,
      "EntityGroupId": "Main"
    },
    {
      "Id": "sub_total",
      "Value": "12.00",
      "Probability": 0.72,
      "EntityGroupId": "Main"
    },
    {
      "Id": "vendor_address",
      "Value": "6332 Business Drive Suite 528 Palo Alto California 94301",
      "Probability": 0.854,
      "EntityGroupId": "Main"
    },
    {
      "Id": "vendor_address_recipient",
      "Value": "Main Street Restaurant",
      "Probability": 0.922,
      "EntityGroupId": "Main"
    },
    {
      "Id": "vendor_name",
      "Value": "Main Street Restaurant",
      "Probability": 0.922,
      "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 Expense Receipt Analyzer.
  • 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_Expense_Receipt(
      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 Expense Receipt Analyzer please see the Machine Learning Service documentation.