use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method testUpdateWorkspace.
/**
* Test updateWorkspace.
*/
@Test
public void testUpdateWorkspace() {
String workspaceName = "testUpdateWorkspace";
String workspaceDescription = "Description for testUpdateWorkspace";
// intents
CreateIntent intent0 = new CreateIntent.Builder("Hello").build();
CreateIntent intent1 = new CreateIntent.Builder("Goodbye").build();
// entities
CreateEntity entity0 = new CreateEntity.Builder("animal").build();
CreateEntity entity1 = new CreateEntity.Builder("beverage").build();
// counterexamples
CreateCounterexample counterexample0 = new CreateCounterexample.Builder("What are you wearing?").build();
CreateCounterexample counterexample1 = new CreateCounterexample.Builder("What are you eating?").build();
CreateWorkspaceOptions createOptions = new CreateWorkspaceOptions.Builder().name(workspaceName).description(workspaceDescription).addIntent(intent0).addIntent(intent1).addEntity(entity0).addEntity(entity1).addCounterexample(counterexample0).addCounterexample(counterexample1).build();
String workspaceId = null;
try {
Workspace createResponse = service.createWorkspace(createOptions).execute();
assertNotNull(createResponse);
assertNotNull(createResponse.getWorkspaceId());
workspaceId = createResponse.getWorkspaceId();
String counterExampleText = "What are you drinking";
CreateCounterexample counterexample2 = new CreateCounterexample.Builder(counterExampleText).build();
UpdateWorkspaceOptions updateOptions = new UpdateWorkspaceOptions.Builder(workspaceId).addCounterexample(counterexample2).append(false).build();
Workspace updateResponse = service.updateWorkspace(updateOptions).execute();
assertNotNull(updateResponse);
GetCounterexampleOptions getOptions = new GetCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
Counterexample eResponse = service.getCounterexample(getOptions).execute();
assertNotNull(eResponse);
assertNotNull(eResponse.getText());
assertEquals(eResponse.getText(), counterExampleText);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
if (workspaceId != null) {
DeleteWorkspaceOptions deleteOptions = new DeleteWorkspaceOptions.Builder(workspaceId).build();
service.deleteWorkspace(deleteOptions).execute();
}
}
}
use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.
the class Conversation method updateCounterexample.
/**
* Update counterexample.
*
* Update the text of a counterexample. Counterexamples are examples that have been marked as irrelevant input.
*
* @param updateCounterexampleOptions the {@link UpdateCounterexampleOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Counterexample}
*/
public ServiceCall<Counterexample> updateCounterexample(UpdateCounterexampleOptions updateCounterexampleOptions) {
Validator.notNull(updateCounterexampleOptions, "updateCounterexampleOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "counterexamples" };
String[] pathParameters = { updateCounterexampleOptions.workspaceId(), updateCounterexampleOptions.text() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (updateCounterexampleOptions.newText() != null) {
contentJson.addProperty("text", updateCounterexampleOptions.newText());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Counterexample.class));
}
use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.
the class Assistant method updateCounterexample.
/**
* Update counterexample.
*
* Update the text of a counterexample. Counterexamples are examples that have been marked as irrelevant input. This
* operation is limited to 1000 requests per 30 minutes. For more information, see **Rate limiting**.
*
* @param updateCounterexampleOptions the {@link UpdateCounterexampleOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Counterexample}
*/
public ServiceCall<Counterexample> updateCounterexample(UpdateCounterexampleOptions updateCounterexampleOptions) {
Validator.notNull(updateCounterexampleOptions, "updateCounterexampleOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "counterexamples" };
String[] pathParameters = { updateCounterexampleOptions.workspaceId(), updateCounterexampleOptions.text() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (updateCounterexampleOptions.newText() != null) {
contentJson.addProperty("text", updateCounterexampleOptions.newText());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Counterexample.class));
}
use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.
the class Assistant method createCounterexample.
/**
* Create counterexample.
*
* Add a new counterexample to a workspace. Counterexamples are examples that have been marked as irrelevant input.
* This operation is limited to 1000 requests per 30 minutes. For more information, see **Rate limiting**.
*
* @param createCounterexampleOptions the {@link CreateCounterexampleOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Counterexample}
*/
public ServiceCall<Counterexample> createCounterexample(CreateCounterexampleOptions createCounterexampleOptions) {
Validator.notNull(createCounterexampleOptions, "createCounterexampleOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "counterexamples" };
String[] pathParameters = { createCounterexampleOptions.workspaceId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("text", createCounterexampleOptions.text());
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Counterexample.class));
}
use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method testGetCounterexample.
/**
* Test getCounterexample.
*/
@Test
public void testGetCounterexample() {
Date start = new Date();
// gotta be unique
String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
service.createCounterexample(createOptions).execute();
try {
GetCounterexampleOptions getOptions = new GetCounterexampleOptions.Builder(workspaceId, counterExampleText).includeAudit(true).build();
Counterexample response = service.getCounterexample(getOptions).execute();
assertNotNull(response);
assertNotNull(response.getText());
assertEquals(response.getText(), counterExampleText);
assertNotNull(response.getCreated());
assertNotNull(response.getUpdated());
Date now = new Date();
assertTrue(fuzzyBefore(response.getCreated(), now));
assertTrue(fuzzyAfter(response.getCreated(), start));
assertTrue(fuzzyBefore(response.getUpdated(), now));
assertTrue(fuzzyAfter(response.getUpdated(), start));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
service.deleteCounterexample(deleteOptions).execute();
}
}
Aggregations