use of com.ibm.watson.developer_cloud.conversation.v1.model.Intent in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method createExampleIntent.
public void createExampleIntent() {
exampleIntent = "Hello";
try {
CreateIntentOptions createOptions = new CreateIntentOptions.Builder(workspaceId, exampleIntent).description("Example Intent").build();
service.createIntent(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.Intent in project java-sdk by watson-developer-cloud.
the class ConversationTest method testCreateIntentOptionsBuilder.
/**
* Test CreateIntentOptions builder.
*/
@Test
public void testCreateIntentOptionsBuilder() {
String intent = "anIntent";
CreateExample intentExample0 = new CreateExample.Builder().text("intentExample0").build();
CreateExample intentExample1 = new CreateExample.Builder().text("intentExample1").build();
CreateIntentOptions createOptions = new CreateIntentOptions.Builder().workspaceId(WORKSPACE_ID).intent(intent).addExample(intentExample0).addExample(intentExample1).build();
assertEquals(createOptions.workspaceId(), WORKSPACE_ID);
assertEquals(createOptions.intent(), intent);
assertEquals(createOptions.examples().size(), 2);
assertEquals(createOptions.examples().get(0), intentExample0);
assertEquals(createOptions.examples().get(1), intentExample1);
CreateIntentOptions.Builder builder = createOptions.newBuilder();
CreateExample intentExample2 = new CreateExample.Builder().text("intentExample2").build();
builder.examples(Arrays.asList(intentExample2));
CreateIntentOptions options2 = builder.build();
assertEquals(options2.workspaceId(), WORKSPACE_ID);
assertEquals(options2.intent(), intent);
assertEquals(options2.examples().size(), 1);
assertEquals(options2.examples().get(0), intentExample2);
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.Intent in project java-sdk by watson-developer-cloud.
the class ConversationTest method testSendMessage.
/**
* Test send message.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessage() throws IOException, InterruptedException {
String text = "I'd like to get insurance to for my home";
MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class);
server.enqueue(jsonResponse(mockResponse));
InputData input = new InputData.Builder(text).build();
RuntimeIntent intent = new RuntimeIntent();
intent.setIntent("turn_off");
intent.setConfidence(0.0);
RuntimeEntity entity = new RuntimeEntity();
entity.setEntity("car");
entity.setValue("ford");
MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID).input(input).addIntent(intent).addEntity(entity).alternateIntents(true).build();
// execute first request
MessageResponse serviceResponse = service.message(options).execute();
// first request
RecordedRequest request = server.takeRequest();
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
assertEquals(path, request.getPath());
assertArrayEquals(new String[] { "Do you want to get a quote?" }, serviceResponse.getOutput().getText().toArray(new String[0]));
assertEquals(request.getMethod(), "POST");
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
String expected = "{" + "\"input\":{\"text\":\"I'd like to get insurance to for my home\"}," + "\"intents\":[{\"confidence\":0.0,\"intent\":\"turn_off\"}]," + "\"entities\":[{\"value\":\"ford\",\"entity\":\"car\"}]," + "\"alternate_intents\":true" + "}";
JsonParser parser = new JsonParser();
JsonObject expectedObj = parser.parse(expected).getAsJsonObject();
JsonObject actualObj = parser.parse(request.getBody().readUtf8()).getAsJsonObject();
assertTrue(expectedObj.equals(actualObj));
assertEquals(serviceResponse, mockResponse);
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.Intent in project java-sdk by watson-developer-cloud.
the class Conversation method createIntent.
/**
* Create intent.
*
* Create a new intent.
*
* @param createIntentOptions the {@link CreateIntentOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Intent}
*/
public ServiceCall<Intent> createIntent(CreateIntentOptions createIntentOptions) {
Validator.notNull(createIntentOptions, "createIntentOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "intents" };
String[] pathParameters = { createIntentOptions.workspaceId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
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", GsonSingleton.getGson().toJsonTree(createIntentOptions.examples()));
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Intent.class));
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.Intent in project java-sdk by watson-developer-cloud.
the class Conversation method getIntent.
/**
* Get intent.
*
* 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 response type of {@link IntentExport}
*/
public ServiceCall<IntentExport> getIntent(GetIntentOptions getIntentOptions) {
Validator.notNull(getIntentOptions, "getIntentOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "intents" };
String[] pathParameters = { getIntentOptions.workspaceId(), getIntentOptions.intent() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (getIntentOptions.export() != null) {
builder.query("export", String.valueOf(getIntentOptions.export()));
}
if (getIntentOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(getIntentOptions.includeAudit()));
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(IntentExport.class));
}
Aggregations