Search in sources :

Example 11 with ProfileOptions

use of com.ibm.watson.personality_insights.v3.model.ProfileOptions in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsIT method getProfileWithTextAsCSVWithHeaders.

/**
 * Gets the profile with text as a CSV string with headers.
 *
 * @throws Exception the exception
 */
@Test
public void getProfileWithTextAsCSVWithHeaders() throws Exception {
    File file = new File(RESOURCE + "en.txt");
    String englishText = getStringFromInputStream(new FileInputStream(file));
    ProfileOptions options = new ProfileOptions.Builder().text(englishText).build();
    String profileString = service.getProfileAsCSV(options, true).execute();
    Assert.assertNotNull(profileString);
    Assert.assertTrue(profileString.split("\n").length == 2);
}
Also used : ProfileOptions(com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 12 with ProfileOptions

use of com.ibm.watson.personality_insights.v3.model.ProfileOptions in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsIT method getProfileWithASingleContentItem.

/**
 * Gets the profile from a single content item.
 *
 * @throws Exception the exception
 */
@Test
public void getProfileWithASingleContentItem() throws Exception {
    File file = new File(RESOURCE + "en.txt");
    String englishText = getStringFromInputStream(new FileInputStream(file));
    Long now = new Date().getTime();
    ContentItem cItem = new ContentItem.Builder(englishText).language(ContentItem.Language.EN).contenttype("text/plain").created(now).updated(now).id(UUID.randomUUID().toString()).forward(false).reply(false).parentid(null).build();
    Content content = new Content.Builder(Arrays.asList(cItem)).build();
    ProfileOptions options = new ProfileOptions.Builder().content(content).consumptionPreferences(true).acceptLanguage(ProfileOptions.AcceptLanguage.EN).rawScores(true).build();
    Profile profile = service.profile(options).execute();
    assertProfile(profile);
    Assert.assertTrue(profile.getValues().size() > 0);
    Assert.assertNotNull(profile.getValues().get(0).getCategory());
    Assert.assertNotNull(profile.getValues().get(0).getName());
    Assert.assertNotNull(profile.getValues().get(0).getTraitId());
    // Assert.assertNotNull(profile.getValues().get(0).getChildren());
    Assert.assertNotNull(profile.getValues().get(0).getPercentile());
    Assert.assertNotNull(profile.getValues().get(0).getRawScore());
    Assert.assertNotNull(profile.getBehavior());
    Assert.assertTrue(profile.getBehavior().size() > 0);
    Assert.assertNotNull(profile.getBehavior().get(0).getCategory());
    Assert.assertNotNull(profile.getBehavior().get(0).getName());
    Assert.assertNotNull(profile.getBehavior().get(0).getTraitId());
    Assert.assertNotNull(profile.getBehavior().get(0).getPercentage());
    Assert.assertTrue(profile.getConsumptionPreferences().size() > 0);
    Assert.assertNotNull(profile.getConsumptionPreferences().get(0).getName());
    Assert.assertNotNull(profile.getConsumptionPreferences().get(0).getConsumptionPreferenceCategoryId());
    Assert.assertNotNull(profile.getConsumptionPreferences().get(0).getConsumptionPreferences());
    Assert.assertTrue(profile.getConsumptionPreferences().get(0).getConsumptionPreferences().size() > 0);
    ConsumptionPreferences preference = profile.getConsumptionPreferences().get(0).getConsumptionPreferences().get(0);
    Assert.assertNotNull(preference.getConsumptionPreferenceId());
    Assert.assertNotNull(preference.getName());
    Assert.assertNotNull(preference.getScore());
}
Also used : FileInputStream(java.io.FileInputStream) Date(java.util.Date) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile) ProfileOptions(com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.developer_cloud.personality_insights.v3.model.Content) ConsumptionPreferences(com.ibm.watson.developer_cloud.personality_insights.v3.model.ConsumptionPreferences) File(java.io.File) ContentItem(com.ibm.watson.developer_cloud.personality_insights.v3.model.ContentItem) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 13 with ProfileOptions

use of com.ibm.watson.personality_insights.v3.model.ProfileOptions in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsIT method getProfileWithText.

/**
 * Gets the profile with text.
 *
 * @throws Exception the exception
 */
@Test
public void getProfileWithText() throws Exception {
    File file = new File(RESOURCE + "en.txt");
    String englishText = getStringFromInputStream(new FileInputStream(file));
    ProfileOptions options = new ProfileOptions.Builder().text(englishText).build();
    Profile profile = service.profile(options).execute();
    Assert.assertNotNull(profile);
    Assert.assertNotNull(profile.getProcessedLanguage());
    Assert.assertNotNull(profile.getValues());
    Assert.assertNotNull(profile.getNeeds());
    Assert.assertNotNull(profile.getPersonality());
}
Also used : ProfileOptions(com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions) File(java.io.File) FileInputStream(java.io.FileInputStream) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 14 with ProfileOptions

use of com.ibm.watson.personality_insights.v3.model.ProfileOptions in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsTest method testGetProfileWithContent.

/**
 * Test get profile with content.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetProfileWithContent() throws InterruptedException {
    final Content content = new Content.Builder().addContentItem(contentItem).build();
    final ProfileOptions options = new ProfileOptions.Builder().content(content).build();
    server.enqueue(jsonResponse(profile));
    final Profile profile = service.profile(options).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(PROFILE_PATH + "?version=2016-10-19", request.getPath());
    assertEquals("POST", request.getMethod());
    assertNotNull(profile);
    assertEquals(this.profile, profile);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ProfileOptions(com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.developer_cloud.personality_insights.v3.model.Content) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 15 with ProfileOptions

use of com.ibm.watson.personality_insights.v3.model.ProfileOptions in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsTest method testGetProfileWithEnglishText.

/**
 * Test get profile with English text.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetProfileWithEnglishText() throws InterruptedException {
    final ProfileOptions options = new ProfileOptions.Builder().text(text).contentLanguage(ProfileOptions.ContentLanguage.EN).build();
    server.enqueue(jsonResponse(profile));
    final Profile profile = service.profile(options).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(PROFILE_PATH + "?version=2016-10-19", request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals("en", request.getHeader(HttpHeaders.CONTENT_LANGUAGE));
    assertEquals(HttpMediaType.TEXT.toString(), request.getHeader(HttpHeaders.CONTENT_TYPE));
    assertEquals(text, request.getBody().readUtf8());
    assertNotNull(profile);
    assertEquals(this.profile, profile);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ProfileOptions(com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Aggregations

Test (org.junit.Test)18 ProfileOptions (com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions)12 File (java.io.File)10 FileInputStream (java.io.FileInputStream)10 Profile (com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile)9 ProfileOptions (com.ibm.watson.personality_insights.v3.model.ProfileOptions)9 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)7 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 Profile (com.ibm.watson.personality_insights.v3.model.Profile)7 Content (com.ibm.watson.personality_insights.v3.model.Content)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 Content (com.ibm.watson.developer_cloud.personality_insights.v3.model.Content)4 ContentItem (com.ibm.watson.personality_insights.v3.model.ContentItem)4 InputStream (java.io.InputStream)3 ContentItem (com.ibm.watson.developer_cloud.personality_insights.v3.model.ContentItem)2 InputStreamReader (java.io.InputStreamReader)2 Date (java.util.Date)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Test (org.testng.annotations.Test)2