Is there a search algorithm to extract information from a document using Document AI?

Viewed 62

I can extract all the information I need through a combination of the formFields and pages fields, almost hardcoding where to find the pieces of information I need (picture of what was used), and this works for the current document that I am working on, but if I need to upload multiple documents, it would be very tedious to look through every single one and hardcode the lines simply to extract what I am looking for, as different documents will be in different formats, or have slightly different spacing guidelines.

So I was wondering if I would be able to simply search for what I was looking for, for example let's say I wanted the Total Disbursements this period (which was the example used in the code). Would there be a way to simply search in the code using the keywords "Total Disbursements this period" to find the value in the formField?

The main reason I require this ease of accessibility is that I'm trying to take the numbers I get from the document and put it into an excel file. This excel file will have empty boxes with fields to fill up, and I will want to automate the reading of the document and the inputting of the correct information.

1 Answers

There's currently not a built-in way to "search" for specific formField names in the output from the Form Parser. But you can always cycle through all of the formfields, load the key-value pairs into a dictionary, then use that to index specific fields.

Here's the documentation for how to handle the Document response from the Form Parser:

https://cloud.google.com/document-ai/docs/handle-response#forms_and_tables

This Codelab for the Form Parser shows how to load the key-value pairs into a Pandas Dataframe, which would likely suit your use case.

https://codelabs.developers.google.com/codelabs/docai-form-parser-v1-python

Related