This API can be utilised to perform extraction from the list of extraction plugins depicted below. Rest of the information for the individual API can be found above.

Request Method POST

 

Input for Extraction Type:

Pass the name of extraction API that is to be used in the client header as shown in following code snippet.

The header extractionAPI can have any of the values from the list given below

  • BARCODE_EXTARCTION
  • RECOSTAR_EXTARCTION
  • REGULAR_REGEX_EXTRACTION
  • KV_EXTRACTION
  • FUZZY_DB

Other inputs to the web service are used as per the extraction performed.

 

Web Service URL: http://{serverName}:{port}/dcma/rest/extractFields

Here’s the sample client code using Regular Regex Extraction:

private static void extractFields() {
		HttpClient client = new HttpClient();
		String url = "http://localhost:8080/dcma/rest/extractFields";
		PostMethod mPost = new PostMethod(url);
		File file1 = new File("C:\\sample\\sample.xml");
		// adding xml file for taking input
		File file2 = new File("C:\\sample\\US-Invoice_HOCR.xml");
		try {
			/*
			 * Pass the name of extraction API that is to used: BARCODE_EXTARCTION RECOSTAR_EXTARCTION REGULAR_REGEX_EXTRACTION
			 * KV_EXTRACTION FUZZY_DB
			 */
			Header header = new Header("extractionAPI", "REGULAR_REGEX_EXTRACTION");
			Part[] parts = new Part[3];
			parts[0] = new FilePart(file1.getName(), file1);
			parts[1] = new FilePart(file2.getName(), file2);
			parts[2] = new StringPart("hocrFileName", file2.getName());
			MultipartRequestEntity entity = new MultipartRequestEntity(parts, mPost.getParams());
			mPost.addRequestHeader(header);
			mPost.setRequestEntity(entity);
			int statusCode = client.executeMethod(mPost);
			if (statusCode == 200) {
				System.out.println("Web service executed successfully.");
				System.out.println(mPost.getResponseBodyAsString());
			} else if (statusCode == 403) {
				System.out.println("Invalid username/password.");
			} else {
				System.out.println(mPost.getResponseBodyAsString());
			}
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (mPost != null) {
				mPost.releaseConnection();
			}
		}
	}

Was this article helpful to you?

Engineering

Comments are closed.