Search in sources :

Example 1 with Content

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

the class PersonalityInsightsIT method getProfileWithContentItems.

/**
 * Gets the profile from a list of content items.
 *
 * @throws Exception the exception
 */
@Test
public void getProfileWithContentItems() throws Exception {
    final Content content = loadFixture(RESOURCE + "v3-contentItems.json", Content.class);
    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) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with Content

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

the class PersonalityInsightsIT method testReadme.

/**
 * Test example in Readme.
 */
@Test
public void testReadme() {
    // PersonalityInsights service = new PersonalityInsights("2016-10-19");
    // service.setUsernameAndPassword("<username>", "<password>");
    // Demo content from Moby Dick by Hermann Melville (Chapter 1)
    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. " + "This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself " + "upon his sword; I quietly take to the ship. There is nothing surprising in this. " + "If they but knew it, almost all men in their degree, some time or other, cherish " + "very nearly the same feelings towards the ocean with me. There now is your insular " + "city of the Manhattoes, belted round by wharves as Indian isles by coral reefs-commerce surrounds " + "it with her surf. Right and left, the streets take you waterward.";
    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) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 3 with Content

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

the class PersonalityInsightsTest method testContentBuilders.

/**
 * Test content builders.
 */
@Test
public void testContentBuilders() {
    final String content1 = "Wow, I liked @TheRock before , now I really SEE how special he is. " + "The daughter story was IT for me. So great! #MasterClass";
    final String content2 = "Wow aren't you loving @TheRock and his candor? #Masterclass";
    Long now = new Date().getTime();
    final ContentItem cItem1 = new ContentItem.Builder(content1).language(ContentItem.Language.EN).contenttype("text/plain").created(now).updated(now).id(UUID.randomUUID().toString()).forward(false).reply(false).parentid(null).build();
    ContentItem cItem2 = cItem1.newBuilder().content(content2).id(UUID.randomUUID().toString()).build();
    assertEquals(cItem2.contenttype(), "text/plain");
    assertEquals(cItem2.created(), now);
    assertEquals(cItem2.updated(), now);
    assertNotEquals(cItem1.id(), cItem2.id());
    final Content content = new Content.Builder().addContentItem(cItem1).addContentItem(cItem2).build();
    assertEquals(content.contentItems().size(), 2);
    final Content newContent = content.newBuilder().build();
    assertEquals(newContent.contentItems().size(), 2);
}
Also used : Content(com.ibm.watson.developer_cloud.personality_insights.v3.model.Content) Date(java.util.Date) ContentItem(com.ibm.watson.developer_cloud.personality_insights.v3.model.ContentItem) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 4 with Content

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

the class PersonalityInsights method profile.

/**
 * Generates a personality profile based on input text.
 *
 * Derives personality insights for up to 20 MB of input content written by an author, though the service requires
 * much less text to produce an accurate profile; for more information, see [Providing sufficient
 * input](https://console.bluemix.net/docs/services/personality-insights/input.html#sufficient). Accepts input in
 * Arabic, English, Japanese, Korean, or Spanish and produces output in one of eleven languages. Provide plain text,
 * HTML, or JSON content, and receive results in JSON or CSV format.
 *
 * @param profileOptions the {@link ProfileOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Profile}
 */
public ServiceCall<Profile> profile(ProfileOptions profileOptions) {
    Validator.notNull(profileOptions, "profileOptions cannot be null");
    String[] pathSegments = { "v3/profile" };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query(VERSION, versionDate);
    builder.header("Content-Type", profileOptions.contentType());
    if (profileOptions.contentLanguage() != null) {
        builder.header("Content-Language", profileOptions.contentLanguage());
    }
    if (profileOptions.acceptLanguage() != null) {
        builder.header("Accept-Language", profileOptions.acceptLanguage());
    }
    if (profileOptions.rawScores() != null) {
        builder.query("raw_scores", String.valueOf(profileOptions.rawScores()));
    }
    if (profileOptions.consumptionPreferences() != null) {
        builder.query("consumption_preferences", String.valueOf(profileOptions.consumptionPreferences()));
    }
    if (profileOptions.contentType().equalsIgnoreCase(ProfileOptions.ContentType.APPLICATION_JSON)) {
        builder.bodyJson(GsonSingleton.getGson().toJsonTree(profileOptions.content()).getAsJsonObject());
    } else {
        builder.bodyContent(profileOptions.body(), profileOptions.contentType());
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Profile.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Profile(com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile)

Example 5 with Content

use of com.ibm.watson.developer_cloud.personality_insights.v3.model.Content 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)7 Content (com.ibm.watson.developer_cloud.personality_insights.v3.model.Content)6 Profile (com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile)6 ProfileOptions (com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions)5 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)3 ContentItem (com.ibm.watson.developer_cloud.personality_insights.v3.model.ContentItem)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Date (java.util.Date)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 ConsumptionPreferences (com.ibm.watson.developer_cloud.personality_insights.v3.model.ConsumptionPreferences)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1