use of com.ibm.watson.discovery.v2.model.QueryLargePassages in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testQueryWOptions.
@Test
public void testQueryWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"matching_results\": 15, \"results\": [{\"document_id\": \"documentId\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"result_metadata\": {\"document_retrieval_source\": \"search\", \"collection_id\": \"collectionId\", \"confidence\": 10}, \"document_passages\": [{\"passage_text\": \"passageText\", \"start_offset\": 11, \"end_offset\": 9, \"field\": \"field\", \"confidence\": 0, \"answers\": [{\"answer_text\": \"answerText\", \"start_offset\": 11, \"end_offset\": 9, \"confidence\": 0}]}]}], \"aggregations\": [{\"type\": \"filter\", \"match\": \"match\", \"matching_results\": 15}], \"retrieval_details\": {\"document_retrieval_strategy\": \"untrained\"}, \"suggested_query\": \"suggestedQuery\", \"suggested_refinements\": [{\"text\": \"text\"}], \"table_results\": [{\"table_id\": \"tableId\", \"source_document_id\": \"sourceDocumentId\", \"collection_id\": \"collectionId\", \"table_html\": \"tableHtml\", \"table_html_offset\": 15, \"table\": {\"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\", \"section_title\": {\"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}, \"title\": {\"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}, \"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}], \"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\"}]}], \"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\": [{\"id\": \"id\"}], \"row_header_texts\": [{\"text\": \"text\"}], \"row_header_texts_normalized\": [{\"text_normalized\": \"textNormalized\"}], \"column_header_ids\": [{\"id\": \"id\"}], \"column_header_texts\": [{\"text\": \"text\"}], \"column_header_texts_normalized\": [{\"text_normalized\": \"textNormalized\"}], \"attributes\": [{\"type\": \"type\", \"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}]}], \"contexts\": [{\"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}]}}], \"passages\": [{\"passage_text\": \"passageText\", \"passage_score\": 12, \"document_id\": \"documentId\", \"collection_id\": \"collectionId\", \"start_offset\": 11, \"end_offset\": 9, \"field\": \"field\", \"confidence\": 0, \"answers\": [{\"answer_text\": \"answerText\", \"start_offset\": 11, \"end_offset\": 9, \"confidence\": 0}]}]}";
String queryPath = "/v2/projects/testString/query";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the QueryLargeTableResults model
QueryLargeTableResults queryLargeTableResultsModel = new QueryLargeTableResults.Builder().enabled(true).count(Long.valueOf("26")).build();
// Construct an instance of the QueryLargeSuggestedRefinements model
QueryLargeSuggestedRefinements queryLargeSuggestedRefinementsModel = new QueryLargeSuggestedRefinements.Builder().enabled(true).count(Long.valueOf("1")).build();
// Construct an instance of the QueryLargePassages model
QueryLargePassages queryLargePassagesModel = new QueryLargePassages.Builder().enabled(true).perDocument(true).maxPerDocument(Long.valueOf("26")).fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).count(Long.valueOf("400")).characters(Long.valueOf("50")).findAnswers(false).maxAnswersPerPassage(Long.valueOf("26")).build();
// Construct an instance of the QueryOptions model
QueryOptions queryOptionsModel = new QueryOptions.Builder().projectId("testString").collectionIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).filter("testString").query("testString").naturalLanguageQuery("testString").aggregation("testString").count(Long.valueOf("26")).xReturn(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).offset(Long.valueOf("26")).sort("testString").highlight(true).spellingSuggestions(true).tableResults(queryLargeTableResultsModel).suggestedRefinements(queryLargeSuggestedRefinementsModel).passages(queryLargePassagesModel).build();
// Invoke operation with valid options model (positive test)
Response<QueryResponse> response = discoveryService.query(queryOptionsModel).execute();
assertNotNull(response);
QueryResponse 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");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, queryPath);
}
Aggregations