use of com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithAggregationMaximumIsSuccessful.
@Test
public void queryWithAggregationMaximumIsSuccessful() throws InterruptedException {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
StringBuilder sb = new StringBuilder();
sb.append(AggregationType.MAX);
sb.append(Operator.OPENING_GROUPING);
sb.append("field");
sb.append(Operator.CLOSING_GROUPING);
String aggregation = sb.toString();
queryBuilder.aggregation(aggregation);
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
Calculation max = (Calculation) queryResponse.getAggregations().get(0);
assertEquals(AggregationType.MAX.getName(), max.getType());
assertEquals(new Double(9), max.getValue());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method getTrainingDataIsSuccessful.
@Test
public void getTrainingDataIsSuccessful() {
String naturalLanguageQuery = "Query" + UUID.randomUUID().toString();
TrainingQuery newQuery = createTestQuery(collectionId, naturalLanguageQuery);
String queryId = newQuery.getQueryId();
GetTrainingDataOptions.Builder queryBuilder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
TrainingQuery queryResponse = discovery.getTrainingData(queryBuilder.build()).execute();
assertEquals(queryResponse.getNaturalLanguageQuery(), naturalLanguageQuery);
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithCountIsSuccessful.
// query tests
@Test
public void queryWithCountIsSuccessful() {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
queryBuilder.count(5L);
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
assertEquals(new Long(10), queryResponse.getMatchingResults());
assertEquals(5, queryResponse.getResults().size());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithOffsetIsSuccessful.
@Test
public void queryWithOffsetIsSuccessful() {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
queryBuilder.offset(5L);
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
assertEquals(new Long(10), queryResponse.getMatchingResults());
assertEquals(5, queryResponse.getResults().size());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method addDocumentWithMetadataIsSuccessful.
@Ignore
@SuppressWarnings("deprecation")
@Test
public void addDocumentWithMetadataIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
String myDocumentJson = "{\"field\":\"value\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder(environmentId, collectionId);
builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
builder.filename("test_file");
builder.metadata(myMetadata.toString());
DocumentAccepted createResponse = discovery.addDocument(builder.build()).execute();
WaitFor.Condition documentAccepted = new WaitForDocumentAccepted(environmentId, collectionId, createResponse.getDocumentId());
WaitFor.waitFor(documentAccepted, 5, TimeUnit.SECONDS, 500);
QueryOptions queryOptions = new QueryOptions.Builder(environmentId, collectionId).build();
QueryResponse queryResponse = discovery.query(queryOptions).execute();
assertTrue(queryResponse.getResults().get(0).getMetadata() != null);
}
Aggregations