Search in sources :

Example 21 with Collection

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

the class DiscoveryServiceTest method listfieldsCollectionIsSuccessful.

// no updateCollection yet?
/**
 * Listfields collection is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void listfieldsCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listfieldsCollResp));
    ListCollectionFieldsOptions getRequest = new ListCollectionFieldsOptions.Builder(environmentId, collectionId).build();
    ListCollectionFieldsResponse response = discoveryService.listCollectionFields(getRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL3_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listfieldsCollResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ListCollectionFieldsOptions(com.ibm.watson.discovery.v1.model.ListCollectionFieldsOptions) ListCollectionFieldsResponse(com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 22 with Collection

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

the class Discovery method createExpansions.

/**
 * Create or update expansion list.
 *
 * <p>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 result of type {@link Expansions}
 */
public ServiceCall<Expansions> createExpansions(CreateExpansionsOptions createExpansionsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createExpansionsOptions, "createExpansionsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", createExpansionsOptions.environmentId());
    pathParamsMap.put("collection_id", createExpansionsOptions.collectionId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/expansions", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createExpansions");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    contentJson.add("expansions", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createExpansionsOptions.expansions()));
    builder.bodyJson(contentJson);
    ResponseConverter<Expansions> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Expansions>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Expansions(com.ibm.watson.discovery.v1.model.Expansions)

Example 23 with Collection

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

the class Discovery method getCollection.

/**
 * Get collection details.
 *
 * @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Collection}
 */
public ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", getCollectionOptions.environmentId());
    pathParamsMap.put("collection_id", getCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getCollection");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Collection(com.ibm.watson.discovery.v1.model.Collection)

Example 24 with Collection

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

the class Discovery method listTrainingData.

/**
 * List training data.
 *
 * <p>Lists the training data for the specified collection.
 *
 * @param listTrainingDataOptions the {@link ListTrainingDataOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link TrainingDataSet}
 */
public ServiceCall<TrainingDataSet> listTrainingData(ListTrainingDataOptions listTrainingDataOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listTrainingDataOptions, "listTrainingDataOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", listTrainingDataOptions.environmentId());
    pathParamsMap.put("collection_id", listTrainingDataOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listTrainingData");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<TrainingDataSet> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingDataSet>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TrainingDataSet(com.ibm.watson.discovery.v1.model.TrainingDataSet)

Example 25 with Collection

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

the class Discovery method createTokenizationDictionary.

/**
 * Create tokenization dictionary.
 *
 * <p>Upload a custom tokenization dictionary to use with the specified collection.
 *
 * @param createTokenizationDictionaryOptions the {@link CreateTokenizationDictionaryOptions}
 *     containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link TokenDictStatusResponse}
 */
public ServiceCall<TokenDictStatusResponse> createTokenizationDictionary(CreateTokenizationDictionaryOptions createTokenizationDictionaryOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createTokenizationDictionaryOptions, "createTokenizationDictionaryOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", createTokenizationDictionaryOptions.environmentId());
    pathParamsMap.put("collection_id", createTokenizationDictionaryOptions.collectionId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/word_lists/tokenization_dictionary", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createTokenizationDictionary");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    if (createTokenizationDictionaryOptions.tokenizationRules() != null) {
        contentJson.add("tokenization_rules", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createTokenizationDictionaryOptions.tokenizationRules()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<TokenDictStatusResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TokenDictStatusResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)23 HashMap (java.util.HashMap)22 Test (org.junit.Test)22 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 JsonObject (com.google.gson.JsonObject)15 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)11 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)10 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)9 Collection (com.ibm.watson.discovery.v1.model.Collection)9 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 MockResponse (okhttp3.mockwebserver.MockResponse)8 Test (org.testng.annotations.Test)7 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5