Search in sources :

Example 11 with Discovery

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

the class Discovery method query.

/**
 * Query a project.
 *
 * <p>By using this method, you can construct queries. For details, see the [Discovery
 * documentation](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-query-concepts).
 * The default query parameters are defined by the settings for this project, see the [Discovery
 * documentation](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-project-defaults)
 * for an overview of the standard default settings, and see [the Projects API
 * documentation](#create-project) for details about how to set custom default query settings.
 *
 * @param queryOptions the {@link QueryOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link QueryResponse}
 */
public ServiceCall<QueryResponse> query(QueryOptions queryOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(queryOptions, "queryOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", queryOptions.projectId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/query", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "query");
    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 (queryOptions.collectionIds() != null) {
        contentJson.add("collection_ids", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(queryOptions.collectionIds()));
    }
    if (queryOptions.filter() != null) {
        contentJson.addProperty("filter", queryOptions.filter());
    }
    if (queryOptions.query() != null) {
        contentJson.addProperty("query", queryOptions.query());
    }
    if (queryOptions.naturalLanguageQuery() != null) {
        contentJson.addProperty("natural_language_query", queryOptions.naturalLanguageQuery());
    }
    if (queryOptions.aggregation() != null) {
        contentJson.addProperty("aggregation", queryOptions.aggregation());
    }
    if (queryOptions.count() != null) {
        contentJson.addProperty("count", queryOptions.count());
    }
    if (queryOptions.xReturn() != null) {
        contentJson.add("return", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(queryOptions.xReturn()));
    }
    if (queryOptions.offset() != null) {
        contentJson.addProperty("offset", queryOptions.offset());
    }
    if (queryOptions.sort() != null) {
        contentJson.addProperty("sort", queryOptions.sort());
    }
    if (queryOptions.highlight() != null) {
        contentJson.addProperty("highlight", queryOptions.highlight());
    }
    if (queryOptions.spellingSuggestions() != null) {
        contentJson.addProperty("spelling_suggestions", queryOptions.spellingSuggestions());
    }
    if (queryOptions.tableResults() != null) {
        contentJson.add("table_results", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(queryOptions.tableResults()));
    }
    if (queryOptions.suggestedRefinements() != null) {
        contentJson.add("suggested_refinements", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(queryOptions.suggestedRefinements()));
    }
    if (queryOptions.passages() != null) {
        contentJson.add("passages", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(queryOptions.passages()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<QueryResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<QueryResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) QueryResponse(com.ibm.watson.discovery.v2.model.QueryResponse) JsonObject(com.google.gson.JsonObject)

Example 12 with Discovery

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

the class Discovery method createProject.

/**
 * Create a Project.
 *
 * <p>Create a new project for this instance.
 *
 * @param createProjectOptions the {@link CreateProjectOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link ProjectDetails}
 */
public ServiceCall<ProjectDetails> createProject(CreateProjectOptions createProjectOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createProjectOptions, "createProjectOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "createProject");
    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("name", createProjectOptions.name());
    contentJson.addProperty("type", createProjectOptions.type());
    if (createProjectOptions.defaultQueryParameters() != null) {
        contentJson.add("default_query_parameters", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createProjectOptions.defaultQueryParameters()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<ProjectDetails> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ProjectDetails>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : ProjectDetails(com.ibm.watson.discovery.v2.model.ProjectDetails) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject)

Example 13 with Discovery

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

the class Discovery method updateEnrichment.

/**
 * Update an enrichment.
 *
 * <p>Updates an existing enrichment's name and description.
 *
 * @param updateEnrichmentOptions the {@link UpdateEnrichmentOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Enrichment}
 */
public ServiceCall<Enrichment> updateEnrichment(UpdateEnrichmentOptions updateEnrichmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateEnrichmentOptions, "updateEnrichmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", updateEnrichmentOptions.projectId());
    pathParamsMap.put("enrichment_id", updateEnrichmentOptions.enrichmentId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments/{enrichment_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateEnrichment");
    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("name", updateEnrichmentOptions.name());
    if (updateEnrichmentOptions.description() != null) {
        contentJson.addProperty("description", updateEnrichmentOptions.description());
    }
    builder.bodyJson(contentJson);
    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) JsonObject(com.google.gson.JsonObject)

Example 14 with Discovery

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

the class Discovery method updateProject.

/**
 * Update a project.
 *
 * <p>Update the specified project's name.
 *
 * @param updateProjectOptions the {@link UpdateProjectOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link ProjectDetails}
 */
public ServiceCall<ProjectDetails> updateProject(UpdateProjectOptions updateProjectOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateProjectOptions, "updateProjectOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", updateProjectOptions.projectId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateProject");
    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 (updateProjectOptions.name() != null) {
        contentJson.addProperty("name", updateProjectOptions.name());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<ProjectDetails> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ProjectDetails>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : ProjectDetails(com.ibm.watson.discovery.v2.model.ProjectDetails) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Example 15 with Discovery

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

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