Search in sources :

Example 31 with Intent

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

the class Assistant method listMentions.

/**
 * List entity mentions.
 *
 * <p>List mentions for a contextual entity. An entity mention is an occurrence of a contextual
 * entity in the context of an intent user input example.
 *
 * @param listMentionsOptions the {@link ListMentionsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link EntityMentionCollection}
 */
public ServiceCall<EntityMentionCollection> listMentions(ListMentionsOptions listMentionsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listMentionsOptions, "listMentionsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", listMentionsOptions.workspaceId());
    pathParamsMap.put("entity", listMentionsOptions.entity());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/mentions", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "listMentions");
    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 (listMentionsOptions.export() != null) {
        builder.query("export", String.valueOf(listMentionsOptions.export()));
    }
    if (listMentionsOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(listMentionsOptions.includeAudit()));
    }
    ResponseConverter<EntityMentionCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<EntityMentionCollection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) EntityMentionCollection(com.ibm.watson.assistant.v1.model.EntityMentionCollection)

Example 32 with Intent

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

the class Assistant method createIntent.

/**
 * Create intent.
 *
 * <p>Create a new intent.
 *
 * <p>If you want to create multiple intents with a single API call, consider using the **[Update
 * workspace](#update-workspace)** method instead.
 *
 * @param createIntentOptions the {@link CreateIntentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Intent}
 */
public ServiceCall<Intent> createIntent(CreateIntentOptions createIntentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createIntentOptions, "createIntentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", createIntentOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "createIntent");
    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 (createIntentOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(createIntentOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("intent", createIntentOptions.intent());
    if (createIntentOptions.description() != null) {
        contentJson.addProperty("description", createIntentOptions.description());
    }
    if (createIntentOptions.examples() != null) {
        contentJson.add("examples", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createIntentOptions.examples()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Intent> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Intent>() {
    }.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) Intent(com.ibm.watson.assistant.v1.model.Intent)

Example 33 with Intent

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

the class Assistant method updateIntent.

/**
 * Update intent.
 *
 * <p>Update an existing intent with new or modified data. You must provide component objects
 * defining the content of the updated intent.
 *
 * <p>If you want to update multiple intents with a single API call, consider using the **[Update
 * workspace](#update-workspace)** method instead.
 *
 * @param updateIntentOptions the {@link UpdateIntentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Intent}
 */
public ServiceCall<Intent> updateIntent(UpdateIntentOptions updateIntentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateIntentOptions, "updateIntentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateIntentOptions.workspaceId());
    pathParamsMap.put("intent", updateIntentOptions.intent());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents/{intent}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateIntent");
    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 (updateIntentOptions.append() != null) {
        builder.query("append", String.valueOf(updateIntentOptions.append()));
    }
    if (updateIntentOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateIntentOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateIntentOptions.newIntent() != null) {
        contentJson.addProperty("intent", updateIntentOptions.newIntent());
    }
    if (updateIntentOptions.newDescription() != null) {
        contentJson.addProperty("description", updateIntentOptions.newDescription());
    }
    if (updateIntentOptions.newExamples() != null) {
        contentJson.add("examples", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateIntentOptions.newExamples()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Intent> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Intent>() {
    }.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) Intent(com.ibm.watson.assistant.v1.model.Intent)

Example 34 with Intent

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

the class Assistant method getIntent.

/**
 * Get intent.
 *
 * <p>Get information about an intent, optionally including all intent content.
 *
 * @param getIntentOptions the {@link GetIntentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Intent}
 */
public ServiceCall<Intent> getIntent(GetIntentOptions getIntentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getIntentOptions, "getIntentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", getIntentOptions.workspaceId());
    pathParamsMap.put("intent", getIntentOptions.intent());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents/{intent}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "getIntent");
    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 (getIntentOptions.export() != null) {
        builder.query("export", String.valueOf(getIntentOptions.export()));
    }
    if (getIntentOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getIntentOptions.includeAudit()));
    }
    ResponseConverter<Intent> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Intent>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Intent(com.ibm.watson.assistant.v1.model.Intent)

Example 35 with Intent

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

the class Assistant method updateExample.

/**
 * Update user input example.
 *
 * <p>Update the text of a user input example.
 *
 * <p>If you want to update multiple examples with a single API call, consider using the **[Update
 * intent](#update-intent)** method instead.
 *
 * @param updateExampleOptions the {@link UpdateExampleOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Example}
 */
public ServiceCall<Example> updateExample(UpdateExampleOptions updateExampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateExampleOptions, "updateExampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateExampleOptions.workspaceId());
    pathParamsMap.put("intent", updateExampleOptions.intent());
    pathParamsMap.put("text", updateExampleOptions.text());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents/{intent}/examples/{text}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateExample");
    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 (updateExampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateExampleOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateExampleOptions.newText() != null) {
        contentJson.addProperty("text", updateExampleOptions.newText());
    }
    if (updateExampleOptions.newMentions() != null) {
        contentJson.add("mentions", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateExampleOptions.newMentions()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Example> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Example>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Example(com.ibm.watson.assistant.v1.model.Example) JsonObject(com.google.gson.JsonObject)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)19 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)19 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)11 Example (com.ibm.watson.assistant.v1.model.Example)10 JsonObject (com.google.gson.JsonObject)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)8 Intent (com.ibm.watson.assistant.v1.model.Intent)6 Mention (com.ibm.watson.assistant.v1.model.Mention)6 CreateIntent (com.ibm.watson.assistant.v1.model.CreateIntent)5 Intent (com.ibm.watson.developer_cloud.conversation.v1.model.Intent)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)4 DialogNodeContext (com.ibm.watson.assistant.v1.model.DialogNodeContext)3 RuntimeIntent (com.ibm.watson.assistant.v1.model.RuntimeIntent)3 Intent (com.ibm.watson.developer_cloud.assistant.v1.model.Intent)3 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)3 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Test (org.junit.Test)3