Search in sources :

Example 6 with ProfileOptions

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

the class PersonalityInsightsIT method getProfileWithTextAsCSVNoHeaders.

/**
 * Gets the profile with text as a CSV string without headers.
 *
 * @throws Exception the exception
 */
@Test
public void getProfileWithTextAsCSVNoHeaders() throws Exception {
    File file = new File(RESOURCE + "en.txt");
    String englishText = getStringFromInputStream(new FileInputStream(file));
    ProfileOptions options = new ProfileOptions.Builder().text(englishText).build();
    InputStream result = service.profileAsCsv(options).execute().getResult();
    String profileString = CharStreams.toString(new InputStreamReader(result, "UTF-8"));
    Assert.assertNotNull(profileString);
    Assert.assertTrue(profileString.split("\n").length == 1);
}
Also used : ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 7 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(Collections.singletonList(cItem)).build();
    ProfileOptions options = new ProfileOptions.Builder().content(content).consumptionPreferences(true).acceptLanguage(ProfileOptions.AcceptLanguage.EN).rawScores(true).build();
    Profile profile = service.profile(options).execute().getResult();
    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).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.personality_insights.v3.model.Profile) ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.personality_insights.v3.model.Content) ConsumptionPreferences(com.ibm.watson.personality_insights.v3.model.ConsumptionPreferences) File(java.io.File) ContentItem(com.ibm.watson.personality_insights.v3.model.ContentItem) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 8 with ProfileOptions

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

the class PersonalityInsightsTest method testProfileWOptions.

@Test
public void testProfileWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"processed_language\": \"ar\", \"word_count\": 9, \"word_count_message\": \"wordCountMessage\", \"personality\": [{\"trait_id\": \"traitId\", \"name\": \"name\", \"category\": \"personality\", \"percentile\": 10, \"raw_score\": 8, \"significant\": false}], \"needs\": [{\"trait_id\": \"traitId\", \"name\": \"name\", \"category\": \"personality\", \"percentile\": 10, \"raw_score\": 8, \"significant\": false}], \"values\": [{\"trait_id\": \"traitId\", \"name\": \"name\", \"category\": \"personality\", \"percentile\": 10, \"raw_score\": 8, \"significant\": false}], \"behavior\": [{\"trait_id\": \"traitId\", \"name\": \"name\", \"category\": \"category\", \"percentage\": 10}], \"consumption_preferences\": [{\"consumption_preference_category_id\": \"consumptionPreferenceCategoryId\", \"name\": \"name\", \"consumption_preferences\": [{\"consumption_preference_id\": \"consumptionPreferenceId\", \"name\": \"name\", \"score\": 0.0}]}], \"warnings\": [{\"warning_id\": \"WORD_COUNT_MESSAGE\", \"message\": \"message\"}]}";
    String profilePath = "/v3/profile";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ContentItem model
    ContentItem contentItemModel = new ContentItem.Builder().content("testString").id("testString").created(Long.valueOf("26")).updated(Long.valueOf("26")).contenttype("text/plain").language("en").parentid("testString").reply(false).forward(false).build();
    // Construct an instance of the Content model
    Content contentModel = new Content.Builder().contentItems(new java.util.ArrayList<ContentItem>(java.util.Arrays.asList(contentItemModel))).build();
    // Construct an instance of the ProfileOptions model
    ProfileOptions profileOptionsModel = new ProfileOptions.Builder().content(contentModel).contentLanguage("en").acceptLanguage("en").rawScores(false).csvHeaders(false).consumptionPreferences(false).build();
    // Invoke operation with valid options model (positive test)
    Response<Profile> response = personalityInsightsService.profile(profileOptionsModel).execute();
    assertNotNull(response);
    Profile 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");
    assertEquals(Boolean.valueOf(query.get("raw_scores")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("csv_headers")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("consumption_preferences")), Boolean.valueOf(false));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, profilePath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Profile(com.ibm.watson.personality_insights.v3.model.Profile) ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.personality_insights.v3.model.Content) ContentItem(com.ibm.watson.personality_insights.v3.model.ContentItem) Test(org.testng.annotations.Test)

Example 9 with ProfileOptions

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

the class PersonalityInsightsExample method main.

public static void main(String[] args) {
    PersonalityInsights service = new PersonalityInsights("2016-10-19");
    service.setUsernameAndPassword("<username>", "<password>");
    String text = "Call me Ishmael. Some years ago-never mind how long " + "precisely-having little or no money in my purse, and nothing " + "particular to interest me on shore, I thought I would sail about " + "a little and see the watery part of the world. It is a way " + "I have of driving off the spleen and regulating the circulation. " + "Whenever I find myself growing grim about the mouth; whenever it " + "is a damp, drizzly November in my soul; whenever I find myself " + "involuntarily pausing before coffin warehouses, and bringing up " + "the rear of every funeral I meet; and especially whenever my " + "hypos get such an upper hand of me, that it requires a strong " + "moral principle to prevent me from deliberately stepping into " + "the street, and methodically knocking people's hats off-then, " + "I account it high time to get to sea as soon as I can.";
    ProfileOptions options = new ProfileOptions.Builder().text(text).build();
    Profile profile = service.profile(options).execute();
    System.out.println(profile);
}
Also used : ProfileOptions(com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions) PersonalityInsights(com.ibm.watson.developer_cloud.personality_insights.v3.PersonalityInsights) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile)

Example 10 with ProfileOptions

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

the class PersonalityInsightsIT method getProfileWithASingleSpanishContentItem.

/**
 * Gets the profile from a single content item in Spanish.
 *
 * @throws Exception the exception
 */
@Test
public void getProfileWithASingleSpanishContentItem() throws Exception {
    File file = new File(RESOURCE + "es.txt");
    String englishText = getStringFromInputStream(new FileInputStream(file));
    ContentItem cItem = new ContentItem.Builder(englishText).language(ContentItem.Language.ES).build();
    Content content = new Content.Builder().contentItems(Arrays.asList(cItem)).build();
    ProfileOptions options = new ProfileOptions.Builder().content(content).consumptionPreferences(true).rawScores(true).build();
    Profile profile = service.profile(options).execute();
    assertProfile(profile);
}
Also used : ProfileOptions(com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.developer_cloud.personality_insights.v3.model.Content) File(java.io.File) FileInputStream(java.io.FileInputStream) ContentItem(com.ibm.watson.developer_cloud.personality_insights.v3.model.ContentItem) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

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