Search in sources :

Example 1 with Calculation

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

Example 2 with Calculation

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

Example 3 with Calculation

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

Example 4 with Calculation

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

Aggregations

WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)4 Calculation (com.ibm.watson.developer_cloud.discovery.v1.model.Calculation)4 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)4 QueryResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)4 Test (org.junit.Test)4