use of com.ibm.watson.compare_comply.v1.model.TableReturn in project java-sdk by watson-developer-cloud.
the class CompareComply method extractTables.
/**
* Extract a document's tables.
*
* <p>Analyzes the tables in a document.
*
* @param extractTablesOptions the {@link ExtractTablesOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link TableReturn}
*/
public ServiceCall<TableReturn> extractTables(ExtractTablesOptions extractTablesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(extractTablesOptions, "extractTablesOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/tables"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "extractTables");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
if (extractTablesOptions.model() != null) {
builder.query("model", String.valueOf(extractTablesOptions.model()));
}
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
okhttp3.RequestBody fileBody = RequestUtils.inputStreamBody(extractTablesOptions.file(), extractTablesOptions.fileContentType());
multipartBuilder.addFormDataPart("file", "filename", fileBody);
builder.body(multipartBuilder.build());
ResponseConverter<TableReturn> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TableReturn>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.compare_comply.v1.model.TableReturn in project java-sdk by watson-developer-cloud.
the class CompareComplyTest method testExtractTablesWOptions.
@Test
public void testExtractTablesWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"document\": {\"html\": \"html\", \"title\": \"title\", \"hash\": \"hash\"}, \"model_id\": \"modelId\", \"model_version\": \"modelVersion\", \"tables\": [{\"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\", \"section_title\": {\"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}, \"title\": {\"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\"}, \"table_headers\": [{\"cell_id\": \"cellId\", \"location\": {\"mapKey\": \"anyValue\"}, \"text\": \"text\", \"row_index_begin\": 13, \"row_index_end\": 11, \"column_index_begin\": 16, \"column_index_end\": 14}], \"row_headers\": [{\"cell_id\": \"cellId\", \"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\", \"text_normalized\": \"textNormalized\", \"row_index_begin\": 13, \"row_index_end\": 11, \"column_index_begin\": 16, \"column_index_end\": 14}], \"column_headers\": [{\"cell_id\": \"cellId\", \"location\": {\"mapKey\": \"anyValue\"}, \"text\": \"text\", \"text_normalized\": \"textNormalized\", \"row_index_begin\": 13, \"row_index_end\": 11, \"column_index_begin\": 16, \"column_index_end\": 14}], \"body_cells\": [{\"cell_id\": \"cellId\", \"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\", \"row_index_begin\": 13, \"row_index_end\": 11, \"column_index_begin\": 16, \"column_index_end\": 14, \"row_header_ids\": [\"rowHeaderIds\"], \"row_header_texts\": [\"rowHeaderTexts\"], \"row_header_texts_normalized\": [\"rowHeaderTextsNormalized\"], \"column_header_ids\": [\"columnHeaderIds\"], \"column_header_texts\": [\"columnHeaderTexts\"], \"column_header_texts_normalized\": [\"columnHeaderTextsNormalized\"], \"attributes\": [{\"type\": \"Currency\", \"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}]}], \"contexts\": [{\"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}], \"key_value_pairs\": [{\"key\": {\"cell_id\": \"cellId\", \"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\"}, \"value\": [{\"cell_id\": \"cellId\", \"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\"}]}]}]}";
String extractTablesPath = "/v1/tables";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the ExtractTablesOptions model
ExtractTablesOptions extractTablesOptionsModel = new ExtractTablesOptions.Builder().file(TestUtilities.createMockStream("This is a mock file.")).fileContentType("application/pdf").model("contracts").build();
// Invoke operation with valid options model (positive test)
Response<TableReturn> response = compareComplyService.extractTables(extractTablesOptionsModel).execute();
assertNotNull(response);
TableReturn responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
assertEquals(query.get("model"), "contracts");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, extractTablesPath);
}
use of com.ibm.watson.compare_comply.v1.model.TableReturn in project java-sdk by watson-developer-cloud.
the class CompareComplyServiceIT method testExtractTables.
@Test
public void testExtractTables() throws FileNotFoundException {
ExtractTablesOptions extractTablesOptions = new ExtractTablesOptions.Builder().file(TABLE_FILE).fileContentType("image/png").build();
TableReturn response = service.extractTables(extractTablesOptions).execute().getResult();
assertNotNull(response);
// System.out.println(response);
}
Aggregations