use of com.ibm.watson.developer_cloud.discovery.v1.model.QueryPassages in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithPassagesIsSuccessful.
@Test
public void queryWithPassagesIsSuccessful() throws InterruptedException, FileNotFoundException {
Collection testCollection = createTestCollection();
String collectionId = testCollection.getCollectionId();
createTestDocument(getStringFromInputStream(new FileInputStream(PASSAGES_TEST_FILE_1)), "test_document_1", collectionId);
createTestDocument(getStringFromInputStream(new FileInputStream(PASSAGES_TEST_FILE_2)), "test_document_2", collectionId);
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
queryBuilder.passages(true);
queryBuilder.naturalLanguageQuery("Watson");
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
List<QueryPassages> passages = queryResponse.getPassages();
assertTrue(passages.size() > 0);
for (QueryPassages passage : passages) {
assertTrue(passage.getPassageText().contains("Watson"));
}
}
Aggregations