How to extract table specific values in Document Intelligence Custom Extraction Model

Tom Chow 115 Reputation points
2024-05-03T06:35:36.23+00:00

In Document Intelligence Custom Extraction Model, I have several fields and several tables to extract. It is doing fine on Document Intelligence Studio, but when I wanted to fit into my solution, the tables not returning the values I want, for example, I have a table "Address", which contains a few column "City", "State", "Postcode", etc. The code Azure provided return all the values within the table he detected instead. Whereas in studio, the json result is returning fine, but I have no idea how do I extract the specific table with column name and getting the value. As there is no function for tables like the fields that having KeyValuePair function.
I have an idea of getting the Json output and deserialize, but the question is how do I get the Json output automatically as an input every time I call the API? I'm doing it in C#, but my end solution would be in VB.NET.

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,721 questions
{count} votes

Accepted answer
  1. VasaviLankipalle-MSFT 17,646 Reputation points
    2024-05-06T20:46:50.1566667+00:00

    Hello @Tom Chow , I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue: How to extract table specific values (columns) in Document Intelligence Custom Extraction Model

    Solution: To extract the table's column value the user found this way. Below is their sample code in C#:

    foreach (DocumentField row in fieldValue.Value.AsList())
    {
        if (row.FieldType == DocumentFieldType.Dictionary)
        {
            var rowFields = row.Value.AsDictionary();          
    		string columnName1 = rowFields.TryGetValue("columnName1", out DocumentField 	columnName1Field) ? columnName1Field.Content : "";
    		string columnName2 = rowFields.TryGetValue("columnName2", out DocumentField columnName2Field) ? columnName2Field.Content : "";
            Console.WriteLine($"  columnName1: {columnName1}");         
    		Console.WriteLine($"  columnName2: {columnName2}"); 
    	}
    }
    
    

    Thank you again for your time and patience throughout this issue.

    Regards,
    Vasavi

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom Chow 115 Reputation points
    2024-05-06T03:13:23.7333333+00:00

    I have figured it out myself on how to extract the table's column value. I actually struggled on the "table" terms, but Azure mentioned that "table" is actually a structured field, so we should act "table" as a field also. This is my way to extract the values, if there is a simpler way, feel free to comment down below. Below is my sample code in C#:

    foreach (DocumentField row in fieldValue.Value.AsList())
    {
        if (row.FieldType == DocumentFieldType.Dictionary)
        {
    
            var rowFields = row.Value.AsDictionary();          
    
    		string columnName1 = rowFields.TryGetValue("columnName1", out DocumentField 	columnName1Field) ? columnName1Field.Content : "";
    		string columnName2 = rowFields.TryGetValue("columnName2", out DocumentField columnName2Field) ? columnName2Field.Content : "";
    
            Console.WriteLine($"  columnName1: {columnName1}");         
    		Console.WriteLine($"  columnName2: {columnName2}"); 
    	}
    }
    
    
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.