use of com.ibm.watson.discovery.v2.model.Enrichment in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method updateConfigurationIsSuccessful.
@Test
public void updateConfigurationIsSuccessful() {
Configuration testConfig = createTestConfig();
Date start = new Date();
String updatedName = testConfig.getName() + UUID.randomUUID().toString();
String updatedDescription = "Description of " + updatedName;
Conversions updatedConversions = new Conversions();
HtmlSettings newHtmlSettings = new HtmlSettings();
newHtmlSettings.setExcludeTagsCompletely(Arrays.asList("table", "h6", "header"));
updatedConversions.setHtml(newHtmlSettings);
NormalizationOperation operation = new NormalizationOperation();
operation.setOperation("foo");
operation.setSourceField("bar");
operation.setDestinationField("baz");
List<NormalizationOperation> updatedNormalizations = Arrays.asList(operation);
Enrichment enrichment = new Enrichment();
enrichment.setSourceField("foo");
enrichment.setDestinationField("bar");
enrichment.setEnrichmentName("baz");
enrichment.setDescription("Erich foo to bar with baz");
enrichment.setIgnoreDownstreamErrors(true);
enrichment.setOverwrite(false);
NluEnrichmentSentiment sentiment = new NluEnrichmentSentiment.Builder().document(true).build();
NluEnrichmentEmotion emotion = new NluEnrichmentEmotion.Builder().document(true).build();
NluEnrichmentEntities entities = new NluEnrichmentEntities.Builder().emotion(true).sentiment(true).model("WhatComesAfterQux").build();
NluEnrichmentKeywords keywords = new NluEnrichmentKeywords.Builder().emotion(true).sentiment(true).build();
NluEnrichmentSemanticRoles semanticRoles = new NluEnrichmentSemanticRoles.Builder().entities(true).build();
NluEnrichmentFeatures features = new NluEnrichmentFeatures.Builder().sentiment(sentiment).emotion(emotion).entities(entities).keywords(keywords).semanticRoles(semanticRoles).build();
EnrichmentOptions options = new EnrichmentOptions.Builder().features(features).build();
enrichment.setOptions(options);
List<Enrichment> updatedEnrichments = Arrays.asList(enrichment);
UpdateConfigurationOptions.Builder updateBuilder = new UpdateConfigurationOptions.Builder(environmentId, testConfig.getConfigurationId());
updateBuilder.name(updatedName);
updateBuilder.description(updatedDescription);
updateBuilder.conversions(updatedConversions);
updateBuilder.normalizations(updatedNormalizations);
updateBuilder.enrichments(updatedEnrichments);
Configuration updatedConfiguration = discovery.updateConfiguration(updateBuilder.build()).execute();
assertEquals(updatedName, updatedConfiguration.getName());
assertEquals(updatedDescription, updatedConfiguration.getDescription());
assertEquals(updatedConversions, updatedConfiguration.getConversions());
assertEquals(updatedNormalizations, updatedConfiguration.getNormalizations());
assertEquals(updatedEnrichments, updatedConfiguration.getEnrichments());
Date now = new Date();
assertTrue(fuzzyBefore(updatedConfiguration.getCreated(), start));
assertTrue(fuzzyBefore(updatedConfiguration.getUpdated(), now));
assertTrue(fuzzyAfter(updatedConfiguration.getUpdated(), start));
}
use of com.ibm.watson.discovery.v2.model.Enrichment in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testCreateEnrichmentWOptions.
@Test
public void testCreateEnrichmentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"enrichment_id\": \"enrichmentId\", \"name\": \"name\", \"description\": \"description\", \"type\": \"part_of_speech\", \"options\": {\"languages\": [\"languages\"], \"entity_type\": \"entityType\", \"regular_expression\": \"regularExpression\", \"result_field\": \"resultField\"}}";
String createEnrichmentPath = "/v2/projects/testString/enrichments";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the EnrichmentOptions model
EnrichmentOptions enrichmentOptionsModel = new EnrichmentOptions.Builder().languages(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).entityType("testString").regularExpression("testString").resultField("testString").build();
// Construct an instance of the CreateEnrichment model
CreateEnrichment createEnrichmentModel = new CreateEnrichment.Builder().name("testString").description("testString").type("dictionary").options(enrichmentOptionsModel).build();
// Construct an instance of the CreateEnrichmentOptions model
CreateEnrichmentOptions createEnrichmentOptionsModel = new CreateEnrichmentOptions.Builder().projectId("testString").enrichment(createEnrichmentModel).file(TestUtilities.createMockStream("This is a mock file.")).build();
// Invoke operation with valid options model (positive test)
Response<Enrichment> response = discoveryService.createEnrichment(createEnrichmentOptionsModel).execute();
assertNotNull(response);
Enrichment responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, createEnrichmentPath);
}
use of com.ibm.watson.discovery.v2.model.Enrichment in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testUpdateEnrichmentWOptions.
@Test
public void testUpdateEnrichmentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"enrichment_id\": \"enrichmentId\", \"name\": \"name\", \"description\": \"description\", \"type\": \"part_of_speech\", \"options\": {\"languages\": [\"languages\"], \"entity_type\": \"entityType\", \"regular_expression\": \"regularExpression\", \"result_field\": \"resultField\"}}";
String updateEnrichmentPath = "/v2/projects/testString/enrichments/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the UpdateEnrichmentOptions model
UpdateEnrichmentOptions updateEnrichmentOptionsModel = new UpdateEnrichmentOptions.Builder().projectId("testString").enrichmentId("testString").name("testString").description("testString").build();
// Invoke operation with valid options model (positive test)
Response<Enrichment> response = discoveryService.updateEnrichment(updateEnrichmentOptionsModel).execute();
assertNotNull(response);
Enrichment responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, updateEnrichmentPath);
}
use of com.ibm.watson.discovery.v2.model.Enrichment 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);
}
use of com.ibm.watson.discovery.v2.model.Enrichment 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);
}
Aggregations