Example #1
0
        public docu3clist ClassifyDocument(string doc_type, string formUri)
        {
            docu3clist docs = new docu3clist();

            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(SERVICE_URL);
                //For local web service, comment out this line.
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", API_KEY);

                docu3cInput inputJson = new docu3cInput();
                inputJson.doc_type = doc_type; inputJson.formUri = formUri;

                var request = new HttpRequestMessage(HttpMethod.Post, string.Empty);
                request.Content = new StringContent(JsonConvert.SerializeObject(inputJson));
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = client.SendAsync(request).Result;

                var jsonString = response.Content.ReadAsStringAsync().Result;
                docs = JsonConvert.DeserializeObject <docu3clist>(jsonString);

                return(docs);
            }
            catch (Exception ex)
            {
                docu3c doc = new docu3c();
                doc.docParseErrorMsg = ex.Message;
                docs.Add(doc);
                return(docs);
            }
        }
Example #2
0
        public async Task <docu3clist> ClassifyDocument(string doc_type, string formUri)
        {
            docu3clist docs    = new docu3clist();
            string     modelId = GetModelID(doc_type);

            try
            {
                WebClient wc         = new WebClient();
                byte[]    imageBytes = wc.DownloadData(formUri);
                var       stream     = new MemoryStream(imageBytes);

                FormRecognizerClient recognizerClient = new FormRecognizerClient(new Uri(endpoint), credential);
                //var forms = await recognizerClient.StartRecognizeCustomFormsFromUri(modelId,new Uri(formUri)).WaitForCompletionAsync();
                //Response<IReadOnlyList<RecognizedForm>>
                var forms = await recognizerClient.StartRecognizeCustomForms(modelId, stream).WaitForCompletionAsync();

                foreach (RecognizedForm form in forms.Value)
                {
                    docu3c doc = new docu3c();
                    doc.docID    = formUri;
                    doc.docURL   = formUri;
                    doc.docType  = form.FormType;
                    doc.docProps = new Dictionary <string, docu3cProp>();
                    foreach (FormField field in form.Fields.Values)
                    {
                        if (field != null)
                        {
                            docu3cProp prop = new docu3cProp();
                            prop.Name = field.Name;
                            if (field.LabelText != null)
                            {
                                prop.Label = field.LabelText;
                            }
                            if (field.Name == "doc.type")
                            {
                                prop.Value = field.ValueText.Text.Replace(" ", "_");
                            }
                            else
                            {
                                prop.Value = field.ValueText.Text;
                            }
                            prop.Confidence = field.Confidence;
                            doc.docProps.Add(field.Name, prop);
                        }
                    }
                    docs.Add(doc);
                }

                //docs.html = docu3cAPI.SetDocHTML(docs);
                return(docs);
            }
            catch (Exception ex)
            {
                docu3c doc = new docu3c();
                doc.docParseErrorMsg = ex.Message;
                docs.Add(doc);
                return(docs);
            }
        }