// </snippet_calls>

    // <snippet_getcontent_call>
    private static async Task GetContent(
        FormRecognizerClient recognizerClient, string invoiceUri)
        {
        Response<FormPageCollection> formPages = await recognizerClient
            .StartRecognizeContentFromUri(new Uri(invoiceUri))
            .WaitForCompletionAsync();
        // </snippet_getcontent_call>

        // <snippet_getcontent_print>
        foreach (FormPage page in formPages.Value)
        {
            Console.WriteLine($"Form Page {page.PageNumber} has {page.Lines.Count}" + 
                $" lines.");
        
            for (int i = 0; i < page.Lines.Count; i++)
            {
                FormLine line = page.Lines[i];
                Console.WriteLine($"    Line {i} has {line.Words.Count}" + 
                    $" word{(line.Words.Count > 1 ? "s" : "")}," +
                    $" and text: '{line.Text}'.");
            }
        
            for (int i = 0; i < page.Tables.Count; i++)
            {
                FormTable table = page.Tables[i];
                Console.WriteLine($"Table {i} has {table.RowCount} rows and" +
                    $" {table.ColumnCount} columns.");
                foreach (FormTableCell cell in table.Cells)
                {
                    Console.WriteLine($"    Cell ({cell.RowIndex}, {cell.ColumnIndex})" +
                        $" contains text: '{cell.Text}'.");
                }
            }
        }
    }
    // </snippet_auth_training>

    // <snippet_getcontent_call>
    private static async Task RecognizeContent(FormRecognizerClient recognizerClient)
    {
        var invoiceUri = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/simple-invoice.png";
        FormPageCollection formPages = await recognizerClient
                                       .StartRecognizeContentFromUri(new Uri(invoiceUri))
                                       .WaitForCompletionAsync();

        // </snippet_getcontent_call>

        // <snippet_getcontent_print>
        foreach (FormPage page in formPages)
        {
            Console.WriteLine($"Form Page {page.PageNumber} has {page.Lines.Count} lines.");

            for (int i = 0; i < page.Lines.Count; i++)
            {
                FormLine line = page.Lines[i];
                Console.WriteLine($"    Line {i} has {line.Words.Count} word{(line.Words.Count > 1 ? "s" : "")}, and text: '{line.Text}'.");
            }

            for (int i = 0; i < page.Tables.Count; i++)
            {
                FormTable table = page.Tables[i];
                Console.WriteLine($"Table {i} has {table.RowCount} rows and {table.ColumnCount} columns.");
                foreach (FormTableCell cell in table.Cells)
                {
                    Console.WriteLine($"    Cell ({cell.RowIndex}, {cell.ColumnIndex}) contains text: '{cell.Text}'.");
                }
            }
        }
    }
        private static async Task RecognizeContent(FormRecognizerClient recognizerClient, string formUrl)
        {
            FormPageCollection formPages = await recognizerClient
                                           .StartRecognizeContentFromUri(new Uri(formUrl))
                                           .WaitForCompletionAsync();

            foreach (FormPage page in formPages)
            {
                //lines
                for (int i = 0; i < page.Lines.Count; i++)
                {
                    FormLine line = page.Lines[i];

                    //returnString += $"{line.Text}{Environment.NewLine}";
                    returnString += $"    Line {i} has {line.Words.Count} word{(line.Words.Count > 1 ? "s" : "")}, and text: '{line.Text}'.{Environment.NewLine}";
                }
                //tables
                for (int i = 0; i < page.Tables.Count; i++)
                {
                    FormTable table = page.Tables[i];
                    foreach (FormTableCell cell in table.Cells)
                    {
                        //returnString += $"{cell.Text} ";
                        returnString += $"    Cell ({cell.RowIndex}, {cell.ColumnIndex}) contains text: '{cell.Text}'.{Environment.NewLine}";
                    }
                }
            }
        }
Esempio n. 4
0
        private static async Task RecognizeContent(FormRecognizerClient recognizerClient)
        {
            var invoiceUri = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/forms/Invoice_1.pdf";
            FormPageCollection formPages = await recognizerClient
                                           .StartRecognizeContentFromUri(new Uri(invoiceUri))
                                           .WaitForCompletionAsync();

            foreach (FormPage page in formPages)
            {
                Console.WriteLine($"Form Page {page.PageNumber} has {page.Lines.Count} lines.");

                for (int i = 0; i < page.Lines.Count; i++)
                {
                    FormLine line = page.Lines[i];
                    Console.WriteLine($"    Line {i} has {line.Words.Count} word{(line.Words.Count > 1 ? "s" : "")}, and text: '{line.Text}'.");
                }

                for (int i = 0; i < page.Tables.Count; i++)
                {
                    FormTable table = page.Tables[i];
                    Console.WriteLine($"Table {i} has {table.RowCount} rows and {table.ColumnCount} columns.");
                    foreach (FormTableCell cell in table.Cells)
                    {
                        Console.WriteLine($"    Cell ({cell.RowIndex}, {cell.ColumnIndex}) contains text: '{cell.Text}'.");
                    }
                }
            }
        }
Esempio n. 5
0
        private async Task RecognizeContent(FormRecognizerClient recognizerClient, string pPictureUri)
        {
            string             xLine     = "";
            FormPageCollection formPages = await recognizerClient
                                           .StartRecognizeContentFromUri(new Uri(pPictureUri))
                                           .WaitForCompletionAsync();

            foreach (FormPage page in formPages)
            {
                Console.WriteLine($"Form Page {page.PageNumber} has {page.Lines.Count} lines.");
                for (int i = 0; i < page.Lines.Count; i++)
                {
                    FormLine line = page.Lines[i];
                    Console.WriteLine($"    Line {i} has {line.Words.Count} word{(line.Words.Count > 1 ? "s" : "")}, and text: '{line.Text}'.");
                    if (xLine.Length > 15)
                    {
                        int distanceReceiptNo = CalcLevenshteinDistance(xLine.Substring(0, 15), "lfd. Nr./Zähler");
                        int distanceAmount    = CalcLevenshteinDistance(xLine.Substring(0, 5), "Menge");
                        if ((distanceReceiptNo != 0) && (distanceReceiptNo < 6))
                        {
                            newReceiptNo = line.Text;
                        }
                        else if ((distanceAmount != 0) && (distanceAmount < 2))
                        {
                            string[] amounts = line.Text.Split(" ");
                            newAmount = amounts[0];
                        }
                    }
                    else if (xLine.Length >= 5)
                    {
                        int distanceAmount = CalcLevenshteinDistance(xLine, "Menge");
                        if ((distanceAmount != 0) && (distanceAmount < 2))
                        {
                            string[] amounts = line.Text.Split(" ");
                            newAmount = amounts[0];
                        }
                    }

                    if (newAmount == "")
                    {
                        if (xLine.Contains("eng"))
                        {
                            string[] amounts = line.Text.Split(" ");
                            newAmount = amounts[0];
                        }
                    }
                    if (newReceiptNo == "")
                    {
                        if (xLine.Contains("hle"))
                        {
                            newReceiptNo = line.Text;
                        }
                    }
                    xLine = line.Text;
                }
            }
        }
Esempio n. 6
0
        private static async Task RecognizeContent(FormRecognizerClient recognizerClient)
        {
            var invoiceUri = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/simple-invoice.png";
            FormPageCollection formPages = await recognizerClient
                                           .StartRecognizeContentFromUri(new Uri(invoiceUri))
                                           .WaitForCompletionAsync();

            foreach (FormPage page in formPages)
            {
                Console.WriteLine($"Form Page {page.PageNumber} has {page.Lines.Count} lines.");

                for (int i = 0; i < page.Lines.Count; i++)
                {
                    FormLine line = page.Lines[i];
                    Console.WriteLine($"    Line {i} has {line.Words.Count} word{(line.Words.Count > 1 ? "
            s " : "
            ")}, and text: '{line.Text}'.");
Esempio n. 7
0
        public async Task <IActionResult> AnalyzeLayout(string layoutUri)
        {
            try
            {
                FormRecognizerClient recognizerClient = AuthenticateClient();
                FormPageCollection   formPages        = await recognizerClient
                                                        .StartRecognizeContentFromUri(new Uri(layoutUri))
                                                        .WaitForCompletionAsync();

                if (formPages != null)
                {
                    return(new OkObjectResult(formPages));
                }
                return(new BadRequestObjectResult("No result"));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex.ToString()));
            }
        }
Esempio n. 8
0
        //public async Task RunFormRecognizerClient()
        //{


        //    string trainingDataUrl = "<SAS-URL-of-your-form-folder-in-blob-storage>";
        //    //string formUrl = "<SAS-URL-of-a-form-in-blob-storage>";

        //    string receiptUrl = "https://docs.microsoft.com/azure/cognitive-services/form-recognizer/media"
        //    + "/contoso-allinone.jpg";

        //    // Call Form Recognizer scenarios:
        //    Console.WriteLine("Get form content...");
        //    await GetContent(recognizerClient, formUrl);

        //    Console.WriteLine("Analyze receipt...");
        //    await AnalyzeReceipt(recognizerClient, receiptUrl);

        //    //Console.WriteLine("Train Model with training data...");
        //    //Guid modelId = await TrainModel(trainingClient, trainingDataUrl);

        //    //Console.WriteLine("Analyze PDF form...");
        //    //await AnalyzePdfForm(recognizerClient, modelId, formUrl);

        //    //Console.WriteLine("Manage models...");
        //    //await ManageModels(trainingClient, trainingDataUrl);
        //}

        public async Task <List <string> > ParseForm(string formurl)
        {
            List <string> retstr = new List <string>();

            retstr.Add("<h3>starting Output Rendering</h3>");
            //Response<IReadOnlyList<FormPage>> formPages = await recognizerClient.StartRecognizeContentFromUri(new Uri(invoiceUri)).WaitForCompletionAsync();
            FormRecognizerClient recognizerClient = new FormRecognizerClient(new Uri(endpoint), credential);
            var formPages = await recognizerClient.StartRecognizeContentFromUri(new Uri(formurl)).WaitForCompletionAsync();

            foreach (FormPage page in formPages.Value)
            {
                retstr.Add($"Form Page {page.PageNumber} has {page.Lines.Count}" + $" lines.");

                for (int i = 0; i < page.Lines.Count; i++)
                {
                    FormLine line = page.Lines[i];
                    retstr.Add($"    Line {i} has {line.Words.Count}" +
                               $" word{(line.Words.Count > 1 ? "s" : "")}," +
                               $" and text: '{line.Text}'.");
                }

                for (int i = 0; i < page.Tables.Count; i++)
                {
                    FormTable table = page.Tables[i];
                    retstr.Add($"Table {i} has {table.RowCount} rows and" +
                               $" {table.ColumnCount} columns.");
                    foreach (FormTableCell cell in table.Cells)
                    {
                        retstr.Add($"    Cell ({cell.RowIndex}, {cell.ColumnIndex})" +
                                   $" contains text: '{cell.Text}'.");
                    }
                }
            }
            retstr.Add("<h3>End Output Rendering</h3>");

            return(retstr);
        }
Esempio n. 9
0
        public async Task RecognizeContentFromUri()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            FormRecognizerClient client = new FormRecognizerClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

            Uri invoiceUri = FormRecognizerTestEnvironment.CreateUri("Invoice_1.pdf");

            #region Snippet:FormRecognizerSampleRecognizeContentFromUri

            FormPageCollection formPages = await client.StartRecognizeContentFromUri(invoiceUri).WaitForCompletionAsync();

            foreach (FormPage page in formPages)
            {
                Console.WriteLine($"Form Page {page.PageNumber} has {page.Lines.Count} lines.");

                for (int i = 0; i < page.Lines.Count; i++)
                {
                    FormLine line = page.Lines[i];
                    Console.WriteLine($"    Line {i} has {line.Words.Count} word{(line.Words.Count > 1 ? "s" : "")}, and text: '{line.Text}'.");
                }

                for (int i = 0; i < page.Tables.Count; i++)
                {
                    FormTable table = page.Tables[i];
                    Console.WriteLine($"Table {i} has {table.RowCount} rows and {table.ColumnCount} columns.");
                    foreach (FormTableCell cell in table.Cells)
                    {
                        Console.WriteLine($"    Cell ({cell.RowIndex}, {cell.ColumnIndex}) contains text: '{cell.Text}'.");
                    }
                }
            }

            #endregion
        }