Search in sources :

Example 21 with Discovery

use of com.ibm.watson.discovery.v2.Discovery 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 22 with Discovery

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

the class Discovery method queryCollectionNotices.

/**
 * Query collection notices.
 *
 * <p>Finds collection-level notices (errors and warnings) that are generated when documents are
 * ingested.
 *
 * @param queryCollectionNoticesOptions the {@link QueryCollectionNoticesOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link QueryNoticesResponse}
 */
public ServiceCall<QueryNoticesResponse> queryCollectionNotices(QueryCollectionNoticesOptions queryCollectionNoticesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(queryCollectionNoticesOptions, "queryCollectionNoticesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", queryCollectionNoticesOptions.projectId());
    pathParamsMap.put("collection_id", queryCollectionNoticesOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}/notices", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "queryCollectionNotices");
    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));
    if (queryCollectionNoticesOptions.filter() != null) {
        builder.query("filter", String.valueOf(queryCollectionNoticesOptions.filter()));
    }
    if (queryCollectionNoticesOptions.query() != null) {
        builder.query("query", String.valueOf(queryCollectionNoticesOptions.query()));
    }
    if (queryCollectionNoticesOptions.naturalLanguageQuery() != null) {
        builder.query("natural_language_query", String.valueOf(queryCollectionNoticesOptions.naturalLanguageQuery()));
    }
    if (queryCollectionNoticesOptions.count() != null) {
        builder.query("count", String.valueOf(queryCollectionNoticesOptions.count()));
    }
    if (queryCollectionNoticesOptions.offset() != null) {
        builder.query("offset", String.valueOf(queryCollectionNoticesOptions.offset()));
    }
    ResponseConverter<QueryNoticesResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<QueryNoticesResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) QueryNoticesResponse(com.ibm.watson.discovery.v2.model.QueryNoticesResponse)

Example 23 with Discovery

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

the class Discovery method updateTrainingQuery.

/**
 * Update a training query.
 *
 * <p>Updates an existing training query and it's examples.
 *
 * @param updateTrainingQueryOptions the {@link UpdateTrainingQueryOptions} containing the options
 *     for the call
 * @return a {@link ServiceCall} with a result of type {@link TrainingQuery}
 */
public ServiceCall<TrainingQuery> updateTrainingQuery(UpdateTrainingQueryOptions updateTrainingQueryOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateTrainingQueryOptions, "updateTrainingQueryOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", updateTrainingQueryOptions.projectId());
    pathParamsMap.put("query_id", updateTrainingQueryOptions.queryId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/training_data/queries/{query_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateTrainingQuery");
    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.addProperty("natural_language_query", updateTrainingQueryOptions.naturalLanguageQuery());
    contentJson.add("examples", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateTrainingQueryOptions.examples()));
    if (updateTrainingQueryOptions.filter() != null) {
        contentJson.addProperty("filter", updateTrainingQueryOptions.filter());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<TrainingQuery> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingQuery>() {
    }.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) TrainingQuery(com.ibm.watson.discovery.v2.model.TrainingQuery)

Example 24 with Discovery

use of com.ibm.watson.discovery.v2.Discovery 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)

Example 25 with Discovery

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

the class Discovery method listTrainingQueries.

/**
 * List training queries.
 *
 * <p>List the training queries for the specified project.
 *
 * @param listTrainingQueriesOptions the {@link ListTrainingQueriesOptions} containing the options
 *     for the call
 * @return a {@link ServiceCall} with a result of type {@link TrainingQuerySet}
 */
public ServiceCall<TrainingQuerySet> listTrainingQueries(ListTrainingQueriesOptions listTrainingQueriesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listTrainingQueriesOptions, "listTrainingQueriesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", listTrainingQueriesOptions.projectId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/training_data/queries", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "listTrainingQueries");
    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<TrainingQuerySet> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingQuerySet>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TrainingQuerySet(com.ibm.watson.discovery.v2.model.TrainingQuerySet)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)26 HashMap (java.util.HashMap)24 JsonObject (com.google.gson.JsonObject)9 DocumentAccepted (com.ibm.watson.discovery.v2.model.DocumentAccepted)4 MultipartBody (okhttp3.MultipartBody)4 CollectionDetails (com.ibm.watson.discovery.v2.model.CollectionDetails)3 Enrichment (com.ibm.watson.discovery.v2.model.Enrichment)3 ProjectDetails (com.ibm.watson.discovery.v2.model.ProjectDetails)3 TrainingQuery (com.ibm.watson.discovery.v2.model.TrainingQuery)3 AddDocumentOptions (com.ibm.watson.discovery.v2.model.AddDocumentOptions)2 QueryNoticesResponse (com.ibm.watson.discovery.v2.model.QueryNoticesResponse)2 QueryResponse (com.ibm.watson.discovery.v2.model.QueryResponse)2 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)1 BearerTokenAuthenticator (com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator)1 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)1 Discovery (com.ibm.watson.discovery.v2.Discovery)1 AnalyzedDocument (com.ibm.watson.discovery.v2.model.AnalyzedDocument)1 Completions (com.ibm.watson.discovery.v2.model.Completions)1 ComponentSettingsResponse (com.ibm.watson.discovery.v2.model.ComponentSettingsResponse)1 DeleteDocumentOptions (com.ibm.watson.discovery.v2.model.DeleteDocumentOptions)1