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); } }
public static string SetDocHTML(docu3clist docs) { string _html = ""; if (docs.Count > 0) { if (docs[0].docProps.ContainsKey("doc.type")) { _html += "<h6 class='text-warning'>doc.type : <span class='text-success'>" + docs[0].docProps["doc.type"].Value.ToString() + "</span></h6>"; } if (docs[0].docProps.ContainsKey("org.name")) { _html += "<h6 class='text-warning'>org.name : <span class='text-success'>" + docs[0].docProps["org.name"].Value.ToString() + "</span></h6>"; } if (docs[0].docProps.ContainsKey("cust.name")) { _html += "<h6 class='text-warning'>cust.name : <span class='text-success'>" + docs[0].docProps["cust.name"].Value.ToString() + "</span></h6>"; } if (docs[0].docProps.ContainsKey("cust.dob")) { _html += "<h6 class='text-warning'>cust.dob : <span class='text-success'>" + docs[0].docProps["cust.dob"].Value.ToString() + "</span></h6>"; } if (docs[0].docProps.ContainsKey("cust.ssn")) { _html += "<h6 class='text-warning'>cust.ssn : <span class='text-success'>" + docs[0].docProps["cust.ssn"].Value.ToString() + "</span></h6>"; } if (docs[0].docProps.ContainsKey("cust.addr")) { _html += "<h6 class='text-warning'>cust.addr : <span class='text-success'>" + docs[0].docProps["cust.addr"].Value.ToString() + "</span></h6>"; } } return(_html); }
private string CompareProperties(docu3clist sel, docu3clist curr) { string _html = "ERROR"; if (sel.Count == 0 || curr.Count == 0) { return(_html); } _html = ""; var seldoc = sel[0]; var currdoc = curr[0]; foreach (var key in seldoc.docProps.Keys) { if (key == "doc.type" || key == "org.name") { continue; } if (!currdoc.docProps.ContainsKey(key)) { continue; } if (!seldoc.docProps[key].Value.Replace(" ", "").Equals(currdoc.docProps[key].Value.Replace(" ", ""))) { _html += "<h6 class='text-warning'>Mismatch for " + key + ": <span class='text-success'>" + seldoc.docProps[key].Value.ToString() + " | vs | " + currdoc.docProps[key].Value.ToString() + "</span></h6>"; } } if (_html == "") { _html += "<h6 class='text-success'>Documents Match!!!</h6>"; } return(_html); }
public string CheckFileProperties(string pID, string fID) { //for the given portfolio, get ALL OTHER file properties. string _html = ""; docu3clist selfile = GetFileProperties(pID, fID); var ds = InitDatSet(); if (ds.Tables.Contains("file")) { docu3clist currfile; foreach (DataRow dr in ds.Tables["file"].Rows) { if (dr["fID"].ToString() != fID && dr["fType"].ToString() != "UNKNOWN") { _html += "<h6 class='text-warning'>Comparing with : (" + dr["fType"] + ")" + dr["fName"] + "</h6>"; currfile = GetFileProperties(pID, dr["fID"].ToString()); var ret_html = CompareProperties(selfile, currfile); if (ret_html == "ERROR") { _html += "<h6 class='text-warning'>Could not compare documents</h6>"; } else { _html += ret_html; } } } } return(_html); }
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); } }
public void SaveFileProperties(string pID, string fID, docu3clist docs) { string binfile = _env.WebRootPath + "/data/" + pID + "/" + fID + ".bin"; IFormatter formatter = new BinaryFormatter(); if (File.Exists(binfile)) { File.Delete(binfile); } using (Stream stream = new FileStream(binfile, FileMode.Create, FileAccess.Write)) { formatter.Serialize(stream, docs); } }
public docu3clist GetFileProperties(string pID, string fID) { string binfile = _env.WebRootPath + "/data/" + pID + "/" + fID + ".bin"; docu3clist docs = new docu3clist(); if (!File.Exists(binfile)) { return(docs); } IFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(binfile, FileMode.Open, FileAccess.Read)) { docs = (docu3clist)formatter.Deserialize(stream); } docs.html = docu3cAPIClient.SetDocHTML(docs); return(docs); }