Search in sources :

Example 6 with Enrichment

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

the class DiscoveryServiceTest method testCreateConfigurationOptions.

/**
 * Test create configuration options.
 */
// Configuration tests
@Test
public void testCreateConfigurationOptions() {
    String name = "name";
    String description = "description";
    Conversions conversions = new Conversions.Builder().build();
    String firstEnrichmentName = "first";
    String secondEnrichmentName = "second";
    String sourceField = "source_field";
    String destinationField = "destination_field";
    List<Enrichment> enrichments = new ArrayList<>();
    Enrichment firstEnrichment = new Enrichment.Builder().enrichment(firstEnrichmentName).sourceField(sourceField).destinationField(destinationField).build();
    enrichments.add(firstEnrichment);
    Enrichment secondEnrichment = new Enrichment.Builder().enrichment(secondEnrichmentName).sourceField(sourceField).destinationField(destinationField).build();
    List<NormalizationOperation> normalizationOperations = new ArrayList<>();
    NormalizationOperation firstOp = new NormalizationOperation.Builder().operation(NormalizationOperation.Operation.MERGE).build();
    NormalizationOperation secondOp = new NormalizationOperation.Builder().operation(NormalizationOperation.Operation.COPY).build();
    normalizationOperations.add(firstOp);
    Source source = new Source.Builder().build();
    CreateConfigurationOptions createConfigurationOptions = new CreateConfigurationOptions.Builder().environmentId(environmentId).name(name).description(description).conversions(conversions).enrichments(enrichments).addEnrichment(secondEnrichment).normalizations(normalizationOperations).addNormalization(secondOp).source(source).build();
    createConfigurationOptions = createConfigurationOptions.newBuilder().build();
    enrichments.add(secondEnrichment);
    normalizationOperations.add(secondOp);
    assertEquals(environmentId, createConfigurationOptions.environmentId());
    assertEquals(name, createConfigurationOptions.name());
    assertEquals(description, createConfigurationOptions.description());
    assertEquals(conversions, createConfigurationOptions.conversions());
    assertEquals(enrichments, createConfigurationOptions.enrichments());
    assertEquals(normalizationOperations, createConfigurationOptions.normalizations());
    assertEquals(source, createConfigurationOptions.source());
}
Also used : Enrichment(com.ibm.watson.discovery.v1.model.Enrichment) CreateConfigurationOptions(com.ibm.watson.discovery.v1.model.CreateConfigurationOptions) Conversions(com.ibm.watson.discovery.v1.model.Conversions) NormalizationOperation(com.ibm.watson.discovery.v1.model.NormalizationOperation) ArrayList(java.util.ArrayList) Source(com.ibm.watson.discovery.v1.model.Source) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 7 with Enrichment

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

the class DiscoveryTest method testGetEnrichmentWOptions.

@Test
public void testGetEnrichmentWOptions() 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 getEnrichmentPath = "/v2/projects/testString/enrichments/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetEnrichmentOptions model
    GetEnrichmentOptions getEnrichmentOptionsModel = new GetEnrichmentOptions.Builder().projectId("testString").enrichmentId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Enrichment> response = discoveryService.getEnrichment(getEnrichmentOptionsModel).execute();
    assertNotNull(response);
    Enrichment responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // 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, getEnrichmentPath);
}
Also used : CollectionEnrichment(com.ibm.watson.discovery.v2.model.CollectionEnrichment) Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) CreateEnrichment(com.ibm.watson.discovery.v2.model.CreateEnrichment) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetEnrichmentOptions(com.ibm.watson.discovery.v2.model.GetEnrichmentOptions) Test(org.testng.annotations.Test)

Example 8 with Enrichment

use of com.ibm.watson.discovery.v1.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));
}
Also used : Enrichment(com.ibm.watson.developer_cloud.discovery.v1.model.Enrichment) NluEnrichmentEmotion(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentEmotion) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) NluEnrichmentEntities(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentEntities) NormalizationOperation(com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation) NluEnrichmentSentiment(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentSentiment) NluEnrichmentSemanticRoles(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentSemanticRoles) Date(java.util.Date) NluEnrichmentFeatures(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentFeatures) Conversions(com.ibm.watson.developer_cloud.discovery.v1.model.Conversions) HtmlSettings(com.ibm.watson.developer_cloud.discovery.v1.model.HtmlSettings) EnrichmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.EnrichmentOptions) UpdateConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateConfigurationOptions) NluEnrichmentKeywords(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentKeywords) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 9 with Enrichment

use of com.ibm.watson.discovery.v1.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);
}
Also used : CollectionEnrichment(com.ibm.watson.discovery.v2.model.CollectionEnrichment) Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) CreateEnrichment(com.ibm.watson.discovery.v2.model.CreateEnrichment) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateEnrichmentOptions(com.ibm.watson.discovery.v2.model.CreateEnrichmentOptions) DeleteEnrichmentOptions(com.ibm.watson.discovery.v2.model.DeleteEnrichmentOptions) GetEnrichmentOptions(com.ibm.watson.discovery.v2.model.GetEnrichmentOptions) EnrichmentOptions(com.ibm.watson.discovery.v2.model.EnrichmentOptions) UpdateEnrichmentOptions(com.ibm.watson.discovery.v2.model.UpdateEnrichmentOptions) CreateEnrichmentOptions(com.ibm.watson.discovery.v2.model.CreateEnrichmentOptions) CreateEnrichment(com.ibm.watson.discovery.v2.model.CreateEnrichment) Test(org.testng.annotations.Test)

Example 10 with Enrichment

use of com.ibm.watson.discovery.v1.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);
}
Also used : CollectionEnrichment(com.ibm.watson.discovery.v2.model.CollectionEnrichment) Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) CreateEnrichment(com.ibm.watson.discovery.v2.model.CreateEnrichment) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateEnrichmentOptions(com.ibm.watson.discovery.v2.model.UpdateEnrichmentOptions) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 Test (org.testng.annotations.Test)7 Enrichment (com.ibm.watson.discovery.v2.model.Enrichment)5 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 Configuration (com.ibm.watson.discovery.v1.model.Configuration)3 Conversions (com.ibm.watson.discovery.v1.model.Conversions)3 Enrichment (com.ibm.watson.discovery.v1.model.Enrichment)3 NormalizationOperation (com.ibm.watson.discovery.v1.model.NormalizationOperation)3 Source (com.ibm.watson.discovery.v1.model.Source)3 HashMap (java.util.HashMap)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)2 Conversions (com.ibm.watson.developer_cloud.discovery.v1.model.Conversions)2 Enrichment (com.ibm.watson.developer_cloud.discovery.v1.model.Enrichment)2 CreateConfigurationOptions (com.ibm.watson.discovery.v1.model.CreateConfigurationOptions)2 EnrichmentOptions (com.ibm.watson.discovery.v1.model.EnrichmentOptions)2 FontSetting (com.ibm.watson.discovery.v1.model.FontSetting)2 HtmlSettings (com.ibm.watson.discovery.v1.model.HtmlSettings)2 NluEnrichmentConcepts (com.ibm.watson.discovery.v1.model.NluEnrichmentConcepts)2