Search in sources :

Example 11 with Enrichments

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

the class Discovery method listEnrichments.

/**
 * List Enrichments.
 *
 * <p>Lists the enrichments available to this project. The *Part of Speech* and *Sentiment of
 * Phrases* enrichments might be listed, but are reserved for internal use only.
 *
 * @param listEnrichmentsOptions the {@link ListEnrichmentsOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Enrichments}
 */
public ServiceCall<Enrichments> listEnrichments(ListEnrichmentsOptions listEnrichmentsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listEnrichmentsOptions, "listEnrichmentsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", listEnrichmentsOptions.projectId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "listEnrichments");
    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<Enrichments> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Enrichments>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Enrichments(com.ibm.watson.discovery.v2.model.Enrichments)

Example 12 with Enrichments

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

the class Discovery method updateCollection.

/**
 * Update a collection.
 *
 * <p>Updates the specified collection's name, description, and enrichments.
 *
 * @param updateCollectionOptions the {@link UpdateCollectionOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link CollectionDetails}
 */
public ServiceCall<CollectionDetails> updateCollection(UpdateCollectionOptions updateCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateCollectionOptions, "updateCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", updateCollectionOptions.projectId());
    pathParamsMap.put("collection_id", updateCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateCollection");
    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 (updateCollectionOptions.name() != null) {
        contentJson.addProperty("name", updateCollectionOptions.name());
    }
    if (updateCollectionOptions.description() != null) {
        contentJson.addProperty("description", updateCollectionOptions.description());
    }
    if (updateCollectionOptions.enrichments() != null) {
        contentJson.add("enrichments", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateCollectionOptions.enrichments()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<CollectionDetails> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CollectionDetails>() {
    }.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) CollectionDetails(com.ibm.watson.discovery.v2.model.CollectionDetails)

Example 13 with Enrichments

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

the class Discovery method createEnrichment.

/**
 * Create an enrichment.
 *
 * <p>Create an enrichment for use with the specified project.
 *
 * @param createEnrichmentOptions the {@link CreateEnrichmentOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Enrichment}
 */
public ServiceCall<Enrichment> createEnrichment(CreateEnrichmentOptions createEnrichmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createEnrichmentOptions, "createEnrichmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", createEnrichmentOptions.projectId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "createEnrichment");
    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));
    MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
    multipartBuilder.setType(MultipartBody.FORM);
    multipartBuilder.addFormDataPart("enrichment", createEnrichmentOptions.enrichment().toString());
    if (createEnrichmentOptions.file() != null) {
        okhttp3.RequestBody fileBody = RequestUtils.inputStreamBody(createEnrichmentOptions.file(), "application/octet-stream");
        multipartBuilder.addFormDataPart("file", "filename", fileBody);
    }
    builder.body(multipartBuilder.build());
    ResponseConverter<Enrichment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Enrichment>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody)

Example 14 with Enrichments

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

the class Discovery method getEnrichment.

/**
 * Get enrichment.
 *
 * <p>Get details about a specific enrichment.
 *
 * @param getEnrichmentOptions the {@link GetEnrichmentOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Enrichment}
 */
public ServiceCall<Enrichment> getEnrichment(GetEnrichmentOptions getEnrichmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getEnrichmentOptions, "getEnrichmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", getEnrichmentOptions.projectId());
    pathParamsMap.put("enrichment_id", getEnrichmentOptions.enrichmentId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments/{enrichment_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "getEnrichment");
    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<Enrichment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Enrichment>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 Test (org.testng.annotations.Test)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)6 Enrichment (com.ibm.watson.discovery.v2.model.Enrichment)6 HashMap (java.util.HashMap)6 CollectionDetails (com.ibm.watson.discovery.v2.model.CollectionDetails)5 CollectionEnrichment (com.ibm.watson.discovery.v2.model.CollectionEnrichment)5 JsonObject (com.google.gson.JsonObject)3 CreateEnrichment (com.ibm.watson.discovery.v2.model.CreateEnrichment)3 DeleteEnrichmentOptions (com.ibm.watson.discovery.v2.model.DeleteEnrichmentOptions)2 Enrichments (com.ibm.watson.discovery.v2.model.Enrichments)2 GetEnrichmentOptions (com.ibm.watson.discovery.v2.model.GetEnrichmentOptions)2 UpdateEnrichmentOptions (com.ibm.watson.discovery.v2.model.UpdateEnrichmentOptions)2 CreateCollectionOptions (com.ibm.watson.discovery.v2.model.CreateCollectionOptions)1 CreateEnrichmentOptions (com.ibm.watson.discovery.v2.model.CreateEnrichmentOptions)1 EnrichmentOptions (com.ibm.watson.discovery.v2.model.EnrichmentOptions)1 GetCollectionOptions (com.ibm.watson.discovery.v2.model.GetCollectionOptions)1 ListEnrichmentsOptions (com.ibm.watson.discovery.v2.model.ListEnrichmentsOptions)1 UpdateCollectionOptions (com.ibm.watson.discovery.v2.model.UpdateCollectionOptions)1