Search in sources :

Example 1 with Expansion

use of com.ibm.watson.developer_cloud.discovery.v1.model.Expansion in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method expansionsOperationsAreSuccessful.

@Test
public void expansionsOperationsAreSuccessful() {
    List<String> expansion1InputTerms = Arrays.asList("weekday", "week day");
    List<String> expansion1ExpandedTerms = Arrays.asList("monday", "tuesday", "wednesday", "thursday", "friday");
    List<String> expansion2InputTerms = Arrays.asList("weekend", "week end");
    List<String> expansion2ExpandedTerms = Arrays.asList("saturday", "sunday");
    Expansion expansion1 = new Expansion();
    expansion1.setInputTerms(expansion1InputTerms);
    expansion1.setExpandedTerms(expansion1ExpandedTerms);
    Expansion expansion2 = new Expansion();
    expansion2.setInputTerms(expansion2InputTerms);
    expansion2.setExpandedTerms(expansion2ExpandedTerms);
    Expansions expansions = new Expansions();
    expansions.setExpansions(Arrays.asList(expansion1, expansion2));
    CreateExpansionsOptions createOptions = new CreateExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).expansions(expansions).build();
    Expansions createResults = discovery.createExpansions(createOptions).execute();
    assertEquals(createResults.getExpansions().size(), 2);
    assertEquals(createResults.getExpansions().get(0).getInputTerms(), expansion1InputTerms);
    assertEquals(createResults.getExpansions().get(0).getExpandedTerms(), expansion1ExpandedTerms);
    assertEquals(createResults.getExpansions().get(1).getInputTerms(), expansion2InputTerms);
    assertEquals(createResults.getExpansions().get(1).getExpandedTerms(), expansion2ExpandedTerms);
    ListExpansionsOptions listOptions = new ListExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    Expansions listResults = discovery.listExpansions(listOptions).execute();
    assertEquals(listResults.getExpansions().size(), 2);
    DeleteExpansionsOptions deleteOptions = new DeleteExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    discovery.deleteExpansions(deleteOptions).execute();
    Expansions emptyListResults = discovery.listExpansions(listOptions).execute();
    assertTrue(emptyListResults.getExpansions().get(0).getInputTerms() == null || emptyListResults.getExpansions().get(0).getInputTerms().isEmpty());
    assertTrue(emptyListResults.getExpansions().get(0).getExpandedTerms() == null || emptyListResults.getExpansions().get(0).getExpandedTerms().get(0).isEmpty());
}
Also used : ListExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListExpansionsOptions) Expansion(com.ibm.watson.developer_cloud.discovery.v1.model.Expansion) CreateExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateExpansionsOptions) Expansions(com.ibm.watson.developer_cloud.discovery.v1.model.Expansions) DeleteExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteExpansionsOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with Expansion

use of com.ibm.watson.developer_cloud.discovery.v1.model.Expansion in project java-sdk by watson-developer-cloud.

the class Discovery method listExpansions.

/**
 * List current expansions.
 *
 * Returns the current expansion list for the specified collection. If an expansion list is not specified, an object
 * with empty expansion arrays is returned.
 *
 * @param listExpansionsOptions the {@link ListExpansionsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Expansions}
 */
public ServiceCall<Expansions> listExpansions(ListExpansionsOptions listExpansionsOptions) {
    Validator.notNull(listExpansionsOptions, "listExpansionsOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "expansions" };
    String[] pathParameters = { listExpansionsOptions.environmentId(), listExpansionsOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Expansions.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Expansions(com.ibm.watson.developer_cloud.discovery.v1.model.Expansions)

Example 3 with Expansion

use of com.ibm.watson.developer_cloud.discovery.v1.model.Expansion in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method createExpansionsIsSuccessful.

@Test
public void createExpansionsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(expansionsResp));
    List<String> expansion1InputTerms = Arrays.asList("weekday", "week day");
    List<String> expansion1ExpandedTerms = Arrays.asList("monday", "tuesday", "wednesday", "thursday", "friday");
    List<String> expansion2InputTerms = Arrays.asList("weekend", "week end");
    List<String> expansion2ExpandedTerms = Arrays.asList("saturday", "sunday");
    Expansion expansion1 = new Expansion();
    expansion1.setInputTerms(expansion1InputTerms);
    expansion1.setExpandedTerms(expansion1ExpandedTerms);
    Expansion expansion2 = new Expansion();
    expansion2.setInputTerms(expansion2InputTerms);
    expansion2.setExpandedTerms(expansion2ExpandedTerms);
    Expansions expansions = new Expansions();
    expansions.setExpansions(Arrays.asList(expansion1, expansion2));
    CreateExpansionsOptions createOptions = new CreateExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).expansions(expansions).build();
    Expansions createResults = discoveryService.createExpansions(createOptions).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(EXPANSIONS_PATH, request.getPath());
    assertEquals(POST, request.getMethod());
    assertEquals(expansion1, createResults.getExpansions().get(0));
    assertEquals(expansion2, createResults.getExpansions().get(1));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Expansion(com.ibm.watson.developer_cloud.discovery.v1.model.Expansion) CreateExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateExpansionsOptions) Expansions(com.ibm.watson.developer_cloud.discovery.v1.model.Expansions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 4 with Expansion

use of com.ibm.watson.developer_cloud.discovery.v1.model.Expansion in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method listExpansionsIsSuccessful.

@Test
public void listExpansionsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(expansionsResp));
    List<String> expansion1InputTerms = Arrays.asList("weekday", "week day");
    List<String> expansion1ExpandedTerms = Arrays.asList("monday", "tuesday", "wednesday", "thursday", "friday");
    List<String> expansion2InputTerms = Arrays.asList("weekend", "week end");
    List<String> expansion2ExpandedTerms = Arrays.asList("saturday", "sunday");
    Expansion expansion1 = new Expansion();
    expansion1.setInputTerms(expansion1InputTerms);
    expansion1.setExpandedTerms(expansion1ExpandedTerms);
    Expansion expansion2 = new Expansion();
    expansion2.setInputTerms(expansion2InputTerms);
    expansion2.setExpandedTerms(expansion2ExpandedTerms);
    ListExpansionsOptions listOptions = new ListExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    Expansions listResults = discoveryService.listExpansions(listOptions).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(EXPANSIONS_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(expansion1, listResults.getExpansions().get(0));
    assertEquals(expansion2, listResults.getExpansions().get(1));
}
Also used : ListExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListExpansionsOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Expansion(com.ibm.watson.developer_cloud.discovery.v1.model.Expansion) Expansions(com.ibm.watson.developer_cloud.discovery.v1.model.Expansions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 5 with Expansion

use of com.ibm.watson.developer_cloud.discovery.v1.model.Expansion in project java-sdk by watson-developer-cloud.

the class Discovery method createExpansions.

/**
 * Set the expansion list.
 *
 * Create or replace the Expansion list for this collection. The maximum number of expanded terms per collection is
 * `500`. The current expansion list is replaced with the uploaded content.
 *
 * @param createExpansionsOptions the {@link CreateExpansionsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Expansions}
 */
public ServiceCall<Expansions> createExpansions(CreateExpansionsOptions createExpansionsOptions) {
    Validator.notNull(createExpansionsOptions, "createExpansionsOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "expansions" };
    String[] pathParameters = { createExpansionsOptions.environmentId(), createExpansionsOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (createExpansionsOptions.expansions() != null) {
        contentJson.add("expansions", GsonSingleton.getGson().toJsonTree(createExpansionsOptions.expansions()));
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Expansions.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Expansions(com.ibm.watson.developer_cloud.discovery.v1.model.Expansions)

Aggregations

Expansions (com.ibm.watson.developer_cloud.discovery.v1.model.Expansions)5 Expansion (com.ibm.watson.developer_cloud.discovery.v1.model.Expansion)3 Test (org.junit.Test)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 CreateExpansionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateExpansionsOptions)2 ListExpansionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListExpansionsOptions)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 JsonObject (com.google.gson.JsonObject)1 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 DeleteExpansionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteExpansionsOptions)1