Search in sources :

Example 1 with QueryPassages

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"));
    }
}
Also used : QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) QueryPassages(com.ibm.watson.developer_cloud.discovery.v1.model.QueryPassages) QueryOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)1 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)1 QueryPassages (com.ibm.watson.developer_cloud.discovery.v1.model.QueryPassages)1 QueryResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)1 FileInputStream (java.io.FileInputStream)1 Test (org.junit.Test)1