How to modify values and confidence scores for Extraction Results after performing extraction in a Document Understanding Process?
Why Would Extraction Results Need to Be Changed After Extraction?
In a Document Understanding process, after extracting data from a document, sometimes business rules can be used to validate the data that was extracted. After the business rule logic is applied, if the values in question meet (or don't meet) the specified conditions, the values and/or confidence scores can be adjusted if needed. By using business rule logic to check the values extracted in the extraction results and reassigning values when appropriate, this can help to improve the documents throughput sent for human validation.
***The following examples are only meant to serve as a reference on how extraction results can be accessed. The actual syntax will likely need to be modified.***
!!!Caution!!! Carefully test the expressions and ensure when accessing via Index that the required value is targeted. Accessing by Index is sometimes necessary but can be prone to silent errors later if the structure of the taxonomy, table, etc. changes after the expression is created.
How to Access and Extraction Results
For specific details regarding UiPath's Extraction Result Class, the following documentation can be referenced - Extraction Result Class
For details regarding UiPath's Extractor Result Class, see Extractor Result Class
Accessing Specific Values
When accessing specific values within the extraction results, there are various was to accomplish this. See the following examples:
- By Index
out_ExtractionResults.ResultsDocument.Fields(0).Values(0).Value
- By Field Name
out_ExtractionResults.ResultsDocument.Fields.where(function(field) field.FieldName="shipping_address") (0).Values(0).Value
Accessing and Modifying Table Extraction Results
In Document Understanding Activities starting with version 1.17.1, new table structure and table helper methods are available. Going forward it is the recommended way of accessing and manipulating table data in the results object.
See Document Understanding Activities Release notes 1.17.1
Extraction Results Accessing specific cell values within a table
out_ExtractionResults.ResultsDocument.Tables(0).Values(0).GetCell(1, 1).Values(0).Value
For accessing the confidence score of a cell, see the following example -
out_ExtractionResults.ResultsDocument.Tables(0).Values(0).GetCell(1, 1).Values(0).Confidence
Modifying Vales or Confidence Scores
Using an Assign activity the values, confidence scores, etc can be overwritten if needed.
In the following example, the value for shipping_address will be overrwritten with the value that was stored in a variable called correctedAddress:
out_ExtractionResults.ResultsDocument.Fields.where(function(field) field.FieldName="shipping_address")(0).Values(0).Value = correctedAddress
In the following example, the value in the derived field will be overwritten with the value that was stored in a variable called correctedAddress:
out_ExtractionResults.ResultsDocument.Fields.where(function(field) field.FieldName="shipping_address")(0).Values(0).DerivedFields(0).Value = correctedAddress