use of com.ibm.watson.developer_cloud.discovery.v1.model.Calculation in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithAggregationAverageIsSuccessful.
@Test
public void queryWithAggregationAverageIsSuccessful() throws InterruptedException {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
StringBuilder sb = new StringBuilder();
sb.append(AggregationType.AVERAGE);
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 avg = (Calculation) queryResponse.getAggregations().get(0);
assertEquals(AggregationType.AVERAGE.getName(), avg.getType());
assertEquals(new Double(4.5), avg.getValue());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.Calculation in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithAggregationMinimumIsSuccessful.
@Test
public void queryWithAggregationMinimumIsSuccessful() throws InterruptedException {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
StringBuilder sb = new StringBuilder();
sb.append(AggregationType.MIN);
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 min = (Calculation) queryResponse.getAggregations().get(0);
assertEquals(AggregationType.MIN.getName(), min.getType());
assertEquals(new Double(0), min.getValue());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.Calculation 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.Calculation in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithAggregationSummationIsSuccessful.
@Test
public void queryWithAggregationSummationIsSuccessful() throws InterruptedException {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
StringBuilder sb = new StringBuilder();
sb.append(AggregationType.SUM);
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 sum = (Calculation) queryResponse.getAggregations().get(0);
assertEquals(AggregationType.SUM.getName(), sum.getType());
assertEquals(new Double(45), sum.getValue());
}
Aggregations